コード例 #1
0
void Draw(void)													// Draw Our Scene
{
	glEnable(GL_MULTISAMPLE_ARB);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear Screen And Depth Buffer										
	glEnable(GL_DEPTH_TEST);
	
#pragma region DRAWING_DATE_TO_THE_SCREEN
	glLoadIdentity();
	glDisable(GL_LIGHTING);
	glColor3f(1, 1, 1);
	glRasterPos3f(0.5, 0.5, -1);
	font.glPrint(t.AsString().c_str());
	glEnable(GL_LIGHTING);
#pragma endregion

	glLoadIdentity();
	g_Camera.Update(centerX, centerY, orientationMode);
	CreateSkyBox(0, 0, 0, 400, 400, 400);
	SolarSystem.render(t, app);
	prev_x = centerX;
	prev_y = centerY;

	glLightfv(GL_LIGHT0, GL_POSITION, g_LightPosition);
	glFlush();													// Flush The GL Rendering Pipeline
}
コード例 #2
0
void RenderScene() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The matrix
	

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

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

	// Here we create our sky box.  It will be centered around (0, 0, 0) with
	// a width of 400, height of 200 and length of 400.  You might wonder why we
	// don't make it a perfect cube?  Well, if we make the height half the size
	// of the width and length it looks better.  Try putting the height to 400 and
	// you will notice that everything looks really close up.  You will want to tweak
	// this ratio most likely for every sky maps you use.  Some look better at different
	// perspectives and ratios.  Try changing the height to 100.  It looks more flat
	// and at a greater distance.  

	// Draw the sky box centered at (0, 0, 0)
	CreateSkyBox(0, 0, 0, 400, 200, 400);

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


	SwapBuffers(g_hDC);									// Swap the backbuffers to the foreground
}
コード例 #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();

	// Render the height map
	RenderHeightMap(g_HeightMap);						


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

	// Just for an added effect, I created a sky box that surrounds the terrain,
	// along with a check to make sure the camera doesn't go through the terrain.
	// It's as simple and checking the height of the current x and z position
	// of the camera, and making sure that the camera's y position isn't lower
	// than the height of the terrain at that point.  This is a simple check,
	// and of course will produce choppy results.  In a future tutorial we will
	// have some good smooth collision detection along the terrain.

	// Create the sky box and center it around the terrain
	CreateSkyBox(500, 0, 500, 2000, 2000, 2000);

	// Get the current position of the camera
	CVector3 vPos		= g_Camera.Position();
	CVector3 vNewPos    = vPos;

	// Check if the camera is below the height of the terrain at x and z,
	// but we add 10 to make it so the camera isn't on the floor.
	if(vPos.y < Height(g_HeightMap, (int)vPos.x, (int)vPos.z ) + 10)
	{
		// Set the new position of the camera so it's above the terrain + 10
		vNewPos.y = (float)Height(g_HeightMap, (int)vPos.x, (int)vPos.z ) + 10;

		// Get the difference of the y that the camera was pushed back up
		float temp = vNewPos.y - vPos.y;

		//  Get the current view and increase it by the different the position was moved
		CVector3 vView = g_Camera.View();
		vView.y += temp;

		// Set the new camera position.
		g_Camera.PositionCamera(vNewPos.x,  vNewPos.y,  vNewPos.z,
								vView.x,	vView.y,	vView.z,	0, 1, 0);								
	}

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


	// Swap the backbuffers to the foreground
	SwapBuffers(g_hDC);
	assert(glGetError() == GL_NO_ERROR);						
}
コード例 #4
0
void DemoEntityManager::DeserializedPhysicScene (const char* const name)
{
	// add the sky
	CreateSkyBox();

	dQuaternion rot;
	dVector origin (-30.0f, 10.0f, 10.0f, 0.0f);
	SetCameraMatrix(rot, origin);

	dTree <DemoMeshInterface*, const void*> cache;
	NewtonDeserializeFromFile (m_world, name, BodyDeserialization, &cache);
}
コード例 #5
0
ファイル: Main.cpp プロジェクト: Allenjonesing/tutorials
void RenderScene() 
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The matrix
	
	// Get the current position of the camera
	CVector3 vPos		= g_Camera.Position();
	CVector3 vNewPos    = vPos;

	// Check if the camera is below the height of the terrain at x and z,
	// but we add 10 to make it so the camera isn't on the floor.
	if(vPos.y < Height(g_HeightMap, (int)vPos.x, (int)vPos.z ) + 10)
	{
		// Set the new position of the camera so it's above the terrain + 10
		vNewPos.y = (float)Height(g_HeightMap, (int)vPos.x, (int)vPos.z ) + 10;

		// Get the difference of the y that the camera was pushed back up
		float temp = vNewPos.y - vPos.y;

		//  Get the current view and increase it by the different the position was moved
		CVector3 vView = g_Camera.View();
		vView.y += temp;

		// Set the new camera position.
		g_Camera.PositionCamera(vNewPos.x,  vNewPos.y,  vNewPos.z,
								vView.x,	vView.y,	vView.z,	0, 1, 0);								
	}

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

	// Render the height map
	RenderHeightMap(g_HeightMap);						

	// Create the sky box and center it around the terrain
	CreateSkyBox(500, 0, 500, 2000, 2000, 2000);

	// Swap the backbuffers to the foreground
	SwapBuffers(g_hDC);									
}
コード例 #6
0
ファイル: Main.cpp プロジェクト: jiangguang5201314/ZNginx
void RenderScene()
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
    glLoadIdentity();									// Reset The matrix

    // Get the current position of the camera
    CVector3 vPos		= g_Camera.Position();
    CVector3 vNewPos    = vPos;

    // Check if the camera is below the height of the terrain at x and z,
    // but we add 10 to make it so the camera isn't on the floor.
    if(vPos.y < Height(g_HeightMap, (int)vPos.x, (int)vPos.z ) + 10)
    {
        // Set the new position of the camera so it's above the terrain + 10
        vNewPos.y = (float)Height(g_HeightMap, (int)vPos.x, (int)vPos.z ) + 10;

        // Get the difference of the y that the camera was pushed back up
        float temp = vNewPos.y - vPos.y;

        //  Get the current view and increase it by the different the position was moved
        CVector3 vView = g_Camera.View();
        vView.y += temp;

        // Set the new camera position.
        g_Camera.PositionCamera(vNewPos.x,  vNewPos.y,  vNewPos.z,
                                vView.x,	vView.y,	vView.z,	0, 1, 0);
    }

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


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

    // Here comes the most technical part of our tutorial--clipping planes.
    // We turn the terrain upside-down, so we don't want the bottom sticking
    // out of the water, so we need to create a clipping plane that will
    // clip anything that is above it.  In this case, (0, -1, 0) is the normal
    // of the plane to clip, and we finally give it out distance from the
    // origin--g_WaterHeight.
    double reflectPlane[] = {0.0f, -1.0f, 0.0f, g_WaterHeight};

    glEnable(GL_CLIP_PLANE0);							// Turn on clipping for plane 0

    // This is where we select the clipping plane we want to use, and then the
    // plane's data is passed in as an array of floats (ABC and D).  You can have
    // many clipping planes going, which is why we need to specify which one we want.
    glClipPlane(GL_CLIP_PLANE0, reflectPlane);

    // Now comes the reflection!
    // Pop on a new matrix so our translation/scaling doesn't effect other data
    glPushMatrix();

    // We first need to translate the terrain to the water height multiplied by 2,
    // since we are reflecting it upside down at that height.
    glTranslatef(0.0f, g_WaterHeight*2.0f, 0.0f);

    // We then use glScale() to flip the terrain upside-down (-1 flips it).
    glScalef(1.0, -1.0, 1.0);

    // Since the terrain is upside-down we need to do front-face culling.
    glCullFace(GL_FRONT);

    // Now we render the terrain and the skybx upside-down for the reflection.
    RenderHeightMap(g_HeightMap);
    CreateSkyBox(500, 0, 500, 2000, 2000, 2000);

    // Now we can restore the app to back-face culling
    glCullFace(GL_BACK);

    // Leave the previous matrix and go back to the original matrix
    glPopMatrix();

    // Since the reflection is already drawn, let's turn off clipping.
    glDisable(GL_CLIP_PLANE0);

    // Now we actually draw the water blended over the reflection, which
    // creates the effect that the reflection is in the water.  We blend
    // with a simple alpha to one minus alpha blending function.  The color
    // is set to a blue, with the alpha value at 50% (0.5).  We don't want
    // the alpha too high or else we wouldn't see the reflection.
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4f(0.5f, 0.5f, 0.9f, 0.5f);
    DrawWater(g_WaterHeight);
    glDisable(GL_BLEND);

    // Render the height map normally, right-side-up.
    RenderHeightMap(g_HeightMap);

    // Create the sky box and center it around the terrain
    CreateSkyBox(500, 0, 500, 2000, 2000, 2000);

    // This block of code right here is for an added effect of
    // what is draw when you are under the water.  This isn't necessary,
    // but I thought I would add it to improve the tutorial's realism.
    // When we go underwater we want to be able to look up out of the
    // water.  To do that we just render the water again, but change
    // the culling to front-face, then change our water color.  Nothing special.
    // We could just do a check to see if we are under or over the water,
    // then only render the water once, but I think you can do that yourself.
    glCullFace(GL_FRONT);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4f(0.0f, 0.0f, 0.9f, 0.5f);
    DrawWater(g_WaterHeight);
    glDisable(GL_BLEND);
    glCullFace(GL_BACK);

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


    // Swap the backbuffers to the foreground
    SwapBuffers(g_hDC);
}
コード例 #7
0
ファイル: SkyBoxHandler.cpp プロジェクト: Meraz/doremi
 SkyBoxHandler::SkyBoxHandler(const DoremiEngine::Core::SharedContext& p_sharedContext) : m_sharedContext(p_sharedContext) { CreateSkyBox(); }