Question

Rendering to a FBO then to the screen buffer appears to make the texture darker. As seen here -> http://imgur.com/QZNyY8U

RenderTarget target = new RenderTarget(Display.getWidth(), Display.getHeight());

RenderTarget class can be found here : http://pastebin.com/anpBPsgv

GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);  

// set the color of the quad (R,G,B,A)
GL11.glColor4f(5/255f, 35/255f,70/255f, 1f);

//Bind Render Target
target.bind();

// draw quad on FBO
GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f(0,0);
    GL11.glVertex2f(0+200,0);
    GL11.glVertex2f(0+200,0+200);
    GL11.glVertex2f(0,0+200);
GL11.glEnd();

target.unBind();

glEnable(GL_TEXTURE_2D); // enable texturing
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);// switch to rendering on the framebuffer
glClearColor (0.0f, 0.0f, 0.0f, 1.0f);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);// Clear Screen And Depth Buffer on the framebuffer to black
glBindTexture(GL_TEXTURE_2D, target.colorTextureID);    // bind our FBO texture

//Draw FBO on screen buffer
glBegin(GL_QUADS);
   glTexCoord2f(0.0f, 0.0f); glVertex2i(0,   0);  
   glTexCoord2f(1.0f, 0.0f); glVertex2i(Display.getWidth(),  0); 
   glTexCoord2f(1.0f, 1.0f); glVertex2i(Display.getWidth(), Display.getHeight()); 
   glTexCoord2f(0.0f, 1.0f); glVertex2i(0, Display.getHeight());
glEnd();

glDisable(GL_TEXTURE_2D);

//Draw same colour image without gonig through FBO
GL11.glBegin(GL11.GL_QUADS);
    GL11.glVertex2f(200,0);
    GL11.glVertex2f(200+200,0);
    GL11.glVertex2f(200+200,0+200);
    GL11.glVertex2f(200,0+200);
GL11.glEnd();

glFlush ();

Classes used can be found here pastebin.com/YRChp5vB and here pastebin.com/anpBPsgv

Was it helpful?

Solution

Rendering to texture is not darker. You just draw the texture darker:

GL11.glColor4f(5/255f, 35/255f,70/255f, 1f);

you never reset this to white, so the color stays as it is. By default, GL uses the GL_MODULATE texture environment mode, so the texture color gets multiplied by the color you have set. See this question for any details.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top