Ejemplo n.º 1
0
void RenderScene() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();									// Reset The matrix

	// Position the camera
	g_Camera.Look();

	// Each frame we calculate the new frustum.  In reality you only need to
	// calculate the frustum when we move the camera.
	g_Frustum.CalculateFrustum();

	// Initialize the total node count that is being draw per frame
	g_TotalNodesDrawn = 0;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// Here we draw the octree, starting with the root node and recursing down each node.
	// This time, we pass in the root node and just the original world model.  You could
	// just store the world in the root node and not have to keep the original data around.
	// This is up to you.  I like this way better because it's easy, though it could be 
	// more error prone.
	g_Octree.DrawOctree(&g_Octree, &g_World);

	// Render the cubed nodes to visualize the octree (in wire frame mode)
	if( g_bDisplayNodes )
		g_Debug.RenderDebugLines();

	// Create a buffer to store the octree information for the title bar
	static char strBuffer[255] = {0};

	// Display in window mode the current subdivision information.  We now display the
	// max triangles per node, the max level of subdivision, total end nodes, current nodes drawn
	// and frames per second we are receiving.  
	sprintf(strBuffer, "Triangles: %d        Subdivisions: %d        EndNodes: %d          NodesDraw: %d          FPS: %s",
		                g_MaxTriangles,		 g_MaxSubdivisions,		 g_EndNodeCount,	   g_TotalNodesDrawn,	  g_strFrameRate);

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


	// Set our window title bar to the subdivision information
	SetWindowText(g_hWnd, strBuffer);

	// Swap the backbuffers to the foreground
	SwapBuffers(g_hDC);									
}
Ejemplo n.º 2
0
void RenderScene() 
{
	int i = 0;

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The matrix

	// Tell OpenGL where to look from our camera info
	g_Camera.Look();

	// Calculate our frustum to check the world data again for PVS and Portal Rendering
	g_Frustum.CalculateFrustum();

	// Render the level to the screen
	g_Level.RenderLevel(g_Camera.Position());

	// Swap the backbuffers to the foreground
	SwapBuffers(g_hDC);	
}
Ejemplo n.º 3
0
void RenderScene()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    glLoadIdentity();									// Reset The matrix

    // Give OpenGL our camera position
    g_Camera.Look();

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // Each frame we calculate the new frustum.  In reality you only need to
    // calculate the frustum when we move the camera.
    g_Frustum.CalculateFrustum();

    // Initialize the total node count that is being draw per frame
    g_TotalNodesDrawn = 0;

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // Here we draw the octree, starting with the root node and recursing down each node.
    // When we get to each of the end nodes we will draw the vertices assigned to them.
    g_Octree.DrawOctree(&g_Octree);

    // Render the cube'd nodes to visualize the octree (in wire frame mode)
    g_Debug.RenderDebugLines();

    SwapBuffers(g_hDC);									// Swap the backbuffers to the foreground

    char strBuffer[255] = {0};							// Create a character buffer

    // To view our octree information I set the window's title bar to the some basic
    // information such as the max triangles per node, the max subdivisions,
    // total end nodes and the total drawn end nodes that are currently in the frustum.

    // Display in window mode the current subdivision information
    sprintf(strBuffer, "MaxTriangles: %d     MaxSubdivisions: %d     TotalEndNodes: %d       TotalNodesDraw: %d",
            g_MaxTriangles,		 g_MaxSubdivisions,		 g_EndNodeCount,		 g_TotalNodesDrawn);

    // Set our window title bar to the subdivision data
    SetWindowText(g_hWnd, strBuffer);
}
Ejemplo n.º 4
0
void RenderScene()
{

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    int spheresRendered = 0;							// This will hold how many spheres are being rendered
    char strText[255]= {0};								// This will hold the window title info

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    glLoadIdentity();									// Reset The matrix

    // Give OpenGL our camera position
    g_Camera.Look();

    // We don't need to calculate this every frame, only when the camera view changes.
    // I just did it every frame anyway.  In this case it isn't a big deal.
    g_Frustum.CalculateFrustum();						// Calculate the frustum each frame

    // If you are unfamiliar with Quadrics, see the tutorial on Quadrics at www.GameTutorials.com.
    // They basically allow you to draw circles and cylinders fast and easily.

    GLUquadricObj *pObj = gluNewQuadric();				// Get a Quadric off the stack

    // Loop through all of our allowed spheres and render them to the screen if in the frustum.
    for(int i = 0; i < g_MaxSpheres; i++)				// g_MaxSpheres varies.
    {
        g_Spheres[i].zPos += SPHERE_SPEED;				// Increase the Z position of the sphere.

        // Below we check if the sphere needs to be draw or not.  If g_bIgnoreFrustum is TRUE,
        // it draws it regardless (which is SLOOOooOoW).  We just pass in the (X, Y, Z)
        // and the radius of the sphere to find out if it is inside of the frustum.

        if(g_bIgnoreFrustum || g_Frustum.SphereInFrustum(g_Spheres[i].xPos, g_Spheres[i].yPos, g_Spheres[i].zPos, g_Spheres[i].radius))
        {
            // Set the sphere's color
            glColor3ub(g_Spheres[i].r, g_Spheres[i].g, g_Spheres[i].b);

            // Create a new scope before positiong the sphere so we don't effect the other spheres.
            glPushMatrix();

            // Position the sphere on the screen at it's XYZ position.
            glTranslatef(g_Spheres[i].xPos, g_Spheres[i].yPos, g_Spheres[i].zPos);

            // Create a sphere with the desired radius chosen in the beginning.
            gluSphere(pObj, g_Spheres[i].radius, 20, 20);	// Draw the sphere with a radius of 0.5
            glPopMatrix();								// Close the scope of this matrix

            spheresRendered++;							// Increase the amount of spheres rendered
        }

        // Here we check to see if the sphere went out of our range,
        // If so, we need to set it back again with a new random position.
        if(g_Spheres[i].zPos > MAX_DISTANCE) {
            // Give the sphere a new random position back in the beginning.
            g_Spheres[i].xPos = (rand() % (MAX_DISTANCE * 10)) * 0.1f;
            g_Spheres[i].yPos = (rand() % (MAX_DISTANCE * 10)) * 0.1f;
            g_Spheres[i].zPos = -MAX_DISTANCE;			// Send it to the back again.

            // Give a 50/50 chance for the sphere to be to the left/right or above/below the XY axis.
            // This is because we are centered at the origin
            if(rand() % 2) g_Spheres[i].xPos = -g_Spheres[i].xPos;
            if(rand() % 2) g_Spheres[i].yPos = -g_Spheres[i].yPos;
        }
    }

    // Since I didn't want to add more code for a rendered font, I decided to just
    // render the frustum information in the title bar of the window.
    // The information tells you how many spheres were rendered and out of how many.
    // Use +/- to increase and decrease the max spheres tested.

    sprintf(strText, "www.GameTutorials.com - Spheres Rendered: %d / %d", spheresRendered, g_MaxSpheres);
    SetWindowText(g_hWnd, strText);						// Change the window title bar

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    SwapBuffers(g_hDC);									// Swap the backbuffers to the foreground
    gluDeleteQuadric(pObj);								// Free the Quadric
}