예제 #1
0
// Called to draw scene
void RenderScene(void)
{
	// Clear the window with current clearing color
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glPushMatrix();
	frameCamera.ApplyCameraTransform();

	// Position light before any other transformations
	glLightfv(GL_LIGHT0, GL_POSITION, fLightPos);

	// Draw the ground
	glColor3f(0.60f, .40f, .10f);
	DrawGround();

	// Draw shadows first
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_LIGHTING);
	glPushMatrix();
	glMultMatrixf(mShadowMatrix);
	DrawInhabitants(1);
	glPopMatrix();
	glEnable(GL_LIGHTING);
	glEnable(GL_DEPTH_TEST);

	// Draw inhabitants normally
	DrawInhabitants(0);

	glPopMatrix();

	// Do the buffer Swap
	glutSwapBuffers();
	glutPostRedisplay();
}
예제 #2
0
// Called to draw scene
void RenderScene(void)
    {
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        
    glPushMatrix();
        frameCamera.ApplyCameraTransform();
        
        // Position light before any other transformations
        glLightfv(GL_LIGHT0, GL_POSITION, fLightPos);
        
        // Draw the ground
        glColor3f(1.0f, 1.0f, 1.0f);
        DrawGround();
        
        // Draw shadows first
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glDisable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_STENCIL_TEST);
        glPushMatrix();
            glMultMatrixf(mShadowMatrix);
            DrawInhabitants(1);
        glPopMatrix();
        glDisable(GL_STENCIL_TEST);
        glDisable(GL_BLEND);
        glEnable(GL_LIGHTING);
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_DEPTH_TEST);
        
        // Draw inhabitants normally
        DrawInhabitants(0);

    glPopMatrix();
        
    // Do the buffer Swap
    glutSwapBuffers();
    }
예제 #3
0
//////////////////////////////////////////////////
// Draw everything
void RenderScene(void)
{
    static int iFrames = 0;   // Count frames to calculate fps ever 100 frames
    static float fps = 0.0f;  // Calculated fps

    // Clear the window
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    glPushMatrix();
    frameCamera.ApplyCameraTransform();

    // Position light before any other transformations
    glLightfv(GL_LIGHT0, GL_POSITION, fLightPos);

    // Draw the ground
    glColor3f(1.0f, 1.0f, 1.0f);
    DrawGround();

    // Draw shadows first
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_LIGHTING);
    glDisable(GL_TEXTURE_2D);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glEnable(GL_STENCIL_TEST);
    glPushMatrix();
    glMultMatrixf(mShadowMatrix);
    DrawInhabitants(1);
    glPopMatrix();
    glDisable(GL_STENCIL_TEST);
    glDisable(GL_BLEND);
    glEnable(GL_LIGHTING);
    glEnable(GL_TEXTURE_2D);
    glEnable(GL_DEPTH_TEST);

    // Draw inhabitants normally
    DrawInhabitants(0);
    glPopMatrix();


    // Calculate Frame Rate, once every 100 frames
    iFrames++;
    if(iFrames == 100)
    {
        float fTime;

        // Get the current count
        LARGE_INTEGER lCurrent;
        QueryPerformanceCounter(&lCurrent);

        fTime = (float)(lCurrent.QuadPart - FPSCount.QuadPart) /
                (float)CounterFrequency.QuadPart;
        fps = (float)iFrames / fTime;


        // Reset frame count and timer
        iFrames = 0;
        QueryPerformanceCounter(&FPSCount);
    }

    // If we have the window position extension, display
    // the frame rate, and tell if multisampling was enabled
    // and if the VSync is turned on.
    if(glWindowPos2i != NULL)
    {
        int iRow = 10;
        char cBuffer[64];

        // Turn off depth test, lighting, and texture mapping
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glDisable(GL_TEXTURE_2D);
        glColor3f(1.0f, 1.0f, 1.0f);


        // Set position and display message
        glWindowPos2i(0, iRow);
        glListBase(nFontList);
        glCallLists (13, GL_UNSIGNED_BYTE, "OpenGL Rocks!");
        iRow+= 20;

        // Display the frame rate
        sprintf(cBuffer,"FPS: %.1f", fps);
        glWindowPos2i(0, iRow);
        glCallLists(strlen(cBuffer), GL_UNSIGNED_BYTE, cBuffer);
        iRow += 20;

        // MultiSampled?
        if(startupOptions.bFSAA == TRUE && startupOptions.nPixelFormatMS != 0)
        {
            glWindowPos2i(0, iRow);
            glCallLists(25 ,GL_UNSIGNED_BYTE,"Multisampled Frame Buffer");
            iRow += 20;
        }

        // VSync?
        if(wglSwapIntervalEXT != NULL && startupOptions.bVerticalSync == TRUE)
        {
            glWindowPos2i(0, iRow);
            glCallLists(9 ,GL_UNSIGNED_BYTE, "VSync On");
            iRow += 20;
        }


        // Put everything back
        glEnable(GL_DEPTH_TEST);
        glEnable(GL_LIGHTING);
        glEnable(GL_TEXTURE_2D);
    }
}
예제 #4
0
// Called to draw scene
void RenderScene(void)
    {
    static int iFrames = 0;             // Frame count
    static CStopWatch frameTimer;       // Render time
    
    // Clear the window with current clearing color
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
        
    glPushMatrix();
        frameCamera.ApplyCameraTransform();
        
        // Position light before any other transformations
        glLightfv(GL_LIGHT0, GL_POSITION, fLightPos);
        
        // Draw the ground
        glColor3f(1.0f, 1.0f, 1.0f);
        if(iMethod == 0)
            DrawGround();
        else
            glCallList(groundList);
        
        // Draw shadows first
        glDisable(GL_DEPTH_TEST);
        glDisable(GL_LIGHTING);
        glDisable(GL_TEXTURE_2D);
        glEnable(GL_BLEND);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glEnable(GL_STENCIL_TEST);
        glPushMatrix();
            glMultMatrixf(mShadowMatrix);
            DrawInhabitants(1);
        glPopMatrix();
        glDisable(GL_STENCIL_TEST);
        glDisable(GL_BLEND);
        glEnable(GL_LIGHTING);
        glEnable(GL_TEXTURE_2D);
        glEnable(GL_DEPTH_TEST);
        
        // Draw inhabitants normally
        DrawInhabitants(0);

    glPopMatrix();
        
    // Do the buffer Swap
    glutSwapBuffers();

    // Increment the frame count
    iFrames++;

    // Do periodic frame rate calculation
    if(iFrames == 100)
        {
        float fps;
        char cBuffer[64];
        
        fps = 100.0f / frameTimer.GetElapsedSeconds();
        if(iMethod == 0)
            sprintf(cBuffer,"OpenGL SphereWorld without Display Lists %.1f fps", fps);
        else
            sprintf(cBuffer,"OpenGL SphereWorld with Display Lists %.1f fps", fps);
            
        glutSetWindowTitle(cBuffer);
        
        frameTimer.Reset();
        iFrames = 0;
        }

    }