我正在使用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();
以下是我迄今为止尝试过的事情: