为什么渲染到FBO会导致纹理变暗?

时间:2013-05-19 12:50:53

标签: java opengl rendering fbo

渲染到FBO然后到屏幕缓冲区似乎使纹理更暗。 如此处所示 - > http://imgur.com/QZNyY8U

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

可以在此处找到RenderTarget类: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 ();

使用的类可在此处找到 pastebin.com/YRChp5vB ,此处 pastebin.com/anpBPsgv

1 个答案:

答案 0 :(得分:2)

渲染到纹理不是更暗。你只是将纹理画得更暗:

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

您永远不会将其重置为白色,因此颜色保持不变。默认情况下,GL使用GL_MODULATE纹理环境模式,因此纹理颜色乘以您设置的颜色。有关详细信息,请参阅this question