Monday, April 9, 2012

GL Bug Fixed

Earlier this week I encountered some trouble getting just a simple cube to render in my GLUT window. I thought I was doing something wrong when initializing my GL viewport, since I was only able to see the background color of my scene. It turns out that my program wasn't properly setting a value for the unsigned int used to represent a varying vec4 in my shader program, and as such none of my vertices were being placed anywhere in the GL scene. To fix this I just defined its location myself using layout(location) in its definition in my vertex shader. Now I can actually see the geometry I generate and know that my camera controls are working properly. Next step: change my fragment shader to use raymarch code to render a cloud.

1 comment:

  1. Matching up attributes with locations is a troublesome area of OpenGL. You can call glBindAttribLocation before calling glLinkProgram to explicitly assign a location, or call glGetAttribLocation afterward. As you mentioned, in more recent OpenGL versions, you can explicitly assign the location in GLSL.

    ReplyDelete