我正在使用 glReadPixels 在我的游戏(例如游戏中、菜单中等)中创建状态的最终帧的副本,以用于过渡效果。我得到了那个副本,但它似乎比原版更暗:
这是相关代码:
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
- 手动调亮像素(惨败)