Here I note down my programming bugs that I encounter that only revealed the nature of the bug after careful examination.
Symptom: No image on screen after enabling stenciling to show bottom left corner.
What happend:
1 pass: Rendering a scene into framebuffer with color, depth, stencil texture attachment buffers, and enable stencil test.\
2nd pass: Use default screen buffer. Render the color texture buffer into a quad, all fragments fail the stencil test.
Fix: disable stencil test before the 2nd pass.
Symptom:The entire screen is shown, but on the lower left corner.
What Happened:
Set viewport to be dimensions of the screen.
1st pass: Render a scene into framebuffer with dimensions larger than the current screen.
2nd pass: Use default screen buffer. Render the color texture buffer into a quad.
Fix: Set viewport to be size of the frame buffer before every pass.
Symptom: Blank Texture
What happened:
I had 2 linked shader programs, one for phong shading, the other texturing. I get all the attributes for phong shading programs then get all the attributes locations for texturing program, then set the texture location like bellow.
//depth sampler location found in GL_TEXTURE2
glUniform1i(depthMapSamplers[i], 2);
But I missed the gluseprogram call on the linked shader program.
Symptom: No lighting.
What Happened:My code originally called QMatrix4x4::perspective to create a point light with perspective transform twice. First time, I don't reset before calling because it was a newly allocated QMatrix4x4 with default values, and the second time I reset the matrix prior to the QMatrix4x4::perspective call. When I change the order around for "Selecting Lua" UI feature, the perspective matrix for light was incorrect.
Symptom: Only 1 color per sphere after instancing.
What happened: Color is a uniform that I changed per sphere. Now that i have instanced sphere, I need to make color a array attribute.
Symptom: Weird problem with one of the non-instanced array attriabute after instancing,
This problem took me a whole year to get around to fix. I didn't know there was such tool as Render Doc which allowed me to freeze the render and see the array attribute for each vertex.
What happened: After calling gldrawinstanced, every array attribute defaults to being instanced and required a glVertexAttribDivisor call.