本文整理汇总了C++中WINDOW::MakeCurrent方法的典型用法代码示例。如果您正苦于以下问题:C++ WINDOW::MakeCurrent方法的具体用法?C++ WINDOW::MakeCurrent怎么用?C++ WINDOW::MakeCurrent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WINDOW
的用法示例。
在下文中一共展示了WINDOW::MakeCurrent方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateFrame
//Perform per frame updates
void UpdateFrame()
{
window.Update();
camera.Update();
//Change anisotropy level
if( window.isKeyPressed(VK_UP) && EXT_texture_filter_anisotropic_supported &&
currentAnisotropy<maxAnisotropy)
{
window.MakeCurrent();
currentAnisotropy*=2;
glBindTexture(GL_TEXTURE_2D, pbufferTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, currentAnisotropy);
window.SetKeyReleased(VK_UP);
}
if( window.isKeyPressed(VK_DOWN) && EXT_texture_filter_anisotropic_supported &&
currentAnisotropy>1)
{
window.MakeCurrent();
currentAnisotropy/=2;
glBindTexture(GL_TEXTURE_2D, pbufferTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, currentAnisotropy);
window.SetKeyReleased(VK_DOWN);
}
//toggle mipmaps
if( window.isKeyPressed('M') && useMipmapFilter==false && SGIS_generate_mipmap_supported)
{
window.MakeCurrent();
glBindTexture(GL_TEXTURE_2D, pbufferTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, true);
useMipmapFilter=true;
}
if( window.isKeyPressed('L') && useMipmapFilter==true && SGIS_generate_mipmap_supported)
{
window.MakeCurrent();
glBindTexture(GL_TEXTURE_2D, pbufferTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, false);
useMipmapFilter=false;
}
//Pause/unpause
if(window.isKeyPressed('P'))
timer.Pause();
if(window.isKeyPressed('U'))
timer.Unpause();
//Swap between scenes in the pbuffer
if(window.isKeyPressed('1') && drawTextured)
{
//Draw wire tori
drawTextured=false;
}
if(window.isKeyPressed('2') && !drawTextured)
{
//draw textured sphere
drawTextured=true;
}
}
示例2: RenderFrame
//draw a frame
void RenderFrame()
{
//Draw to pbuffer
pbuffer.MakeCurrent();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); //reset modelview matrix
gluLookAt( 0.0f, 0.0f, 4.0f,
0.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f);
//Draw scene
if(drawTextured)
{
glBindTexture(GL_TEXTURE_2D, decalTexture);
glEnable(GL_TEXTURE_2D);
glPushMatrix();
glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f);
glutSolidTeapot(0.8f);
glPopMatrix();
glDisable(GL_TEXTURE_2D);
}
else
{
glPushMatrix();
glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f);
glRotatef(55.0f, 1.0f, 0.0f, 0.0f);
glutWireTorus(0.3f, 1.0f, 12, 24);
glPopMatrix();
glPushMatrix();
glRotatef(timer.GetTime()/20, 0.0f, 1.0f, 0.0f);
glRotatef(-55.0f, 1.0f, 0.0f, 0.0f);
glutWireTorus(0.3f, 1.0f, 12, 24);
glPopMatrix();
}
//Draw to window
window.MakeCurrent();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
camera.SetupViewMatrix();
glLoadMatrixf(camera.viewMatrix);
glBindTexture(GL_TEXTURE_2D, pbufferTexture);
//use the pbuffer as the texture
wglBindTexImageARB(pbuffer.hBuffer, WGL_FRONT_LEFT_ARB);
//Draw simple rectangle
glBegin(GL_TRIANGLE_STRIP);
{
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-1.0f, -1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f( 1.0f, -1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
}
glEnd();
//release the pbuffer for further rendering
wglReleaseTexImageARB(pbuffer.hBuffer, WGL_FRONT_LEFT_ARB);
fpsCounter.Update(); //update frames per second counter
glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
window.StartTextMode();
window.Print(0, 28, "FPS: %.2f", fpsCounter.GetFps()); //print the fps
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
window.Print(0, 48, "%dx Anisotropy", currentAnisotropy);
glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
window.Print(0, 68, "%s", useMipmapFilter ? "LINEAR_MIPMAP_LINEAR filtering" :
"LINEAR filtering");
window.EndTextMode();
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
if(window.isKeyPressed(VK_F1))
{
window.SaveScreenshot();
window.SetKeyReleased(VK_F1);
}
window.SwapBuffers(); //swap buffers
//check for any opengl errors
window.CheckGLError();
//quit if necessary
if(window.isKeyPressed(VK_ESCAPE))
//.........这里部分代码省略.........
示例3: GLInit
//Set up openGL
bool GLInit()
{
//Set up for pbuffer
pbuffer.MakeCurrent();
//set viewport
glViewport(0, 0, pbufferSize, pbufferSize);
//set up projection matrix
glMatrixMode(GL_PROJECTION); //select projection matrix
glLoadIdentity(); //reset
gluPerspective(45.0f, 1.0f, 1.0f, 100.0f);
//load identity modelview
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//other states
//shading
glShadeModel(GL_SMOOTH);
glClearColor( pbufferBackgroundColor.r,
pbufferBackgroundColor.g,
pbufferBackgroundColor.b,
pbufferBackgroundColor.a);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
//depth
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//hints
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
//Set up for window
window.MakeCurrent();
//set viewport
int height;
if (window.height==0)
height=1;
else
height=window.height;
glViewport(0, 0, window.width, height); //reset viewport
//set up projection matrix
glMatrixMode(GL_PROJECTION); //select projection matrix
glLoadIdentity(); //reset
gluPerspective(45.0f, (GLfloat)window.width/(GLfloat)height, 1.0f, 100.0f);
//load identity modelview
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//other states
//shading
glShadeModel(GL_SMOOTH);
glClearColor( windowBackgroundColor.r,
windowBackgroundColor.g,
windowBackgroundColor.b,
windowBackgroundColor.a);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
//depth
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
//hints
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_TEXTURE_2D);
return true;
}