identifier “ ” is undefined

匿名 (未验证) 提交于 2019-12-03 02:43:01

问题:

I am coding a 3D opengl test application, I have a function set up like this:

Shader::Shader(const std::string& fileName) {     program = glCreateProgram();     shaders[0] = CreateShader(LoadShader(fileName + ".vs"), GL_VERTEX_SHADER);     shaders[1] = CreateShader(LoadShader(fileName + ".fs"), GL_FRAGMENT_SHADER);      for (unsigned int i=0; i < NUM_SHADERS; i++)         glAttachShader(program, shaders[1]);      glBindAttribLocation(program, 0, "position");      glLinkProgram(program); } 

However when I try to declare shaders[0] = CreateShader(LoadShader(fileName + ".vs"), GL_VERTEX SHADER); I get the error: identifier "shaders" is undefined, how do I fix this?

回答1:

You forgot #include "shader.h". This will fix your issue.

I guess you are working on something similar to https://github.com/BennyQBD/ModernOpenGLTutorial. Here is the declaration for m_shaders https://github.com/BennyQBD/ModernOpenGLTutorial/blob/master/shader.h#L29. You are using shaders instead.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!