2
我試圖使可以讀取和編譯OpenGL的頂點和片段着色器文件的功能,但我得到這個錯誤:'的std :: basic_string的<炭的std :: char_traits <char>,性病::分配器<char>> :: c_str':非標準語法;使用「&」來創建一個指針成員
'std::basic_string<char,std::char_traits<char>,std::allocator<char>>::c_str': non-standard syntax; use '&' to create a pointer to member
我不太清楚如何解決它。這裏是我的代碼:
GLuint shader_load(const GLchar* vertex, const GLchar* fragment) {
std::string ver = file_read_all(vertex);
std::string frag = file_read_all(fragment);
const GLchar* verCode = ver.c_str;
const GLchar* fragCode = frag.c_str;
GLuint program;
GLuint verShader, fragShader;
GLint success;
GLchar log[512];
verShader = glCreateShader(GL_VERTEX_SHADER);
glShaderSource(verShader, 1, &verCode, NULL);
glCompileShader(verShader);
glGetShaderiv(verShader, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(verShader, 512, NULL, log);
std::cout << "Failed to compile Vertex Shader\n" << log << std::endl;
return NULL;
}
fragShader = glCreateShader(GL_FRAGMENT_SHADER);
glShaderSource(fragShader, 1, &fragCode, NULL);
glCompileShader(fragShader);
glGetShaderiv(fragShader, GL_COMPILE_STATUS, &success);
if (!success) {
glGetShaderInfoLog(fragShader, 512, NULL, log);
std::cout << "Failed to compile Fragment Shader\n" << log << std::endl;
return NULL;
}
program = glCreateProgram();
glAttachShader(program, verShader);
glAttachShader(program, fragShader);
glLinkProgram(program);
glGetProgramiv(program, GL_LINK_STATUS, &success);
if (!success)
{
glGetProgramInfoLog(program, 512, NULL, log);
std::cout << "Failed to Link Shader\n" << log << std::endl;
}
glDeleteShader(verShader);
glDeleteShader(fragShader);
}
我使用Visual Studio 2015年社區在Windows 10