Beispiel #1
0
static void Display(GLvoid)									// Draw Everything
{
    // Clear Screen, Depth Buffer & Stencil Buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    // Clip Plane Equations
    double eqr[] = {0.0f,-1.0f, 0.0f, 0.0f};			// Plane Equation To Use For The Reflected Objects

    glLoadIdentity();									// Reset The Modelview Matrix
    glTranslatef(0.0f, -0.6f, zoom);					// Zoom And Raise Camera Above The Floor (Up 0.6 Units)
    glColorMask(0,0,0,0);								// Set Color Mask
    glEnable(GL_STENCIL_TEST);							// Enable Stencil Buffer For "marking" The Floor
    glStencilFunc(GL_ALWAYS, 1, 1);						// Always Passes, 1 Bit Plane, 1 As Mask
    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);			// We Set The Stencil Buffer To 1 Where We Draw Any Polygon
    // Keep If Test Fails, Keep If Test Passes But Buffer Test Fails
    // Replace If Test Passes
    glDisable(GL_DEPTH_TEST);							// Disable Depth Testing
    DrawFloor();										// Draw The Floor (Draws To The Stencil Buffer)
    // We Only Want To Mark It In The Stencil Buffer
    glEnable(GL_DEPTH_TEST);							// Enable Depth Testing
    glColorMask(1,1,1,1);								// Set Color Mask to true, true, true, true
    glStencilFunc(GL_EQUAL, 1, 1);						// We Draw Only Where The Stencil Is 1
    // (I.E. Where The Floor Was Drawn)
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);				// Don't Change The Stencil Buffer
    glEnable(GL_CLIP_PLANE0);							// Enable Clip Plane For Removing Artifacts
    // (When The Object Crosses The Floor)
    glClipPlane(GL_CLIP_PLANE0, eqr);					// Equation For Reflected Objects
    glPushMatrix();										// Push The Matrix Onto The Stack
    glScalef(1.0f, -1.0f, 1.0f);					// Mirror Y Axis
    glLightfv(GL_LIGHT0, GL_POSITION, LightPos);	// Set Up Light0
    glTranslatef(0.0f, height, 0.0f);				// Position The Object
    glRotatef(xrot, 1.0f, 0.0f, 0.0f);				// Rotate Local Coordinate System On X Axis
    glRotatef(yrot, 0.0f, 1.0f, 0.0f);				// Rotate Local Coordinate System On Y Axis
    DrawObject();									// Draw The Sphere (Reflection)
    glPopMatrix();										// Pop The Matrix Off The Stack
    glDisable(GL_CLIP_PLANE0);							// Disable Clip Plane For Drawing The Floor
    glDisable(GL_STENCIL_TEST);							// We Don't Need The Stencil Buffer Any More (Disable)
    glLightfv(GL_LIGHT0, GL_POSITION, LightPos);		// Set Up Light0 Position
    glEnable(GL_BLEND);									// Enable Blending (Otherwise The Reflected Object Wont Show)
    glDisable(GL_LIGHTING);								// Since We Use Blending, We Disable Lighting
    glColor4f(1.0f, 1.0f, 1.0f, 0.8f);					// Set Color To White With 80% Alpha
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	// Blending Based On Source Alpha And 1 Minus Dest Alpha
    DrawFloor();										// Draw The Floor To The Screen
    glEnable(GL_LIGHTING);								// Enable Lighting
    glDisable(GL_BLEND);								// Disable Blending
    glTranslatef(0.0f, height, 0.0f);					// Position The Ball At Proper Height
    glRotatef(xrot, 1.0f, 0.0f, 0.0f);					// Rotate On The X Axis
    glRotatef(yrot, 0.0f, 1.0f, 0.0f);					// Rotate On The Y Axis
    DrawObject();										// Draw The Ball
    xrot += xrotspeed;									// Update X Rotation Angle By xrotspeed
    yrot += yrotspeed;									// Update Y Rotation Angle By yrotspeed
    glFlush();											// Flush The GL Pipeline

    glutSwapBuffers();
}
Beispiel #2
0
void CVXS_SimGLView::Draw(int Selected, bool ViewSection, int SectionLayer)
{
	if (!pSim->IsInitalized()) return;

	if (CurViewMode == RVM_NONE) return;
	else if (CurViewMode == RVM_VOXELS){ 
		switch (CurViewVox){
		case RVV_DISCRETE: DrawGeometry(Selected, ViewSection, SectionLayer); break; //section view only currently enabled in voxel view mode
		case RVV_DEFORMED: DrawVoxMesh(Selected); break;
		case RVV_SMOOTH: DrawSurfMesh(); break;
		}
	}
	else { //CurViewMode == RVT_BONDS
		vfloat VoxScale=0.2;
		if (ViewForce){
			DrawForce();
			DrawGeometry(Selected, ViewSection, SectionLayer, VoxScale);

		}
		else {
			if (CurViewVox == RVV_SMOOTH) VoxScale=0.1;
			DrawBonds();
			DrawGeometry(Selected, ViewSection, SectionLayer, VoxScale);
		}
		DrawStaticFric();
	}
	if (ViewAngles)	DrawAngles();
	if (pSim->IsFeatureEnabled(VXSFEAT_FLOOR)) DrawFloor(); //draw the floor if its in use
//	if (pEnv->IsFloorEnabled()) DrawFloor(); //draw the floor if its in use

	NeedStatsUpdate=true;
}
Beispiel #3
0
void World::DrawScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

    camera_.Apply();
    
    glLoadIdentity();

    DrawReflections();
    DrawShadows();

    // ¹Ù´Ú ±×¸®±â
	glDisable(GL_STENCIL_TEST);
	glEnable(GL_BLEND);
	glDisable(GL_LIGHTING);
	glColor4f(1.0f, 1.0f, 1.0f, 0.8f);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	DrawFloor();
	glEnable(GL_LIGHTING);
	glDisable(GL_BLEND);

    // ½Ç¹° ½ºÇÁ¶óÀÌÆ® ±×¸®±â
    //glTranslatef(0.0f, 0.0f, 1.5f);
    DrawSprites();

    DrawOrigin();
    DrawCollisionInfo();
}
void GameClass::DrawGameGrid () const {
  ALLEGRO_COLOR color(cWhite);

  for (size_t i = 0; i < gridHeight; i++) {
    for (size_t j = 0; j < gridWidth; j++) {
      int x = j*cTileSize, y = i*cTileSize,
          xf = (j+1)*cTileSize, yf = (i+1)*cTileSize;
      switch (gameGrid[i][j]) {
        case cBlock:
          if (i > 0 && gameGrid[i-1][j] == cNone)
            DrawFloor(x, y, xf, yf);
          else
            DrawBlock(x, y, xf, yf);
          break;
        case cSpike:
          DrawSpike(x, y, xf, yf);
          break;
        case cNone:
          if (i < gridHeight-1 && gameGrid[i+1][j] == cBlock)
            DrawGrass(x, y, xf, yf);
          //Nothing
        default:
          break;
      }
    }
  }

  float x = regionExit->GetX() +
      cTileSize*regionExit->GetWidth()/2;
  float y = regionExit->GetY();
  al_draw_text(hugeFont, cWhite, x, y,
      ALLEGRO_ALIGN_CENTRE, cExit[language].c_str());
}
Beispiel #5
0
void Scene :: Draw()
{
  glPushMatrix();
    DrawFloor();
	DrawPlatform();
	DrawCageDome();
	DrawGlassDome();
  glPopMatrix();
}  // Draw
Beispiel #6
0
/*************************************************************************
 GameMain()

 The work of the application is done here. This is called every frame.
*************************************************************************/
bool GameMain(float elapsedTime)
{
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();
  gluLookAt(2.0, 1.0, 2.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);

  DrawLight(elapsedTime);
  DrawFloor(elapsedTime);
  return true;
} // end GameMain()
Beispiel #7
0
void DrawScene()
{
	DrawFloor(0,0,0);
	
	glPushMatrix();
		glTranslatef (0,1,0);
		glScalef (2/scale, 2/scale, 2/scale);
		glTranslatef (-center[0], -center[1], -center[2]);
		loopOver = MD2MInterpolate (&g_3DModel);
	glPopMatrix();	
}
Beispiel #8
0
void DrawMaze()
{
	if (cur_layer){
		M.PreviousLayer();
		DrawWalls(cur_layer - 1);
		DrawFloor(cur_layer - 1);
		M.NextLayer();
	}
	if (cur_layer < layers - 1){
		M.NextLayer();
		DrawWalls(cur_layer + 1);
		DrawCeiling(cur_layer + 1);
		M.PreviousLayer();
	}
	DrawLayer(cur_layer);

	
}
Beispiel #9
0
void DrawBufferDraw(DrawBuffer *b, Vec2i offset, GrafxDrawExtra *extra)
{
    // First draw the floor tiles (which do not obstruct anything)
    DrawFloor(b, offset);
    // Then draw debris (wrecks)
    DrawDebris(b, offset);
    // Now draw walls and (non-wreck) things in proper order
    DrawWallsAndThings(b, offset);
    // Draw objective highlights, for visible and always-visible objectives
    DrawObjectiveHighlights(b, offset);
    // Draw actor chatter
    DrawChatters(b, offset);
    // Draw editor-only things
    if (extra)
    {
        DrawExtra(b, offset, extra);
    }
}
Beispiel #10
0
void Renderer::DrawCombinedScene(){
	SetCurrentShader(sceneShader);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "bumpTex"), 1);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "shadowTex"), 2);

	glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "cameraPos"), 1, (float*)&camera->GetPosition());

	SetShaderLight(*light);

	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, shadowTex);

	viewMatrix = camera->BuildViewMatrix();
	UpdateShaderMatrices();

	DrawFloor();
	DrawMesh();

	glUseProgram(0);
}
Beispiel #11
0
void World::DrawReflections()
{
    //glTranslatef(1.0f, 0.0f, -3.6f);  // * ÇÊ¿ä¾ø´Â Translate·Î º¸ÀÓ
	glColorMask(0, 0, 0, 0);
	glEnable(GL_STENCIL_TEST);
	glStencilFunc(GL_ALWAYS, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
	glDisable(GL_DEPTH_TEST);
	DrawFloor();
	glEnable(GL_DEPTH_TEST);
	glColorMask(1,1,1,1);
	glStencilFunc(GL_EQUAL, 1, 1);
	glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
	
    glPushMatrix();
    glTranslatef(0.0f, 0.0f, -1.5f);
	glScalef(1.0f, 1.0f, -1.0f);
	
    DrawSprites();
	
    glPopMatrix();
}
Beispiel #12
0
void CVX_Sim::Draw(int Selected, bool ViewSection, int SectionLayer)
{
	if (!Initalized) return;

	if (CurViewMode == RVM_NONE) return;
	else if (CurViewMode == RVM_VOXELS){ 
		switch (CurViewVox){
		case RVV_DISCRETE: DrawGeometry(Selected, ViewSection, SectionLayer); break; //section view only currently enabled in voxel view mode
		case RVV_DEFORMED: DrawVoxMesh(Selected); break;
		case RVV_SMOOTH: DrawSurfMesh(); break;
		}
	}
	else { //CurViewMode == RVT_BONDS
		DrawBonds();
		DrawStaticFric();
	}
	if (ViewAngles)	DrawAngles();
	if (ViewForce) DrawForce();
	if (pEnv->IsFloorEnabled()) DrawFloor(); //draw the floor if its in use

	NeedStatsUpdate=true;
}
Beispiel #13
0
	void Vessel::DrawWorld()
	{
		if (myPlayer)
		{
			camera.position = myPlayer->pos;

			glm::mat4 viewMat(1.0f);
			camera.GenerateView(viewMat);

			glUseProgram(floorProgram.program);
			glActiveTexture(GL_TEXTURE0);
			glBindTexture(GL_TEXTURE_2D, floorProgram.texture);
			glUniformMatrix4fv(floorProgram.viewMat, 1, false, glm::value_ptr(viewMat));
			glUniform1i(floorProgram.textureLoc, 0);

			DrawFloor();

			glUseProgram(coloredVertexProgram.program);
			glm::vec4 color(0.5f, 0.5f, 0.5f, 1.0f);
			glUniform4fv(coloredVertexProgram.color, 1, glm::value_ptr(color));
			glUniformMatrix4fv(coloredVertexProgram.viewMat, 1, false, glm::value_ptr(viewMat));

			DrawWalls();

			glDisable(GL_CULL_FACE);
			glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

			glUseProgram(shadowProgram.program);
			glUniform2fv(shadowProgram.playerPos, 1, glm::value_ptr(camera.position));
			glUniformMatrix4fv(shadowProgram.viewMat, 1, false, glm::value_ptr(viewMat));

			DrawShadows();

			glEnable(GL_CULL_FACE);
			glDisable(GL_BLEND);
		}
	}
Beispiel #14
0
void Renderer::DrawShadowScene(){
	glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
	glClear(GL_DEPTH_BUFFER_BIT);

	glViewport(0, 0, SHADOWSIZE, SHADOWSIZE);

	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

	SetCurrentShader(shadowShader);

	viewMatrix = Matrix4::BuildViewMatrix(light->GetPosition(), Vector3(0,0,0));
	textureMatrix = biasMatrix * (projMatrix * viewMatrix);

	UpdateShaderMatrices();
	DrawFloor();
	DrawMesh();

	glUseProgram(0);
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glViewport(0, 0, width, height);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
Beispiel #15
0
// 출력
void Draw() {
  if(!(refresh_object || refresh_message || refresh_status || refresh_time)) {
    return;
  }
  if(refresh_object) {
    refresh_object = 0;
    DrawFloor(map_id);
    DrawObjects();
  }
  if(refresh_message) {
    refresh_message = 0;
    DrawMessage();
  }
  if(refresh_status) {
    refresh_status = 0;
    DrawStatus();
  }
  if(refresh_time) {
    refresh_time = 0;
    DrawTime();
  }
  mvaddch(22, 78, ' ');
  refresh();
}
Beispiel #16
0
void DrawLayer(int layer)
{
	DrawCeiling(layer);
	DrawFloor(layer);
	DrawWalls(layer);
}
Beispiel #17
0
void Mesh::drawVBOs() {
  // scale it so it fits in the window
  Vec3f center; bbox.getCenter(center);
  float s = 1/bbox.maxDim();
  glScalef(s,s,s);
  glTranslatef(-center.x(),-center.y(),-center.z());

  // setup the light
  Vec3f light_position = LightPosition();
  GLfloat position[4] = { float(light_position.x()),float(light_position.y()),float(light_position.z()),1 };
  glLightfv(GL_LIGHT1, GL_POSITION, position);
  
  if (args->glsl_enabled) {
  
  
    glEnable(GL_DEPTH_TEST);
    glClearColor(0,0,0,1.0f);
    glEnable(GL_CULL_FACE);
    //glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
    
    //BEGIN SHADOW FUN/////////////===================================
    
    //First step: Render from the light POV to a FBO, story depth values only
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,fboId);  //Rendering offscreen
    
    //Using the fixed pipeline to render to the depthbuffer
    glUseProgramObjectARB(0);
      
    
    // In the case we render the shadowmap to a higher resolution, the viewport must be modified accordingly.
    glViewport(0,0,args->width * SHADOW_MAP_RATIO,args->height* SHADOW_MAP_RATIO);
    
    // Clear previous frame values
    glClear(GL_DEPTH_BUFFER_BIT);
    
    //Disable color rendering, we only want to write to the Z-Buffer
    glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); 
    
    
    
    //LIGHT POSITION==========================================================================================
    setupMatrices(float(light_position.x()),float(light_position.y()),float(light_position.z()),
            10,10,1);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45,args->width/args->height,1.0f,1000.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt((float)light_position.x(),(float)light_position.y(),(float)light_position.z(),0,0,0,0,1,0);
            
    
    // Culling switching, rendering only backface, this is done to avoid self-shadowing
    glCullFace(GL_FRONT);
     
    
    //===========Draw the Things===================================================================================
    InsertColor(floor_color);
    DrawFloor();
    //startTranslate(0,0,0);
    //glutSolidCube(1);
    
    InsertColor(mesh_color);
    glUseProgramObjectARB(GLCanvas::program);
    glColor3b(GLbyte(240-127), GLbyte(184-127), GLbyte(0-127));
    DrawMesh(table, board_tri_verts_VBO);
    DrawPieces(editBoard());

    //endTranslate();
    
    glUseProgramObjectARB(0);
    
    //=============================================================================================================
    
    //Save modelview/projection matrice into texture7, also add a biais
    setTextureMatrix();
    
    
    // Now rendering from the camera POV, using the FBO to generate shadows
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);
    
    glViewport(0,0,args->width,args->height);
    
    //Enabling color write (previously disabled for light POV z-buffer rendering)
    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); 
    
    // Clear previous frame values
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      
    //Using the shadow shader
    glUseProgramObjectARB(GLCanvas::program);

    glUniform1iARB(shadowMapUniform,7);
    glActiveTextureARB(GL_TEXTURE7);
    glBindTexture(GL_TEXTURE_2D,depthTextureId);
    
    Vec3f cam_position = camera->camera_position;
    Vec3f interest = camera->point_of_interest;
    
    //CAMERA MATRIX=======================================================================================================
    //setupMatrices(cam_pos[0],cam_pos[1],cam_pos[2],interest[0],interest[1],interest[2]);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(45,args->width/args->height,1.0f,1000.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    gluLookAt((float)cam_position.x(),(float)cam_position.y(),(float)cam_position.z(),(float)interest.x(),(float)interest.y(),(float)interest.z(),0,1,0);
    
    glCullFace(GL_BACK);
    //============================Draw the things
    InsertColor(floor_color);
    DrawFloor();
    //startTranslate(0,0,0);
    //glutSolidCube(1);
    
    InsertColor(mesh_color);
    glUseProgramObjectARB(GLCanvas::program);
    glColor3b(GLbyte(240-127), GLbyte(184-127), GLbyte(0-127));
    DrawMesh(table, board_tri_verts_VBO);
    DrawPieces(editBoard());

    //endTranslate();
    
    glUseProgramObjectARB(0);
    
    //============================All the things
    
    // DEBUG only. this piece of code draw the depth buffer onscreen
    //*
    glUseProgramObjectARB(0);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-args->width/2,args->width/2,-args->height/2,args->height/2,1,20);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glColor4f(1,1,1,1);
    glActiveTextureARB(GL_TEXTURE0);
    glBindTexture(GL_TEXTURE_2D,depthTextureId);
    glEnable(GL_TEXTURE_2D);
    glTranslated(0,0,-1);
    glBegin(GL_QUADS);
    glTexCoord2d(0,0);glVertex3f(0,0,0);
    glTexCoord2d(1,0);glVertex3f(args->width/2,0,0);
    glTexCoord2d(1,1);glVertex3f(args->width/2,args->width/2,0);
    glTexCoord2d(0,1);glVertex3f(0,args->height/2,0);
     
    glEnd();
    glDisable(GL_TEXTURE_2D);
    //*/
    
    //glutSwapBuffers();

    glDisable(GL_STENCIL_TEST);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glDepthMask(1);
    
	  //END SHADOW FUN//////////////////////////////////////////////////
  }
  else
  {
    InsertColor(floor_color);
    DrawFloor();
    
    InsertColor(mesh_color);
    glColor3b(GLbyte(240-127), GLbyte(184-127), GLbyte(0-127));

    DrawMesh(table, board_tri_verts_VBO);
    if(args->board_control)
    {
      DrawControlMap();
    }
    DrawPieces(editBoard());
  }
  

  // -------------------------
  // ADDITIONAL VISUALIZATIONS (for debugging)
  glColor3f(1,1,0);
  //DrawLight();
  if (args->bounding_box) {
    glColor3f(0,0,0);
    bbox.drawVBOs();
  }
    
  HandleGLError(); 
}
Beispiel #18
0
void CGLLogoView::DrawGLScene()
{
	wglMakeCurrent(hDC, hRC);

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	gluLookAt(0,y,z, 0,0,0, 0,1,0);

	glFrontFace(GL_CCW);
	if (bReflection)
	{
		glPushMatrix();
			// Move light under floor to light the "reflected" world
			LightPosition[1] *= -1.0; 
			glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
			LightPosition[1] *= -1.0;

			// Geometry is mirrored, swap orientation
			glFrontFace(GL_CW);
			glScalef(1.0f, -1.0f, 1.0f);
			glTranslatef(0.0,5.6f,0);
			glRotatef(xrot,1,0,0);
			glRotatef(yrot,0,1,0);
			glRotatef(zrot,0,0,1);
			if (bÑrystallize) { glLogicOp(glColorOp); glEnable(GL_COLOR_LOGIC_OP); }
			glCallList(logo);
			if (bÑrystallize) { glLogicOp(GL_CLEAR); glDisable(GL_COLOR_LOGIC_OP); }
			glFrontFace(GL_CCW);

		glPopMatrix();
	}

	// draw the shadow
	if (bShadow)
	{
		glPushMatrix();
			glColor4f(0.3f, 0.3f, 0.3f, 1.0f);
			glDisable(GL_TEXTURE_2D);
			glDisable(GL_LIGHTING);
			glDisable(GL_DEPTH_TEST);

			glTranslatef(1.5f,0.0f,0.0f);
			glMultMatrixf(fShadowMatrix);
			glRotatef(xrot,1,0,0);
			glRotatef(yrot,0,1,0);
			glRotatef(zrot,0,0,1);
			glCallList(logo);

			glEnable(GL_TEXTURE_2D);
			glEnable(GL_DEPTH_TEST);
			glEnable(GL_LIGHTING);
		glPopMatrix();
	}

	// Draw the ground transparently over the reflection
	glDisable(GL_LIGHTING);
	DrawFloor();
	glEnable(GL_LIGHTING);
	// Restore correct lighting and draw the world correctly
	glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);

	// draw object
	glPushMatrix();
		if (bÑrystallize) { glLogicOp(glColorOp); glEnable(GL_COLOR_LOGIC_OP); }
		glTranslatef(0.0f,1.0f, 0.0f);
		glRotatef(xrot,1,0,0);
		glRotatef(yrot,0,1,0);
		glRotatef(zrot,0,0,1);
		glCallList(logo);
		if (bÑrystallize) { glLogicOp(GL_CLEAR); glDisable(GL_COLOR_LOGIC_OP); }
	glPopMatrix();

	// draw info window
	if (bDrawInfo || (alpha_inc < 0.0f))
	{
		glLoadIdentity();
		gluLookAt(0,0,-5, 0,0,0, 0,1,0);
		glTranslatef(0.0f,-1.0f, 1.0f);
		glDisable(GL_LIGHTING);
		glDisable(GL_TEXTURE_2D);

		glColor4f(0.3f,0.3f,0.4f, alpha-0.2f);
		glBegin(GL_QUADS);									
			glTexCoord2f(0.0f, 1.0f); glVertex3f(-2.0f, 1.0f, 0.0f);					
			glTexCoord2f(1.0f, 1.0f); glVertex3f( 2.0f, 1.0f, 0.0f);					
			glTexCoord2f(1.0f, 0.0f); glVertex3f( 2.0f,-1.3f, 0.0f);					
			glTexCoord2f(0.0f, 0.0f); glVertex3f(-2.0f,-1.3f, 0.0f);					
		glEnd();

		glDisable(GL_DEPTH_TEST);
		glColor4f(1.0f, 1.0f, 0.0f, alpha);
		glRotatef(180.0,0,1,0);
		glScalef(0.25f, 0.25f, 0.25f);
		glTranslatef(-8.0f, 2.6f, 0.0f);

		InfoValues[1] = (ds==0.001f);
		InfoValues[2] = bReflection;
		InfoValues[3] = bShadow;
		InfoValues[4] = bFloor;
		InfoValues[5] = bWireFrame;
		for (int i=0; i<INFO_SIZE; i++)
		{
			glPushMatrix();
				glTranslatef(0.0f, -i*1.2f, 0.0f);
				if (i>0 && i<INFO_SIZE-1)
					Print(Info[i],InfoValues[i]?"off":"on");
				else
					Print(Info[i]);
			glPopMatrix();
		}

		glEnable(GL_DEPTH_TEST);
		glEnable(GL_TEXTURE_2D);
		glEnable(GL_LIGHTING);

		if (alpha < 1.0f || (!bDrawInfo && alpha > 0.0f)) alpha += alpha_inc;
	}

	// Recalculate rotation speed
	if (xspeed!=0) xspeed>0?xspeed-=ds:xspeed+=ds; xrot+=xspeed;
	if (yspeed!=0) yspeed>0?yspeed-=ds:yspeed+=ds; yrot+=yspeed;
	if (zspeed!=0) zspeed>0?zspeed-=ds:zspeed+=ds; zrot+=zspeed;
}
Beispiel #19
0
void Draw( double t )
{
    double xpos, ypos, zpos, angle_x, angle_y, angle_z;
    static double t_old = 0.0;
    float  dt;

    // Calculate frame-to-frame delta time
    dt = (float)(t-t_old);
    t_old = t;

    // Setup viewport
    glViewport( 0, 0, width, height );

    // Clear color and Z-buffer
    glClearColor( 0.1f, 0.1f, 0.1f, 1.0f );
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    // Setup projection
    glMatrixMode( GL_PROJECTION );
    glLoadIdentity();
    gluPerspective( 65.0, (double)width/(double)height, 1.0, 60.0 );

    // Setup camera
    glMatrixMode( GL_MODELVIEW );
    glLoadIdentity();

    // Rotate camera
    angle_x = 90.0 - 10.0;
    angle_y = 10.0 * sin( 0.3 * t );
    angle_z = 10.0 * t;
    glRotated( -angle_x, 1.0, 0.0, 0.0 );
    glRotated( -angle_y, 0.0, 1.0, 0.0 );
    glRotated( -angle_z, 0.0, 0.0, 1.0 );

    // Translate camera
    xpos =  15.0 * sin( (M_PI/180.0) * angle_z ) +
             2.0 * sin( (M_PI/180.0) * 3.1 * t );
    ypos = -15.0 * cos( (M_PI/180.0) * angle_z ) +
             2.0 * cos( (M_PI/180.0) * 2.9 * t );
    zpos = 4.0 + 2.0 * cos( (M_PI/180.0) * 4.9 * t );
    glTranslated( -xpos, -ypos, -zpos );

    // Enable face culling
    glFrontFace( GL_CCW );
    glCullFace( GL_BACK );
    glEnable( GL_CULL_FACE );

    // Enable lighting
    SetupLights();
    glEnable( GL_LIGHTING );

    // Enable fog (dim details far away)
    glEnable( GL_FOG );
    glFogi( GL_FOG_MODE, GL_EXP );
    glFogf( GL_FOG_DENSITY, 0.05f );
    glFogfv( GL_FOG_COLOR, fog_color );

    // Draw floor
    DrawFloor();

    // Enable Z-buffering
    glEnable( GL_DEPTH_TEST );
    glDepthFunc( GL_LEQUAL );
    glDepthMask( GL_TRUE );

    // Draw fountain
    DrawFountain();

    // Disable fog & lighting
    glDisable( GL_LIGHTING );
    glDisable( GL_FOG );

    // Draw all particles (must be drawn after all solid objects have been
    // drawn!)
    DrawParticles( t, dt );

    // Z-buffer not needed anymore
    glDisable( GL_DEPTH_TEST );
}