我正在编写一个简单的着色器管理器,因此我不必一直编写涉及我的着色器的重复代码并且我遇到了一些问题,这里是出现错误的函数:
void ShaderManager::create_program(std::string name) {
GLuint vertexshader;
GLuint fragmentshader;
GLint link_ok = GL_FALSE;
if ((vertexshader = create_shader(name + ".v.glsl", GL_VERTEX_SHADER)) == 0) {
print_shader_errors(&vertexshader);
}
if ((fragmentshader = create_shader(name + ".f.glsl", GL_FRAGMENT_SHADER)) == 0) {
print_shader_errors(&fragmentshader);
}
program_values.emplace_back(glCreateProgram());
program_keys.emplace_back(name);
glAttachShader(program_values.at(program_values.size()), vertexshader);
glAttachShader(program_values.at(program_values.size()), fragmentshader);
glLinkProgram(program_values.at(program_values.size()));
glGetProgramiv(program_values.at(program_values.size()), GL_LINK_STATUS, &link_ok);
if (!link_ok) {
std::cout << "The shaders did not link correctly." << "\n";
}
}
我尝试访问的每个私有静态成员都说同样的话:
Generator\src\ShaderManager.cpp|33|undefined reference to ShaderManager::program_values'
我的头文件如下所示:
#ifndef SHADERMANAGER_H
#define SHADERMANAGER_H
#include <string>
#include <vector>
#include <GL/glew.h>
#include <GL/glu.h>
#include <GL/gl.h>
class ShaderManager {
public:
ShaderManager();
virtual ~ShaderManager();
static GLuint get_program(std::string shader_name);
static int get_index_of_program_key(std::string program_name);
static void create_program(std::string name);
static bool bind_attribute(std::string shader_name, std::string attribute_name);
static bool bind_uniform(std::string shader_name, std::string uniform_name);
protected:
private:
static std::vector<GLuint> program_values;
static std::vector<std::string> program_keys;
static std::vector<GLuint> attribute_values;
static std::vector<std::string> attribute_keys;
static std::vector<GLuint> uniform_values;
static std::vector<std::string> uniform_keys;
static void print_shader_errors(GLuint *shader);
static const char* file_read(std::string filename);
static GLuint create_shader(std::string filename, GLenum type);
};
#endif // SHADERMANAGER_H