glReadPixels返回较暗的图像

时间:2012-05-29 05:12:52

标签: c++ opengl

我正在使用glReadPixels创建游戏中状态的最终帧的副本(例如游戏中,菜单中等等)以用于过渡效果。我得到那份副本,但它看起来比原来的要暗:

enter image description here

这是相关代码:

void GameStateManager::GetLastFrame()
{
    if (last_frame_buffer.id != 0)
        glDeleteTextures(1,&last_frame_buffer.id);

    uint8* data = new uint8[Constants::SCREEN_WIDTH * Constants::SCREEN_HEIGHT*3];


    glReadPixels(0,0,Constants::SCREEN_WIDTH,Constants::SCREEN_HEIGHT,GL_RGB,GL_UNSIGNED_BYTE,data);

    last_frame_buffer.target = GL_TEXTURE_RECTANGLE_ARB;

    glGenTextures(1,&last_frame_buffer.id);
    glBindTexture(last_frame_buffer.target,last_frame_buffer.id);
    glTexParameterf(last_frame_buffer.target,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
    glTexParameterf(last_frame_buffer.target,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
    glTexImage2D(last_frame_buffer.target,0,GL_RGB,Constants::SCREEN_WIDTH,Constants::SCREEN_HEIGHT,0,GL_RGB,GL_UNSIGNED_BYTE,data);
    glBindTexture(last_frame_buffer.target,0);

    delete[] data;
}

这是实际的渲染代码:

    glPushMatrix();
        glTranslatef(0,last_frame_pos,0);
        glCallList(last_frame_quad);
    glPopMatrix();

这是显示列表:

  glBegin(GL_QUADS);
        glTexCoord2f(0     , 0);     glVertex2f(0    , height);
        glTexCoord2f(0    , height); glVertex2f(0    , 0);
        glTexCoord2f(width, height); glVertex2f(width, 0);
        glTexCoord2f(width, 0);      glVertex2f(width, height);
  glEnd();

以下是我迄今为止尝试过的事情:

  • 更改缓冲区格式:BYTE(图像更暗),UNSIGNED_SHORT,UNSIGNED_INT,FLOAT
  • 启用/禁用:TEXTURE_2D,TEXTURE_RECTANGLE,BLEND
  • 手动照亮像素(悲惨地失败)

0 个答案:

没有答案