1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
ViewportPositionX=0;
ViewportPositionY=0;
ViewportWidth=512;
ViewportHeight=512;
Fovy=60.0;
Aspect=512/512;
ZNear=1.0;
ZFar=100.0;
RealTextureWidth=512;
RealTextureHeight=512;
glViewport(ViewportPositionX, ViewportPositionY, ViewportWidth, ViewportHeight);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(Fovy, Aspect, ZNear, ZFar);
glClearColor(1, 1, 1, 1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(Light->GetPositionX(),Light->GetPositionY(),Light->GetPositionZ(),Light->GetTargetX(),Light->GetTargetY(),Light->GetTargetZ(),Light->GetUpVector().x,Light->GetUpVector().y,Light->GetUpVector().z);
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_PIXEL_MODE_BIT); // for GL_DRAW_BUFFER and GL_READ_BUFFER
glDrawBuffer(GL_BACK);
glReadBuffer(GL_BACK);
DrawScene();
glEnable(GL_TEXTURE_2D);
// copy the framebuffer pixels to a texture
glBindTexture(GL_TEXTURE_2D, TextureId);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, RealTextureWidth, RealTextureHeight);
glBindTexture(GL_TEXTURE_2D, 0);
glDisable(GL_TEXTURE_2D);
glPopAttrib();
// back to normal viewport and projection matrix
glViewport(0, 0, GSEApplication->GetSizeX(), GSEApplication->GetSizeY());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(GSEApplication->GetVerticalAngle(), (float)(GSEApplication->GetSizeX())/GSEApplication->GetSizeY(), GSEApplication->GetDepthMinimumView(), GSEApplication->GetDepthMaximumView());
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
// clear framebuffer
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
gluLookAt(GSECamera->GetPositionX(),GSECamera->GetPositionY(),GSECamera->GetPositionZ(),GSECamera->GetTargetX(),GSECamera->GetTargetY(),GSECamera->GetTargetZ(),GSECamera->GetUpVector().x,GSECamera->GetUpVector().y,GSECamera->GetUpVector().z);
DrawScene(); |
Partager