1
$\begingroup$

I'm trying to render a randomly generated terrain with vertex buffers and OpenGL. I want to use a shader to color the terrain, but it seemms like my shader isn't used. I have used shaders before when drawing triangles manually on the CPU and didn't have any problems there.

activate and deactivate is just glUseProgram(m_ShaderProgram) and glUseProgram(0);

This is my draw method:

void Terrain::drawTest() { glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); // setup position & normal pointers glVertexPointer(3, GL_FLOAT, sizeof(TerrainVertex), BUFFER_OFFSET(0)); glNormalPointer(GL_FLOAT, sizeof(TerrainVertex), BUFFER_OFFSET(12)); m_ShaderProgram.activate(); glDrawElements(GL_TRIANGLES, indicesCount, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); m_ShaderProgram.deactivate(); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); } 

And my shaders look like this:

Vertex shader:

varying vec3 Normal; varying vec3 Position; varying vec2 Texcoord; void main(void) { Position = (gl_ModelViewMatrix * gl_Vertex).xyz; Normal = gl_NormalMatrix * gl_Normal; Texcoord = gl_MultiTexCoord0.xy; gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex; } 

Fragment shader:

varying vec3 Normal; varying vec3 Position; varying vec2 Texcoord; void main(void) { gl_FragColor = vec4(1.0,1.0,0,0); } 

Result: Terrain

As you can see the fragment shader doesn't seem to do anything and I can't figure out what the problem is.

$\endgroup$
3
  • 1
    $\begingroup$ Have you called glGetError() to see if there are any errors? $\endgroup$ Commented Aug 16, 2016 at 14:40
  • $\begingroup$ Gives me 1281 - Invalid Value $\endgroup$ Commented Aug 16, 2016 at 14:56
  • $\begingroup$ So I get GL_INVALID_ENUM on the first run of the render loop after glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_IndexBuffer); glBindBuffer(GL_ARRAY_BUFFER, m_VertexBuffer); and GL_INVALID_VALUE after the first shaderProgram.activate() and everytime thereafter. $\endgroup$ Commented Aug 16, 2016 at 15:06

1 Answer 1

-1
$\begingroup$

Apparently there was just a problem with the loading of the shader. A bug that crept into the code from an old project...

EDIT: The GLuint of the compiled shader was never saved in the class and only local to the load function. Just a stupid mistake really.

$\endgroup$
1
  • 3
    $\begingroup$ As it stands this is more of a comment than an answer. Could you expand to explain the bug and how it affected your code? $\endgroup$ Commented Aug 17, 2016 at 21:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.