Ejemplo n.º 1
0
void DrawMinimap(){
	float ratio;
	// Prevenir a divisão por zero, se a janela for muito pequena
	if (height == 0) height = 1;
	ratio = 1.0 * width / height;
	glViewport(width / 1.5, height / 1.5, width / 2, height / 2);
	glClear(GL_DEPTH_BUFFER_BIT);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45, ratio, 1, 5000);

	//HERE BE DRAGONS AND MAGIC NUMBERS
	float offsetX;
	if (width > 800) {
		offsetX = -30.0;
	}
	else{
		offsetX = -90.0;
	}
	glTranslatef(offsetX, -150.0, 0.0);
	gluLookAt(0.0, 1300, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, -1.0);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	DrawCamera();
	DrawPlanetas(true);
}
Ejemplo n.º 2
0
int GameLoop()
{
	Timer Timer;
	int Frame = 0;

	bool quit = false;
	SDL_Event PollEvent;
	while(!quit)
	{
		int frameTicks = Timer.start();

		while(SDL_PollEvent(&PollEvent))
		{
			if(PollEvent.type == SDL_QUIT)
			{
				quit = true;
				break;
			}
			if(HandleInput(PollEvent, frameTicks) == -1)
			{
				quit = true;
				break;
			}			
		}
		if(quit == true)
			break;

		Actions(frameTicks);
		
		SDL_FillRect(screen, &(screen->clip_rect), backgroundColor);

		DrawCamera();
		DrawUI();

		if(SDL_Flip(screen) == -1)
			return 1;

        //Cap the frame rate
        if( Timer.get_ticks() < 1000 / MAX_FPS )
        {
			int delay =  ( 1000 / MAX_FPS ) - Timer.get_ticks();
            SDL_Delay(delay);
        }

		Frame++;
		if(Frame % MAX_FPS == 0)
			Frame = 0;
	}

	return 0;
}
Ejemplo n.º 3
0
void GLUTRedraw(void)
{
  // Initialize OpenGL drawing modes
  glEnable(GL_LIGHTING);
  glDisable(GL_BLEND);
  glBlendFunc(GL_ONE, GL_ZERO);
  glDepthMask(true);

  // Clear window 
  R3Rgb background = scene->background;
  glClearColor(background[0], background[1], background[2], background[3]);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Load camera
  LoadCamera(&camera);

  // Load scene lights
  LoadLights(scene);

  // Draw scene camera
  DrawCamera(scene);

  // Draw scene lights
  DrawLights(scene);

  // Draw particles
  DrawParticles(scene);

  // Draw particle sources 
  DrawParticleSources(scene);

  // Draw particle sinks 
  DrawParticleSinks(scene);

  // Draw particle springs
  DrawParticleSprings(scene);

  // Draw scene surfaces
  if (show_faces) {
    glEnable(GL_LIGHTING);
    DrawScene(scene);
  }

  // Draw scene edges
  if (show_edges) {
    glDisable(GL_LIGHTING);
    glColor3d(1 - background[0], 1 - background[1], 1 - background[2]);
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    DrawScene(scene);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  }

  // Save image
  if (save_image) {
    char image_name[256];
    static int image_number = 1;
    for (;;) {
      sprintf(image_name, "image%d.jpg", image_number++);
      FILE *fp = fopen(image_name, "r");
      if (!fp) break; 
      else fclose(fp);
    }
    GLUTSaveImage(image_name);
    printf("Saved %s\n", image_name);
    save_image = 0;
  }

  // Save video
  if (save_video) {
    char frame_name[512];
    static int next_frame = 0;
    static int num_frames_recorded = 0;
    for (;;) {
      sprintf(frame_name, "%sframe%04d.jpg", video_prefix, next_frame++);
      FILE *fp = fopen(frame_name, "r");
      if (!fp) break; 
      else fclose(fp);
    }
    GLUTSaveImage(frame_name);
    if (next_frame % 100 == 1) {
      printf("Saved %s\n", frame_name);
    }
    if (num_frames_to_record == ++num_frames_recorded) {
      save_video = 0;
      printf("Recorded %d frames, stopping as instructed.\n", num_frames_recorded);
      quit = 1;
    }
  }

  // Quit here so that can save image before exit
  if (quit) {
    if (output_image_name) GLUTSaveImage(output_image_name);
    GLUTStop();
  }

  // Swap buffers 
  glutSwapBuffers();
}    
Ejemplo n.º 4
0
void GLUTRedraw(void)
{
  // Check scene
  if (!scene) return;

  // Set viewing transformation
  viewer->Camera().Load();

  // Clear window
  RNRgb background = scene->Background();
  glClearColor(background.R(), background.G(), background.B(), 1.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  // Load lights
  LoadLights(scene);

  // Draw camera
  if (show_camera) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(5);
    DrawCamera(scene);
    glLineWidth(1);
  }

  // Draw lights
  if (show_lights) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(5);
    DrawLights(scene);
    glLineWidth(1);
  }

  // Draw rays
  if (show_rays) {
    glDisable(GL_LIGHTING);
    glColor3d(0.0, 1.0, 0.0);
    glLineWidth(3);
    DrawRays(scene);
    glLineWidth(1);
  }

  // Draw rays
  if (show_photons) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(1);
    DrawPhotonPaths(scene);
    glLineWidth(1);
  }

  // Draw rays
  if (show_global_samples) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(1);
    DrawGlobalSamples(scene);
    glLineWidth(1);
  }

  // Draw rays
  if (show_caustic_samples) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 1.0, 1.0);
    glLineWidth(1);
    DrawCausticSamples(scene);
    glLineWidth(1);
  }

  // Draw scene nodes
  if (show_shapes) {
    glEnable(GL_LIGHTING);
    R3null_material.Draw();
    DrawShapes(scene, scene->Root());
    R3null_material.Draw();
  }

  // Draw bboxes
  if (show_bboxes) {
    glDisable(GL_LIGHTING);
    glColor3d(1.0, 0.0, 0.0);
    DrawBBoxes(scene, scene->Root());
  }

  // Draw frame time
  if (show_frame_rate) {
    char buffer[128];
    static RNTime last_time;
    double frame_time = last_time.Elapsed();
    last_time.Read();
    if ((frame_time > 0) && (frame_time < 10)) {
      glDisable(GL_LIGHTING);
      glColor3d(1.0, 1.0, 1.0);
      sprintf(buffer, "%.1f fps", 1.0 / frame_time);
      DrawText(R2Point(100, 100), buffer);
    }
  }

  // Capture screenshot image
  if (screenshot_image_name) {
    if (print_verbose) printf("Creating image %s\n", screenshot_image_name);
    R2Image image(GLUTwindow_width, GLUTwindow_height, 3);
    image.Capture();
    image.Write(screenshot_image_name);
    screenshot_image_name = NULL;
  }

  // Swap buffers
  glutSwapBuffers();
}