I’ve been converting some of my old code to OpenGL 3, and I’ve gotten most of it working. All the VAOs, VBOs, etc. are working fine, as verified by an OpenGL debugging program, and my shaders compile just fine, but nothing appears on the screen other than my clear color. I think all my matrices should be fine, although I’m not sure if the projection matrix is supposed to convert negative Z-coordinates to positive ones; every code sample I’ve tried produces such a matrix. Here are my shaders:
Vertex shader:
#version 330
uniform mat4 modelview;
uniform mat4 projection;
in vec4 position;
in vec4 normal;
in vec4 texCoord;
void main() {
gl_Position = projection * modelview * position;
}
Fragment shader:
#version 330
out vec4 fragColor;
void main() {
fragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
My code is complex, so I’ll just post a modified, commented version of the glIntercept call log, which should have all the relevant calls:
//Create shaders
glCreateShader(GL_VERTEX_SHADER)=1
glShaderSource(1,1,vertShaderText,vertShaderTextLen)
glCompileShader(1)
glGetShaderiv(1,GL_COMPILE_STATUS,buf)
glCreateShader(GL_FRAGMENT_SHADER)=2
glShaderSource(2,1,fragShaderText,fragShaderTextLen)
glCompileShader(2)
glGetShaderiv(2,GL_COMPILE_STATUS,buf)
glCreateProgram()=3
glAttachShader(3,1)
glAttachShader(3,2)
glLinkProgram(3)
glGetProgramiv(3,GL_LINK_STATUS,buf)
//Find uniform/attribute locations
//Extra glUseProgram() calls are for safety.
glGetUniformLocation(3,"modelview")=0
glUseProgram(3)
glGetUniformLocation(3,"projection")=1
glUseProgram(3)
glGetAttribLocation(3,"position")=0
glUseProgram(3)
glGetAttribLocation(3,"normal")=-1
glUseProgram(3)
glGetAttribLocation(3,"texCoord")=-1
//Create a texture; probably irrelevant to this code
glGenTextures(1,texId)
glBindTexture(GL_TEXTURE_2D,1)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,256,256,0,GL_RGBA,GL_UNSIGNED_BYTE,texData)
glGenTextures(1,01DD275C)
//Create VAO, VBO
glGenVertexArrays(1,vaoId)
glBindVertexArray(1)
glGenBuffers(1,bufId)
glBindBuffer(GL_ARRAY_BUFFER,1)
//Redundant call; actual data set later
glBufferData(GL_ARRAY_BUFFER,0,00000000,GL_STATIC_DRAW)
glGenBuffers(1,indexBufId)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,4)
glBufferData(GL_ELEMENT_ARRAY_BUFFER,0,00000000,GL_STATIC_DRAW)
//Set up buffer data
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,4)
glBufferData(GL_ELEMENT_ARRAY_BUFFER,96,indexData,GL_STATIC_DRAW)
glBindBuffer(GL_ARRAY_BUFFER,1)
glBufferData(GL_ARRAY_BUFFER, 48,01DC3D00,GL_STATIC_DRAW)
//Start drawing
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT)
glUseProgram(3)
glUseProgram(3)
//Modelview
glUniformMatrix4fv(modelviewLocation,1,false,[1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,0.000000,1.000000,0.000000,0.000000,0.000000,-6.000000,1.000000])
glUseProgram(3)
//Projection
glUniformMatrix4fv(projectionLocation,1,false,[0.200000,0.000000,0.000000,0.000000,0.000000,0.150000,0.000000,0.000000,0.000000,0.000000,-1.000200,-1.000000,0.000000,0.000000,-0.200020,0.000000])
//Bind VAO, VBOs, and attribute positions
glBindVertexArray(1)
glBindBuffer(GL_ARRAY_BUFFER,1)
glVertexAttribPointer(positionAttributeLocation,3,GL_FLOAT,false,12,00000000)
glEnableVertexAttribArray(positionAttributeLocation)
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,4)
glDrawElements(GL_TRIANGLES,24,GL_UNSIGNED_INT,00000000) GLSL=3 Textures[ (0,2) ]
glDisableVertexAttribArray(0)
I’ve got a plane facing directly into the camera, but it doesn’t show up at all. All I see is the clear color. Culling and depth test are off.
Any ideas what could be wrong?