Пример #1
0
//Called to update the display.
//You should call glutSwapBuffers after all of your rendering to display what you rendered.
//If you need continuous updates of the screen, call glutPostRedisplay() at the end of the function.
void display()
{
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClearDepth(1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	if (g_pConeMesh && g_pCylinderMesh && g_pCubeTintMesh && g_pCubeColorMesh && g_pPlaneMesh)
	{
		const glm::vec3 &camPos = ResolveCamPosition();

		glutil::MatrixStack camMatrix;
		camMatrix.SetMatrix(CalcLookAtMatrix(camPos, g_camTarget, glm::vec3(0.0f, 1.0f, 0.0f)));

		glBindBuffer(GL_UNIFORM_BUFFER, g_GlobalMatricesUBO);
		glBufferSubData(GL_UNIFORM_BUFFER, sizeof(glm::mat4), sizeof(glm::mat4), glm::value_ptr(camMatrix.Top()));
		glBindBuffer(GL_UNIFORM_BUFFER, 0);

		glutil::MatrixStack modelMatrix;

		//Draw Scene
		DrawRoom(modelMatrix);
		DrawArmchair(modelMatrix);
		DrawTable(modelMatrix);
		DrawCarpet(modelMatrix);
		DrawLowTable(modelMatrix);
		DrawPicture(modelMatrix);
		DrawLamp(modelMatrix);
		DrawPlant(modelMatrix);
		DrawCandlesInLoop(modelMatrix);
	}

	glutSwapBuffers();
	glutPostRedisplay();
}
Пример #2
0
void Render() 
{ 
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	SetCamera();
	DrawBall(GL_FALSE);		
	DrawLifes();
	DrawScores();
	DrawCubes();
	DrawRoom();

	projection.Init(ROOM_HALF_LENGTH - 0.01, X, Y, -ROOM_LENGTH*10);
	glPushMatrix();
		glMultMatrixf((GLfloat*)projection.shadowMat);
		DrawBall(GL_TRUE);
	glPopMatrix();

	DrawReflector();
	RoomCollision();
	CubesCollision();

	glClearColor(0.3, 0.3, 0.3, 0);
    glutSwapBuffers();
}
Пример #3
0
void Renderer2::Render() const
{
    glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // Set viewport
    glViewport(0, 0, m_surfaceSize.x, m_surfaceSize.y);
    
    // Enable depth
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    
    // Draw
    DrawSurface();
    DrawRoom();
}
Пример #4
0
/* 
 * Functions should call RedrawAll if they need the room to be redrawn.
 * This sets a flag, and the next time an opportunity arises, the room
 * is redrawn via a call to RedrawForce.
 */
void RedrawForce(void)
{
   HDC hdc;
   static DWORD lastEndFrame = 0;
   DWORD endFrame, startFrame;
   int totalFrameTime, oldMode;
   char buffer[32];

   if (GameGetState() == GAME_INVALID || /*!need_redraw ||*/ IsIconic(hMain) ||
       view.cx == 0 || view.cy == 0 || current_room.rows == 0 || current_room.cols == 0)
   {
      need_redraw = False;
      return;
   }

   timeBeginPeriod(1);
   startFrame = timeGetTime();

   /* REVIEW: Clearing flag before draw phase allows draw phase to set flag.
    *         This is useful in rare circumstances when an effect should
    *         last only one frame, even if animation is off.
    */
   need_redraw = False;
   hdc = GetDC(hMain);
   DrawRoom(hdc, view.x, view.y, &current_room, map);

   endFrame = timeGetTime();
   msDrawFrame = (int)(endFrame - startFrame);
   totalFrameTime = (int)(endFrame - lastEndFrame);

   // if totalFrameTime is less than one, clamp to 1 so we don't divide by 0 or get negative fps
   if (1 > totalFrameTime)
	   totalFrameTime = 1;

   fps = 1000 / (int)totalFrameTime;
   if (config.maxFPS)
   {
      if (fps > config.maxFPS)
      {
	 int msSleep = (1000 / config.maxFPS) - totalFrameTime;
	 Sleep(msSleep);
      }
   }
   lastEndFrame = endFrame;
   timeEndPeriod(1);

   if (config.showFPS)
   {
      RECT rc,lagBox;
      wsprintf(buffer, "FPS=%d (%dms)        ", fps, msDrawFrame);
      ZeroMemory(&rc,sizeof(rc));
      rc.bottom = DrawText(hdc,buffer,-1,&rc,DT_SINGLELINE|DT_CALCRECT);
      Lagbox_GetRect(&lagBox);
      OffsetRect(&rc,lagBox.right + TOOLBAR_SEPARATOR_WIDTH,lagBox.top);
      DrawWindowBackground(hdc, &rc, rc.left, rc.top);
      oldMode = SetBkMode(hdc,TRANSPARENT);
      DrawText(hdc,buffer,-1,&rc,DT_SINGLELINE);
      SetBkMode(hdc,oldMode);
      GdiFlush();
   }
   ReleaseDC(hMain, hdc);

   GameWindowSetCursor();   // We may have moved; reset cursor
}
Пример #5
0
void NewRoom(int place_x, int place_y, int room_w, int room_h, int creator)
{
  int connect_points = 0;
  int cplist_x[100], cplist_y[100], cplist_r[100], cplist_t[100];
	
  int sr_cps = 0;
  int sr_cp[100];
	
  int sr_nps = 0;
  int sr_np[100];
	
  int i;
	
  /* Draw this room */
  map.rooms[total_rooms].checkpoint = 0;
  DrawRoom(place_x, place_y, room_w, room_h, total_rooms);
	
  map.rooms[total_rooms].x = place_x;
  map.rooms[total_rooms].y = place_y;
	
  map.rooms[total_rooms].w = room_w;
  map.rooms[total_rooms].h = room_h;
	
  map.rooms[total_rooms].room_type = 0;
  map.rooms[total_rooms].room_param = 0;
	
  map.rooms[total_rooms].creator = creator;
	
  map.rooms[total_rooms].connections = 0;
  map.rooms[total_rooms].con = NULL;
  map.rooms[total_rooms].enemies = 0;
	
  map.rooms[total_rooms].visited = 0;

  map.rooms[total_rooms].s_dist = -1;
	
  if (total_rooms == 0) {
    map.rooms[total_rooms].checkpoint = 1;
  }
	
	
	
  total_rooms++;

  if (creator == -1) return;
	
  /* Find connection points */
	
  for (i = 0; i < room_w - 2; i++) {
    if (SuitableConnection(Get(place_x + 1 + i, place_y - 1))) {
      cplist_x[connect_points] = place_x + 1 + i;
      cplist_y[connect_points] = place_y;
      cplist_r[connect_points] = GetRoom(place_x + 1 + i, place_y - 1);
      cplist_t[connect_points] = 0;
      connect_points++;
    }
		
    if (SuitableConnection(Get(place_x + 1 + i, place_y + room_h))) {
      cplist_x[connect_points] = place_x + 1 + i;
      cplist_y[connect_points] = place_y + room_h - 1;
      cplist_r[connect_points] = GetRoom(place_x + 1 + i, place_y + room_h);
      cplist_t[connect_points] = 1;
      connect_points++;
    }
  }
  for (i = 0; i < room_h - 2; i++) {
    if (SuitableConnection(Get(place_x - 1, place_y + 1 + i))) {
      cplist_x[connect_points] = place_x;
      cplist_y[connect_points] = place_y + 1 + i;
      cplist_r[connect_points] = GetRoom(place_x - 1, place_y + 1 + i);
      cplist_t[connect_points] = 2;
      connect_points++;
    }
		
    if (SuitableConnection(Get(place_x + room_w, place_y + 1 + i))) {
      cplist_x[connect_points] = place_x + room_w - 1;
      cplist_y[connect_points] = place_y + 1 + i;
      cplist_r[connect_points] = GetRoom(place_x + room_w, place_y + 1 + i);
      cplist_t[connect_points] = 3;
      connect_points++;
    }
  }
	
  for (i = 0; i < connect_points; i++) {
    if (cplist_r[i] == creator) {
      sr_cp[sr_cps++] = i;
    } else {
      sr_np[sr_nps++] = i;
    }
  }
	
  /* printf("cps: %d      room: %d\n", sr_cps, total_rooms); */

  assert(sr_cps > 0);
	
  i = rndval(0, sr_cps-1);
  MakeConnect(cplist_x[sr_cp[i]], cplist_y[sr_cp[i]], cplist_t[sr_cp[i]]);
	
  /* one other connection (if we can) */
  if (sr_nps > 0) {
    i = rndval(0, sr_nps-1);
    MakeConnect(cplist_x[sr_np[i]], cplist_y[sr_np[i]], cplist_t[sr_np[i]]);
  }

}