【发布时间】:2012-06-08 07:04:36
【问题描述】:
我看到了this 的问题,它确实揭示了一些启示。尽管如此,我似乎无法弄清楚我是如何“不正确地”加载我的着色器的,因为这个已经之前执行过,而最近没有对着色器加载代码进行任何更改,所以我认为这些错误必须来自我的抽奖电话。
尽管如此,为了简洁起见,我仍然会发布着色器文件、用于绘制我要渲染的圆的绘制函数,以及作为字符串加载到着色器文件中的代码。
基本上我需要知道的是为什么我会收到这些错误以及它们到底有什么问题?
(来自调试输出)
ERROR {
OpenGL Says:
Vertex info
-----------
0(1) : error C0000: syntax error, unexpected $undefined at token "<undefined>"
Fragment info
-------------
0(1) : error C0000: syntax error, unexpected $undefined at token "<undefined>"
};
绘制代码
void Circle::draw( GLuint program )
{
const size_t centerMag = mCenter.length();
glUseProgram( program );
for( float t = 0; t < mCircumference; t += 0.1 )
{
float x = centerMag + glm::cos( 2 * M_PI * t );
float y = centerMag + glm::sin( 2 * M_PI * t );
mVertices->push_back( glm::vec4( x, y, 0, 1 ) );
}
QListIterator< glm::vec4 > iVertices( *mVertices );
const size_t size = mVertices->size();
float** verts = new float*[ size ];
size_t i = 0;
glEnableClientState( GL_VERTEX_ARRAY );
while( iVertices.hasNext() )
{
verts[ i ] = new float[ size ];
verts[ i ] = const_cast< float* >( glm::value_ptr( iVertices.next() ) );
glVertexPointer( 4, GL_FLOAT, 0, verts[ i ] );
glDrawArrays( GL_LINES, 0, 4 );
++i;
}
glDisableClientState( GL_VERTEX_ARRAY );
for( unsigned iMem = 0; iMem < size; ++iMem )
{
delete[] verts[ iMem ];
verts[ iMem ] = NULL;
}
delete[] verts;
verts = NULL;
}
文件实用程序
QString FileUtility::readShader( QString filepath )
{
std::ifstream in( filepath.toStdString().c_str() );
std::stringstream shaderDat;
shaderDat << in.rdbuf();
QString shaderFile;
shaderFile += shaderDat.str().c_str();
in.close();
return shaderFile;
}
GenericColor.frag
#version 330
out vec4 outputColor;
void main()
{
outputColor = vec4(1.0f, 0, 0, 1.0f);
}
Position.vert
#version 330
layout(location = 0) in vec4 position;
void main()
{
gl_Position = position;
}
更新
由于请求了我的着色器绑定/编译代码,我想我不妨只发布我的整个着色器处理程序以及引擎类。
更新
这里是解析的着色器字符串(Info 是调试输出):
Info {
Shader Source #version 330
in uniform mvp;
layout(location = 0) in vec4 position;
void main()
{
gl_ModelViewProjectionMatrix = mvp;
gl_Position = position;
}
};
Info {
Shader Source #version 330
out vec4 outputColor;
void main()
{
outputColor = vec4(1.0f, 0, 0, 1.0f);
}
};
【问题讨论】:
-
能否也显示着色器编译/VA 绑定代码?
-
已更新,我决定将整个源文件粘贴到 bin 中。
-
您是否有机会发布正在加载到 glShaderSource 的确切 c_str?着色器编译错误应该与程序的其余部分无关(您的绘制代码可能无关紧要)。也许可以通过这种方式发现一些东西。
-
是的,刚刚更新。我想知道问题是否是因为我为此使用了 Qt...
-
哦,Qt... QGLWindow 可能不是支持 GL3.1 核心配置文件的东西...不幸的是。您必须稍作修改才能使用纯 WinAPI 创建兼容的上下文。您没有提到 Qt,但这是 GL3 的一个众所周知的问题
标签: c++ opengl error-handling compilation glsl