0
我有一個3D場景和一個對象,我想保存一個與當前屏幕不同的對象的視圖。 所以我想我只需要做這樣的事情(僞代碼):在OpenGL中保存一個特定的攝像頭視圖爲
PushMatrix()
LoadIdentity()
TranslateAndRotate()
gluperspective()
setViewport()
DrawScene()
saveScreenshot()
PopMatrix()
但我只得到我的相機,不是我指定的當前視圖的圖片。 我忘了什麼嗎?
編輯: 因爲下面的答案,我想下面的代碼:
void ScenePhotograph(GLubyte* Target, float *Translation, float RotationAroundY)
{
glMatrixMode(GL_PROJECTION);
gluPerspective(54.0f, (GLfloat)openGLControl1->Width/(GLfloat)openGLControl1->Height, 1.0f, 3000.0f);
glViewport(0,0,openGLControl1->Width, openGLControl1->Height);
glMatrixMode(GL_MODELVIEW);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(Translation[0],Translation[1],Translation[2]);
glRotatef(RotationAroundY, 0,1,0);
openGLControl1_OnDrawGL(NULL,System::EventArgs::Empty);
openGLControl1->Refresh();
glReadPixels(0, 0, openGLControl1->Width, openGLControl1->Height, GL_RGB, GL_UNSIGNED_BYTE, Target);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
cam->SetView();
openGLControl1_OnDrawGL(NULL,System::EventArgs::Empty);
openGLControl1->Refresh();
glutSwapBuffers();
}
這是給我的glutSwapBuffers訪問衝突(); 任何想法?
是否可以使用矩陣推&流而不是再次使用它來獲得我的前矩陣? – 2013-05-09 14:20:22
我不這麼認爲。你要做的第一件事就是設置相機的位置。所以,如果這種情況正在發生改變,我認爲你不能通過push和pop來保存你的矩陣。 – Amadeus 2013-05-09 14:25:32
@MartinHennig:你可以使用'glGetFloatv'和'GL_MODELVIEW_MATRIX'和'GL_PROJECTION_MATRIX'來存儲另一個視圖的矩陣,然後使用'glLoadIdentity(); glLoadMatrix();'你的存儲值。 – Nobody 2013-05-09 15:12:32