コード例 #1
0
ファイル: main.cpp プロジェクト: JackTing/shadows
/**
   Callback that occurs when glut thinks its time to redraw the window.
*/
void handleDisplay()
{
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

   // update the light position
   glLightfv(GL_LIGHT0, GL_POSITION, lightPosition0);

   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
   setCamera();

   // draw the light source
   drawLightSource();

   // draw the wall background
   drawBackdropGeometry();

   // draw scene objects
   glColor3f(0.0,0.0,1.0);
   drawScene();

   // calc and draw shadows
   if (shadowsOn && light0On)
   {
      calculateShadows(floorPlane);
      drawShadows();
      calculateShadows(wallPlane);
      drawShadows();
   }

   glFlush();
   glutSwapBuffers();
}
コード例 #2
0
void display (void)
{
	glClearColor (0.0, 0.0, 0.0, 0.0);
	glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glShadeModel (GL_SMOOTH);
	//glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );  // WIREFRAME
	
	displayFog();

	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glLightfv(GL_LIGHT0, GL_POSITION, light_position);

	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity();

	camera.update();

	glDisable(GL_CULL_FACE);
	skybox.display();
	glEnable(GL_CULL_FACE);

	table.display();
	drawShadows();
	mainGear.display();
	powerGear.display();
	smallMiddleGear.display();
	bigPowerGear.display();
	sideGear.display();
	sidePole.display();
	powerPole.display();
	powerPole2.display();
	powerPole3.display();
	powerPole4.display();
	sun.display();
	baseBox.display();
	coverBox.display();
	coverBox2.display();
	coverBox3.display();
	coverBox4.display();
	moonCylinder.display();
	drawPlanets();
	neptunePole.display();
	uranusPole.display();
	saturnPole.display();
	jupiterPole.display();
	marsPole.display();
	earthPole.display();
	venusPole.display();
	mercuryPole.display();
	saturnRingPole.display();

	glutSwapBuffers();
}
コード例 #3
0
void Light::drawAlpha(Scene *scene) {
	glBegin(GL_TRIANGLE_FAN);
		glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
		glVertex2f(pos.x, pos.y);
		glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
		for(int i=0; i <= NUM_POINTS; i++) {
			float angle = i * 2 * M_PI / NUM_POINTS;
			glVertex3f(pos.x + (cos(angle) * radius), pos.y + (sin(angle) * radius), 0.0f);
		}
	glEnd();
	if(castShadows)
		drawShadows(scene);
}
コード例 #4
0
ファイル: ShadowableScene.cpp プロジェクト: JackTing/shadows
/**
  Render the scene
*/
void ShadowableScene::render()
{
   // update light positions and properties
   updateLights();

   // iterate through the normal list and display the geomerty
   renderModelList(normalList);

   // iterate  through the receiver list and display the geometry
   renderModelList(shadowReceiverList);

   // iterate  through the caster list and display the geometry
   renderModelList(shadowCasterList);

   // Draw the shadows
   if (drawShadowsFlag) drawShadows();
}
コード例 #5
0
void Renderer::render()
{
	D3DXMATRIX viewMatrix;

	if ((menuHandler->enabled) && ((menuHandler->getMode() == MAIN_MENU) || (menuHandler->getMode() == LOADING)))
	{
		device->SetRenderState(D3DRS_ZENABLE, FALSE);
		device->SetRenderState(D3DRS_LIGHTING, FALSE);

		camera->updateForSkybox();
		camera->update();
		camera->getViewMatrix(viewMatrix);
		device->SetTransform(D3DTS_PROJECTION, &projectionMatrix);
		device->SetTransform(D3DTS_VIEW, &viewMatrix);
		device->SetTransform(D3DTS_WORLD, &worldMatrix);

		device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_ARGB(255,0,0,0), 1.0f, 0);
		device->BeginScene();
		menuHandler->render();
		device->EndScene();

		device->Present(NULL, NULL, NULL, NULL);
		return;
	}
	
	
	// Draw skybox

	camera->updateForSkybox();

	// Get view matrix
	camera->getViewMatrix(viewMatrix);

	// Build shadow volumes for all racers
	for (int i = 0; i < currentDrawable; i++)
	{
		if ((drawables[i]->meshType == RACER) || (drawables[i]->meshType == REARWHEEL)
			|| (drawables[i]->meshType == FRONTWHEEL) || (drawables[i]->meshType == GUNMOUNTMESH))
		{
			drawables[i]->buildShadowVolume(lightDir);
		}
	}
	
	
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER | D3DCLEAR_STENCIL, NULL, 1.0f, 0);
	
	device->SetTransform(D3DTS_PROJECTION, &projectionMatrix);
	device->SetTransform(D3DTS_VIEW, &viewMatrix);
	device->SetTransform(D3DTS_WORLD, &worldMatrix);

	device->SetRenderState(D3DRS_ZENABLE, FALSE);
	device->SetRenderState(D3DRS_LIGHTING, FALSE);
	
	device->BeginScene();

	skybox->render(device);

	device->SetRenderState(D3DRS_LIGHTING, TRUE);
	device->SetRenderState(D3DRS_ZENABLE, TRUE);


	// Now draw rest of the scene

	camera->update();



	// Get view matrix
	camera->getViewMatrix(viewMatrix);

	device->SetTransform(D3DTS_VIEW, &viewMatrix);
	

	device->SetRenderState(D3DRS_FOGENABLE, TRUE);

	for (int i = 0; i < currentDrawable; i++)
	{
		drawables[i]->render(device);
	}
	
	
	device->SetRenderState(D3DRS_FOGENABLE, FALSE);
	// Draw stencil shadows
	drawShadows();
	


	// Draw dynamic objects that will be removed after this frame (like rockets, landmines, explosion effects)
	if (!(dynamicDrawables->empty()))
	{
		for (std::vector<Drawable*>::iterator iter = dynamicDrawables->begin();
			iter < dynamicDrawables->end(); ++iter)
		{
			(*iter)->render(device);
		}

		dynamicDrawables->clear();
	}

	// Render SmokeSystem particles
	device->SetTransform(D3DTS_WORLD, &worldMatrix);
	smokeSystem->render(EXPLOSION_SMOKE);
	smokeSystem->render(ROCKET_SMOKE);

	// Render LaserSystem particles (beginning and end points of shots)
	laserSystem->render();


	for (int i = 0; i < numSentences; i++)
	{
		writeText(sentences[i], i);
	}
	

	// Now draw HUD
	hud->render();

	// Now draw menu stuff
	if (menuHandler->enabled)
		menuHandler->render();

	device->EndScene();

	device->Present(NULL, NULL, NULL, NULL);

	return;
}
コード例 #6
0
ファイル: GLWindow.cpp プロジェクト: aashithk/BipedSoccer
/**
 *	This method is used to draw the scene.
 */
void GLWindow::draw(){
	//clear the screen
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	//we will now place the camera
	setupGLCamera();
	//and set up the lights (do this so that the position is specified in world coordinates, not in camera ones).
	setupLights();

	/**
		If we want fog...
	*/
/*
	GLfloat fogColor[4]= {0.5f, 0.5f, 0.5f, 1.0f};		// Fog Color
	glFogi(GL_FOG_MODE, GL_LINEAR);		// Fog Mode
	glFogfv(GL_FOG_COLOR, fogColor);			// Set Fog Color
	glFogf(GL_FOG_DENSITY, 0.35f);				// How Dense Will The Fog Be
	glHint(GL_FOG_HINT, GL_DONT_CARE);			// Fog Hint Value
	glFogf(GL_FOG_START, 20.0f);				// Fog Start Depth
	glFogf(GL_FOG_END, 80.0f);				// Fog End Depth
	glEnable(GL_FOG);					// Enables GL_FOG
*/

	if (Globals::drawCubeMap)
		drawCubeMap();

	glColor3d(1, 1, 1);
	//and then draw the application stuff
	if (Globals::app)
		Globals::app->draw();

	if (Globals::drawGroundPlane && Globals::app)
		Globals::app->drawGround();

	//no more texture mapping or lighting needed
	glDisable(GL_LIGHTING);
	glDisable(GL_TEXTURE_2D);


	if (Globals::drawShadows && Globals::drawGroundPlane && Globals::app)
		drawShadows();

	glColor3d(1,1,1);
	
	if (Globals::app)
		Globals::app->drawExtras();

	if (Globals::drawGlobalAxes)
		drawAxes();

	//wait until the required ammount of time has passed (respect the desired FPS requirement)
	while (fpsTimer.timeEllapsed()<1.0/Globals::desiredFrameRate);	

	if (Globals::drawFPS)
		drawFPSandPerf(fpsTimer.timeEllapsed(), timeSpentProcessing/(1/Globals::desiredFrameRate));
	
	//print a screenshot if needed
	if (Globals::drawScreenShots){
		static int screenShotNumber = 0;
		char fName[100];
		sprintf(fName, "..\\screenShots\\ss%05d.bmp", screenShotNumber);
		screenShotNumber++;
		GLUtils::saveScreenShot(fName, 0, 0, w, h);
	}

	if (Globals::drawWorldShots && Globals::app ){
		static int worldShotNumber = 0;
		char fName[100];
		sprintf(fName, "..\\worldShots\\ws%05d.obj", worldShotNumber);
		worldShotNumber++;
		FILE* fp = fopen( fName, "w" );
		fprintf( fp, 
				 "####\n"
				 "#\n"
				 "# OBJ File Generated by UBC-IMAGER character animation tool\n"
				 "# Frame %05d\n"
				 "#\n"
				 "####\n\n", worldShotNumber );

		Globals::app->renderToObjFile( fp, 0 );

		fclose( fp );
	}

	fpsTimer.restart();
}