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);						
}
Пример #2
0
/////////////
//DisplayLoop
/////////////
void display(void)
{
    //glPushMatrix();            //start matrix
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    //glColor3f(1.0, 1.0, 1.0);    //set color of rectangle


	//glEnable( GL_TEXTURE_2D );
	//glBindTexture( GL_TEXTURE_2D, tex );
    //glTranslatef(0.0, 0.0, -5.0);    //set origin of shape (5 units into the distance)
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	// Clear The Screen And The Depth Buffer
	glLoadIdentity();									// Reset The Matrix
	
	// 			 Position	      View		Up Vector
	gluLookAt(212, 60, 194,  186, 55, 171,  0, 1, 0);	// This Determines Where The Camera's Position And View Is

	glRotatef(rot, 0.0, 1.0, 0.0); //rotate 20 degrees around the x axis
	glTranslatef(-65.0, 00.0, -50.0);	
	
	glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue);

		RenderHeightMap(g_HeightMap);						// Render The Height Map


   /* glBegin(GL_QUADS);        //begin shape
	//glColor4f(1.0, 0.0, 0.0, 1.0);
	//glTexCoord2f(0, 0);
    glVertex3f(-1.0, -1.0, 0.0);    //draw each vertex
    
	//glColor4f(0.0, 1.0, 0.0, 1.0);
	//glTexCoord2f(1, 0);
	glVertex3f(1.0, -1.0, 0.0);
    
	//glColor4f(0.0, 0.0, 1.0, 1.0);
	//glTexCoord2f(1, 1);
	glVertex3f(1.0, 1.0, 0.0);
    
	//glColor4f(1.0, 1.0, 0.0, 1.0);
	//glTexCoord2f(0, 1);
	glVertex3f(-1.0, 1.0, 0.0);
    glEnd();  */              //end shape
    //glPopMatrix();            //end matrix

    glutSwapBuffers();

    rot += .1;            //increase rotation amount
}
Пример #3
0
int drawGLScene(GLvoid)									/* Here's Where We Do All The Drawing */
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);	/* Clear The Screen And The Depth Buffer */
    glLoadIdentity();									/* Reset The Matrix */

    /* 			 Position	      View		Up Vector */
    gluLookAt(212, 60, 194,  186, 55, 171,  0, 1, 0);	/* This Determines Where The Camera's Position And View Is */

    glScalef(scaleValue, scaleValue * HEIGHT_RATIO, scaleValue);

    RenderHeightMap(g_HeightMap);						/* Render The Height Map */

    return True;										/* Keep Going */
}
Пример #4
0
	/**
	* Clear the screen, then render the mesh using the given camera.
	* @param camera The logical camera to use.
	* @see math/camera.hpp
	*/
	void OpenglProject::render( const Camera* camera )
	{
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

		glMatrixMode(GL_PROJECTION);
		glLoadIdentity();
		gluPerspective(camera->fov * 180 / PI, camera->aspect, camera->near_clip, camera->far_clip);

		glMatrixMode(GL_MODELVIEW);
		glLoadIdentity();
		Vector3 eye = camera->get_position();
		Vector3 target = camera->get_position() + camera->get_direction();
		gluLookAt(eye.x, eye.y, eye.z, 
			target.x, target.y, target.z, 
			camera->get_up().x, camera->get_up().y, camera->get_up().z);

		RenderMesh();

		RenderHeightMap();
	}
Пример #5
0
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
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();

	// If we pass the g_HeightMap data into our RenderHeightMap() function it will
	// render the terrain in QUADS.  If you are going to make any use of this function,
	// it might be a good idea to put in an (X, Y) parameter to draw it at, or just use
	// OpenGL's matrix operations (glTranslatef() glRotate(), etc...)

	RenderHeightMap(g_HeightMap);						// Render the height map

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


	SwapBuffers(g_hDC);									// Swap the backbuffers to the foreground
}
Пример #7
0
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);
}
//////////////////////////////////////////////////////////////////////////
//캐릭터 툴을 위한 렌더 함수
//render를 pre - main - post renderring 구조에서 main을 담당
//////////////////////////////////////////////////////////////////////////
YAMANGDXDLL_API void RenderingTool( MESHOBJECT* inputVal )
{
	if ( NULL == g_D3dDevice )
	{
		return;
	}

	if ( g_Mesh == nullptr )
	{
		InitGroundMesh( 100, 100 );
	}
	g_D3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB( 30, 10, 10 ), 1.0f, 0 );

	// 렌더 방어코드
	if ( SUCCEEDED( g_D3dDevice->BeginScene() ) )
	{
		// SetupTranslateMatricesTool();
		// 일단 height map 등 다른 쪽을 생각할 것

		// ViewSetting();

		// lightsetting
		// 일단 1로 진행, 향후 라이트 개수 등 확정되면 인자 받아 설정
		int lightNum = 1;
		Lighting( lightNum );
		// Log( "라이팅 세팅!\n" );

		g_D3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
		g_D3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		g_D3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
		g_D3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

		// Log( "Render Begin \n" );
		// Log( "pre render 완료!\n" );
	}

	// 카메라 셋팅
	D3DXMATRIXA16 viewMatrix;
	D3DXMatrixLookAtLH( &viewMatrix, &g_EyePoint, &g_LookAtPoint, &g_UpVector );
	SetCameraMatrix( &viewMatrix );

	// 보여주기 위한 땅을 만듬
	//InitGroundMesh(100, 100);
	CreateRawGround( 100, 100, 10 );
	RenderHeightMap();

	g_D3dDevice->SetRenderState( D3DRS_FILLMODE, D3DFILL_SOLID );

	// Log( "Now Render : %p \n", inputVal );
	for ( DWORD i = 0; i < inputVal->NumMaterials; ++i )
	{
		g_D3dDevice->SetMaterial( &inputVal->MeshMarterials[i] );
		g_D3dDevice->SetTexture( 0, inputVal->MeshTexture[i] );

		( inputVal->importedMesh )->DrawSubset( i );
	}
	g_D3dDevice->EndScene();

	// Log( "Render End \n" );
	g_D3dDevice->Present( NULL, NULL, NULL, NULL );
}