本文整理汇总了C++中TIMER::GetTime方法的典型用法代码示例。如果您正苦于以下问题:C++ TIMER::GetTime方法的具体用法?C++ TIMER::GetTime怎么用?C++ TIMER::GetTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TIMER
的用法示例。
在下文中一共展示了TIMER::GetTime方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: UpdateFrame
//Perform per-frame updates
void UpdateFrame()
{
//set currentTime and timePassed
static double lastTime=timer.GetTime();
double currentTime=timer.GetTime();
double timePassed=currentTime-lastTime;
lastTime=currentTime;
//Update window
WINDOW::Instance()->Update();
//Update the lights
for(int i=0; i<numLights; ++i)
{
lights[i].position+=lights[i].velocity*float(timePassed)/1000;
//bounce off the borders
if(lights[i].position.x>1.0f && lights[i].velocity.x>0.0f)
lights[i].velocity.x=-lights[i].velocity.x;
if(lights[i].position.x<-1.0f && lights[i].velocity.x<0.0f)
lights[i].velocity.x=-lights[i].velocity.x;
if(lights[i].position.z>1.0f && lights[i].velocity.z>0.0f)
lights[i].velocity.z=-lights[i].velocity.z;
if(lights[i].position.z<-1.0f && lights[i].velocity.z<0.0f)
lights[i].velocity.z=-lights[i].velocity.z;
}
//Toggle vertex program/fixed function
if(WINDOW::Instance()->IsKeyPressed('1') && GLEE_NV_vertex_program)
{
useVP1=true;
useVP2=false;
useFixedFunction=false;
}
if(WINDOW::Instance()->IsKeyPressed('2') && GLEE_NV_vertex_program2)
{
useVP1=false;
useVP2=true;
useFixedFunction=false;
}
if(WINDOW::Instance()->IsKeyPressed('3'))
{
useVP1=false;
useVP2=false;
useFixedFunction=true;
}
//Render frame
RenderFrame(currentTime, timePassed);
}
示例2: RenderFrame
//draw a frame
void RenderFrame()
{
//Clear buffers
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); //reset modelview matrix
glEnable(GL_LIGHTING);
glTranslatef(0.0f, 0.0f, -30.0f);
glRotatef((float)timer.GetTime()/30, 1.0f, 0.0f, 1.0f);
cubeGrid.DrawSurface(threshold);
glDisable(GL_LIGHTING);
fpsCounter.Update(); //update frames per second counter
glColor4f(0.0f, 0.0f, 1.0f, 1.0f);
window.StartTextMode();
window.Print(0, 28, "FPS: %.2f", fpsCounter.GetFps()); //print the fps
glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
window.Print(0, 48, "Grid Size: %d", gridSize);
window.Print(0, 68, "%d triangles drawn", cubeGrid.numFacesDrawn);
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))
PostQuitMessage(0);
}
示例3: Display
//Called to draw scene
void Display(void)
{
//angle of spheres in scene. Calculate from time
float angle=timer.GetTime()/10;
//First pass - from light's point of view
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(lightProjectionMatrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(lightViewMatrix);
//Use viewport the same size as the shadow map
glViewport(0, 0, shadowMapSize, shadowMapSize);
//Draw back faces into the shadow map
glCullFace(GL_FRONT);
//Disable color writes, and use flat shading for speed
glShadeModel(GL_FLAT);
glColorMask(0, 0, 0, 0);
//Draw the scene
DrawScene(angle);
//Read the depth buffer into the shadow map texture
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, shadowMapSize, shadowMapSize);
//restore states
glCullFace(GL_BACK);
glShadeModel(GL_SMOOTH);
glColorMask(1, 1, 1, 1);
//2nd pass - Draw from camera's point of view
glClear(GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(cameraProjectionMatrix);
glMatrixMode(GL_MODELVIEW);
glLoadMatrixf(cameraViewMatrix);
glViewport(0, 0, windowWidth, windowHeight);
//Use dim light to represent shadowed areas
glLightfv(GL_LIGHT1, GL_POSITION, VECTOR4D(lightPosition));
glLightfv(GL_LIGHT1, GL_AMBIENT, white*0.2f);
glLightfv(GL_LIGHT1, GL_DIFFUSE, white*0.2f);
glLightfv(GL_LIGHT1, GL_SPECULAR, black);
glEnable(GL_LIGHT1);
glEnable(GL_LIGHTING);
DrawScene(angle);
//3rd pass
//Draw with bright light
glLightfv(GL_LIGHT1, GL_DIFFUSE, white);
glLightfv(GL_LIGHT1, GL_SPECULAR, white);
//Calculate texture matrix for projection
//This matrix takes us from eye space to the light's clip space
//It is postmultiplied by the inverse of the current view matrix when specifying texgen
static MATRIX4X4 biasMatrix(0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f); //bias from [-1, 1] to [0, 1]
MATRIX4X4 textureMatrix=biasMatrix*lightProjectionMatrix*lightViewMatrix;
//MATRIX4X4 textureMatrix=lightProjectionMatrix*lightViewMatrix;
//Set up texture coordinate generation.
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_S, GL_EYE_PLANE, textureMatrix.GetRow(0));
glEnable(GL_TEXTURE_GEN_S);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_T, GL_EYE_PLANE, textureMatrix.GetRow(1));
glEnable(GL_TEXTURE_GEN_T);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_R, GL_EYE_PLANE, textureMatrix.GetRow(2));
glEnable(GL_TEXTURE_GEN_R);
glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGenfv(GL_Q, GL_EYE_PLANE, textureMatrix.GetRow(3));
glEnable(GL_TEXTURE_GEN_Q);
//Bind & enable shadow map texture
glBindTexture(GL_TEXTURE_2D, shadowMapTexture);
glEnable(GL_TEXTURE_2D);
//.........这里部分代码省略.........