In the past few days, I’ve been really deep in OpenGL and GLSL stuff. I’ve learned a few critical things that would be helpful for people to know. Help you avoid the mistakes I made and such.
When dealing with defined uniform variables, variables you send into the shader from the program, you MUST in some way reference (use) the variable somewhere, or the shader won’t fully compile (or sometimes will, but will have strange effects). One thing that happened to me was getting errors like “Can’t find overload function for Texture2D(error, gl_TexCoord[0].st);” I also saw that even though my frame buffer objects did get rendered in the first pass, they weren’t directly usable in the shader (but I COULD use them in the program).
Speaking of FBO shaders and uniform variables, I made the common mistake of assuming that when creating a uniform variable, the number you give is the handle to the texture you are using. This is NOT true! It’s supposed to simply be an integer value from 0 to the maximum allowed uniform variables. Here’s the code:
// Incorrect: GLuint location = glGetUniformLocation(shaderProgram, "Texture0"); glUniform1i(location, textureHandle); // Correct: GLuint location = glGetUniformLocation(shaderProgram, "Texture0"); glUniform1i(location, 0);
March 3, 2009 | 10:23 PM
Categories: Graphics, How To, Programming

Comments are closed for this post.