1

I am drawing on a texture and then rendering this texture to the screen using GL_QUADS. There is no problem drawing the texture on screen, but while drawing to the texture the only operation that has any effect is glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - this sets the whole texture to the colour I want. It is however impossible to draw any primitives.

The following code should absolutely cover the whole texture with black, right?

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, texRenderer.framebufferID);                        // switch to the texture framebuffer

glClearColor(1.0f,0.5f,0.0f,1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glDisable(GL_DEPTH_TEST);
glDisable(GL_SCISSOR_TEST);
glDisable(GL_CULL_FACE);

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, texRenderer.pixelsWidth, 0, texRenderer.pixelsHeight, 1, -1);

// switch to modelview matrix before rendering objects
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glColor4f(0,0,0,1);
glBegin(GL_QUADS);
glVertex2f(-100, -100);
glVertex2f(-100, 100);
glVertex2f(100, 100);
glVertex2f(100, -100);
glEnd();

glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);

//RenderScene(sim, stateMachine, viewSettings, commandMgr, font, texRenderer.pixelsWidth, texRenderer.pixelsHeight, isMainView, drawText);

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);                        // switch back to normal framebuffer

Instead it is orange.

pixelsWidth and pixelsHeight are both equal to 64. I've made sure the viewport is set up correctly. Also glGetError() returns 0.

What have I missed?

matt_rule
  • 1,220
  • 1
  • 12
  • 23

1 Answers1

1

Took me 6 hours but the problem is solved. I was wrong. The viewport was not properly set. Before rendering to a texture, be sure to add the following line:

glViewport(0, 0, textureWidth, textureHeight);

And also unbind any currently bound textures using

glBindTexture(GL_TEXTURE_2D, 0);
matt_rule
  • 1,220
  • 1
  • 12
  • 23