Ejemplo n.º 1
0
void Manager::draw() const {
  std::stringstream strm;
  std::string msg;
  clouds.draw();
  hills.draw();
  view->draw();
  int score = orbs.getScore(); 
  
	

if(var1==0)
  pter->draw();
 else
 pterleft->draw();
  orbs.draw();
  //strm << "Tracking orb number: " << orbs.getTrackedOrb()  << std::ends;
  //msg = strm.str();

  //io->printMessageAt("Press <space> to track the other orb", 10, 10);
  //io->printMessageAt(msg, 10, 30);
  strm << "Score is : " << score  << " Time is "<< remainingTime << std::ends;
  msg = strm.str();
  io->printMessageAt(msg, 10, 30);
  io->printMessageAt("Time: ", 10, 50);
  io->printMessageAt("Health: ", 10, 70);
if ( !drawTheStupidHud ){
  io->printMessageAt("Press F1 to see the options", 10, 10);
}
else if(drawTheStupidHud) drawHud();  
}
Ejemplo n.º 2
0
void MainGame::draw() {
    // Set the base depth to 1.0
    glClearDepth(1.0);
    // Clear the color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glActiveTexture(GL_TEXTURE0);

    // Grab the camera matrix
    glm::mat4 projectionMatrix = m_camera.getCameraMatrix();

    _ballRenderers[_currentRenderer]->renderBalls(m_spriteBatch, m_balls, projectionMatrix);

	m_textureProgram.use();

	// Make sure the shader uses texture 0
	GLint textureUniform = m_textureProgram.getUniformLocation("mySampler");
	glUniform1i(textureUniform, 0);

	GLint pUniform = m_textureProgram.getUniformLocation("P");
	glUniformMatrix4fv(pUniform, 1, GL_FALSE, &projectionMatrix[0][0]);

    drawHud();

    m_textureProgram.unuse();

    m_window.swapBuffer();
}
Ejemplo n.º 3
0
/*
	Draws the game

*/
void Game::draw()
{
	glClearDepth(1.0);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glActiveTexture(GL_TEXTURE0);

	program_.use();
	sb_.begin();

	// Make sure the shader uses texture 0
	GLint textureUniform = program_.getUniformLocation("mySampler");
	glUniform1i(textureUniform, 0);
	// Grab the camera matrix
	glm::mat4 projectionMatrix = camera_.getCameraMatrix();
	// Grab the camera matrix
	GLint pUniform = program_.getUniformLocation("P");
	glUniformMatrix4fv(pUniform, 1, GL_FALSE, &projectionMatrix[0][0]);

	worldManager_.draw(sb_);

	sb_.end();
	sb_.renderBatch();

	drawHud();

	program_.unuse();
	SDL_GL_SwapWindow(window_);
}
Ejemplo n.º 4
0
void display()
{
  static const float ambient [] = {0.5, 0.5, 0.5, 1.0};
  static const float diffuse [] = {1.0, 0.0, 0.0, 1.0};
  static const float specular[] = {1.0, 1.0, 1.0, 1.0};
  static const float lightPos[] = {2.0, 2.0, 2.0, 0.0};
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();

  /* camera transform */
  glTranslatef(0.0, 0.0, -zoom);     /* zoom transform */
  glRotatef(camRotX, 1.0, 0.0, 0.0); /* rotation around x axis */
  glRotatef(camRotY, 0.0, 1.0, 0.0); /* rotation around y axis */

  /* set the light position */
  glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
  glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
  glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
  glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
  glMaterialf(GL_FRONT, GL_SHININESS, shininess);

  /* update uniform variable */
  if (options[OPT_SHADING_TOGG])
      updateShader();

  /* draw the scene */
  drawScene();

  /* draw normals */
  drawNormal();

  /* Render the hud */
  glDisable(GL_DEPTH_TEST);
  glMatrixMode(GL_PROJECTION);
  glPushMatrix();
  glLoadIdentity();
  glOrtho(0,1,0,1,-1,1);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();

  if (options[OPT_LIGHTENING])
      glDisable(GL_LIGHTING);
  /* display current setting */
  glTranslatef(0.0, 0.0, -0.5);
  drawHud();

  if (options[OPT_LIGHTENING])
      glEnable(GL_LIGHTING);

  glMatrixMode(GL_PROJECTION);
  glPopMatrix();
  glMatrixMode(GL_MODELVIEW);
  glEnable(GL_DEPTH_TEST);

  glutSwapBuffers();

  // Check for gl errors.
  checkGLErrors();
}
Ejemplo n.º 5
0
void MainGame::drawGame() {
    // Set the base depth to 1.0
    glClearDepth(1.0);
    // Clear the color and depth buffer
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    m_textureProgram.use();

    // Draw code goes here
    glActiveTexture(GL_TEXTURE0);

    // Make sure the shader uses texture 0
    GLint textureUniform = m_textureProgram.getUniformLocation("mySampler");
    glUniform1i(textureUniform, 0);

    // Grab the camera matrix
    glm::mat4 projectionMatrix = m_camera.getCameraMatrix();
    GLint pUniform = m_textureProgram.getUniformLocation("P");
    glUniformMatrix4fv(pUniform, 1, GL_FALSE, &projectionMatrix[0][0]);

    // Draw the level
    m_levels[m_currentLevel]->draw();

    // Begin drawing agents
    m_agentSpriteBatch.begin();

    m_grid.draw(m_agentSpriteBatch, m_camera);

    // End spritebatch creation
    m_agentSpriteBatch.end();

    // Render to the screen
    m_agentSpriteBatch.renderBatch();

    // Render the particles
    m_particleEngine.draw(&m_agentSpriteBatch);

    // Render the heads up display
    drawHud();

    // Unbind the program
    m_textureProgram.unuse();

    // Swap our buffer and draw everything to the screen!
    m_window.swapBuffer();
}
Ejemplo n.º 6
0
void
LevelFour::drawShadow()
{
	secondlayer->setOnlyClipNumber(5);
	int radius = 0;
	if(isCSpecial())
	{
		radius = 40+(int)(inventory->getQtdBattery()*1.75);
		secondlayer->defineCurrentIdleTime(1);
		if(secondlayer->getCurrentIdleTime() == 16)
		{
			secondlayer->setCurrentIdleTime(0);
			inventory->setQtdBattery(-1);
		}
		else
			secondlayer->setCurrentIdleTime(secondlayer->getCurrentIdleTime()+1);
	}
	int x = aim->getKernel().x;
	int y = aim->getKernel().y;
	int i = 0;
	int j = 0;
	for(i = 0; i<=100 ; i++)
	{
		for(j = 0; j<=100; j++)
		{
			if(	(8*i+getCameraLeftPosition()<=x-radius||6*j<=y-radius) ||
					(8*i+getCameraLeftPosition()>=x+radius||6*j>=y+radius) ||
					(8*i+getCameraLeftPosition()>x-radius&&6*j<=(y-radius))	)
			{
				secondlayer->generatePosition(8*i,6*j,8,6);
				secondlayer->draw();
			}
		}
	}
	drawHud();
	aim->draw();
}
Ejemplo n.º 7
0
void Hud::draw(Uint32 liveNum, Uint32 freeNum, int enemyLeft)
{
   if(hudTime <= existTime || showHud == true) 
        drawHud(liveNum, freeNum, enemyLeft);
}
Ejemplo n.º 8
0
void display() {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

  /* camera transform */
	glTranslatef(0, 0, -camera.zoom);
	glRotatef(camera.rot.x, 1, 0, 0);
	glRotatef(camera.rot.y, 0, 1, 0);

  drawAxes(0.5);

  /* set the light position  */
  if(options[OPT_LIGHTING]) {
    glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
    glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
    glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
    glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
    glMaterialf(GL_FRONT, GL_SHININESS, shininess);
    glEnable(GL_LIGHTING);
  } else {
    glDisable(GL_LIGHTING);
  }

  if(options[OPT_SMOOTH_SHADE])
    glShadeModel(GL_SMOOTH);
  else
    glShadeModel(GL_FLAT);

  if(options[OPT_DRAW_NORMALS])
    drawNormals();
  
  if(options[OPT_SHADER]) {
    glUseProgram(currentShader);
    if (currentShader != 0 && (loc = glGetUniformLocation(currentShader, "GeomGen")) != -1)
      glUniform1i(loc, options[OPT_SHADER_GEN]);
  }

  if(options[OPT_WIREFRAME])
    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  else
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

  if(options[OPT_BUMP_MAP]) {
    glUseProgram(bumpShader);
    if (bumpShader != 0 && (loc = glGetUniformLocation(bumpShader, "LightPosition")) != -1)
      glUniform3fv(loc, 1, lightPos);
    if (bumpShader != 0 && (loc = glGetUniformLocation(bumpShader, "SurfaceColor")) != -1)
      glUniform3f(loc, 1.0, 0.0, 0.0);
    if (bumpShader != 0 && (loc = glGetUniformLocation(bumpShader, "BumpDensity")) != -1)
      glUniform1f(loc, 4);
    if (bumpShader != 0 && (loc = glGetUniformLocation(bumpShader, "BumpSize")) != -1)
      glUniform1f(loc, 0.15);
    if (bumpShader != 0 && (loc = glGetUniformLocation(bumpShader, "SpecularFactor")) != -1)
      glUniform1f(loc, 0.5);
    if (bumpShader != 0 && (loc = glGetUniformLocation(bumpShader, "R")) != -1)
      glUniform1f(loc, R);
    if (bumpShader != 0 && (loc = glGetUniformLocation(bumpShader, "r")) != -1)
      glUniform1f(loc, r);
  
    if (bumpShader != 0 && (loc = glGetUniformLocation(bumpShader, "Time")) != -1) {
      double tt = 1.0;
      if(options[OPT_ANIM]) {
        double ipart, fpart;
        fpart = modf(thisTime * 0.001f, &ipart);
        if((int)ipart % 2 == 0)
          // using slightly less fpart smoothes animation
          tt = 1.1 - fpart; 
        else
          tt = fpart;
      }
      glUniform1f(loc, tt);
    }

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, geom_uv);
    glDrawElements(GL_QUAD_STRIP, n_geom_indices, GL_UNSIGNED_INT, geom_indices);
    glDisableClientState(GL_VERTEX_ARRAY);
  } else if(options[OPT_SHADER_GEN]) {
    /* pass in radii as uniforms */
    if (currentShader != 0 && (loc = glGetUniformLocation(currentShader, "R")) != -1)
      glUniform1f(loc, R);
    if (currentShader != 0 && (loc = glGetUniformLocation(currentShader, "r")) != -1)
      glUniform1f(loc, r);
    if (currentShader != 0 && (loc = glGetUniformLocation(currentShader, "GenMode")) != -1)
      glUniform1i(loc, gMode);

    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(3, GL_FLOAT, 0, geom_uv);
    glDrawElements(GL_QUAD_STRIP, n_geom_indices, GL_UNSIGNED_INT, geom_indices);
    glDisableClientState(GL_VERTEX_ARRAY);
  } else {
    if(options[OPT_IMMEDIATE]) {
      drawImmediate();
    } else {
      glEnableClientState(GL_VERTEX_ARRAY);
      glEnableClientState(GL_NORMAL_ARRAY);
      glNormalPointer(GL_FLOAT, 0, geom_norms);

      if(options[OPT_VBO])
        drawVBO();
      else
        drawVertexArray();

      glDisableClientState(GL_NORMAL_ARRAY);
      glDisableClientState(GL_VERTEX_ARRAY);
    }
  }

  /* Render the hud */
	glDisable(GL_DEPTH_TEST);
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	glOrtho(0, 1, 0, 1, -1, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	glUseProgram(0);
	glDisable(GL_LIGHTING);
	glTranslatef(0.0, 0.0, -0.5);
	drawHud();
	glEnable(GL_LIGHTING);
	
	glMatrixMode(GL_PROJECTION);
	glPopMatrix(); 
	glMatrixMode(GL_MODELVIEW);
	glEnable(GL_DEPTH_TEST);

	glutSwapBuffers();
  int err;
	if ((err = glGetError()) != GL_NO_ERROR)
		fprintf(stderr, "%s\n", gluErrorString(err));
}
Ejemplo n.º 9
0
void MainGame::drawGame() {
	// Set the base depth to 1.0
	glClearDepth(1.0);
	// Clear the color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	m_textureProgram.use();

	// Draw code goes here
	glActiveTexture(GL_TEXTURE0);

	// Make sure the shader uses texture 0
	m_textureProgram.setUniform1i("mySampler",0);

	// Grab the camera matrix
	glm::mat4 projectionMatrix = m_camera.getCameraMatrix();
	m_textureProgram.setUniformMatrix4fv("P", projectionMatrix);

	// Draw the level
	m_levels[m_currentLevel]->draw();

	// Begin drawing agents
	m_agentSpriteBatch.begin();

	const glm::vec2 agentDims(AGENT_RADIUS * 2.0f);

	// Draw the humans
	for (auto i = 0; i < m_humans.size(); i++) {
		if (m_camera.isBoxInView(m_humans[i]->getPosition(), agentDims)) {
			m_humans[i]->draw(m_agentSpriteBatch);
		}
	}

	// Draw the zombies
	for (auto i = 0; i < m_zombies.size(); i++) {
		if (m_camera.isBoxInView(m_zombies[i]->getPosition(), agentDims)) {
			m_zombies[i]->draw(m_agentSpriteBatch);
		}
	}

	// Draw the bullets
	for (auto i = 0; i < m_bullets.size(); i++) {
		m_bullets[i].draw(m_agentSpriteBatch);
	}

	// End spritebatch creation
	m_agentSpriteBatch.end();

	// Render to the screen
	m_agentSpriteBatch.renderBatch();

	// Render the particles
	m_particleEngine2D.draw(&m_agentSpriteBatch);

	// Render the heads up display
	drawHud();

	// Unbind the program
	m_textureProgram.unuse();

	// Swap our buffer and draw everything to the screen!
	m_window.swapBuffer();
}
Ejemplo n.º 10
0
void Renderer::run()
{
	NBT_Debug("begin");

	al_hide_mouse_cursor(dpy_);

	al_identity_transform(&camera_transform_);

	float x = -camera_pos_.x, y = -camera_pos_.y, z = -camera_pos_.z;
	//x = -dim0_->spawnX();
	//z = -dim0_->spawnZ();

	al_translate_transform_3d(&camera_transform_, x, y, z);

	al_rotate_transform_3d(&camera_transform_, 0.0, 1.0, 0.0, DEG_TO_RAD(180));

	memset(key_state_, 0, sizeof(key_state_) * sizeof(key_state_[0]));

	al_start_timer(tmr_);

	NBT_Debug("run!");

	//al_use_shader(nullptr);

	/*ALLEGRO_TRANSFORM trans;
	al_identity_transform(&trans);
	al_orthographic_transform(&trans, 0, 0, -1, al_get_display_width(dpy_), al_get_display_height(dpy_), 1);
	al_set_projection_transform(dpy_, &trans);
	al_identity_transform(&trans);
	al_use_transform(&trans);

	if(!resManager_->getAtlas()->getSheet(0)->alBitmap())
		NBT_Debug("no sheet bitmap????");
	*/
	//al_draw_bitmap(resManager_->getAtlas()->getSheet(0)->alBitmap(), 0, 0, 0);

	//al_flip_display();
	//sleep(10);

	bool redraw = false;
	bool doUpdateLookPos = false;
	bool cleared = false;
	
	while(1)
	{
		ALLEGRO_EVENT ev;
      al_wait_for_event(queue_, &ev);

      if(ev.type == ALLEGRO_EVENT_TIMER)
		{
         redraw = true;
			//cam_.rx = 1.0;
			float x = 0.0, y = 0.0, z = 0.0;
			float translate_diff = 0.3;
			float ry = 0.0;
			float rotate_diff = 0.04;
			bool changeTranslation = false;
			bool changeRotation = false;

			if(key_state_[ALLEGRO_KEY_W])
			{
				z += translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_S])
			{
				z -= translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_A])
			{
				x += translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_D])
			{
				x -= translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_SPACE])
			{
				y -= translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_LSHIFT])
			{
				y += translate_diff;
				changeTranslation = true;
			}

			if(key_state_[ALLEGRO_KEY_LEFT])
			{
				ry += rotate_diff;
				changeRotation = true;
			}

			if(key_state_[ALLEGRO_KEY_RIGHT])
			{
				ry -= rotate_diff;
				changeRotation = true;
			}

			if(changeTranslation)
			{
				//camera_pos_.translate(x, y, z);
				al_translate_transform_3d(&camera_transform_, x, y, z);
				doUpdateLookPos = true;
			}

			if(changeRotation)
			{
				al_rotate_transform_3d(&camera_transform_, 0.0, 1.0, 0.0, ry);
				doUpdateLookPos = true;
			}

			if(doUpdateLookPos)
				updateLookPos();

      }
      else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
		{
			NBT_Debug("display close");
         break;
      }
      else if(ev.type == ALLEGRO_EVENT_KEY_DOWN)
		{
			//NBT_Debug("key down");
			//NBT_Debug("pos: %fx%f", -camera_transform_.m[2][0], -camera_transform_.m[2][2]);
			key_state_[ev.keyboard.keycode] = true;

			if (ev.keyboard.keycode == ALLEGRO_KEY_Q)
			{
				break;
			}
			else if(ev.keyboard.keycode == ALLEGRO_KEY_C)
			{
				NBT_Debug("CLEAR CHUNKS");
				glBindVertexArray(vao_);
				for(auto ch: chunkData_)
				{
					delete ch.second;
				}
				glBindVertexArray(0);
				chunkData_.clear();

				glDeleteBuffers(1, &vao_);
				
				cleared = true;
			}
			else if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
			{
				grab_mouse_ = !grab_mouse_;
			}
		}
		else if(ev.type == ALLEGRO_EVENT_KEY_UP)
		{
			//NBT_Debug("pos: %fx%f", -camera_transform_.m[2][0], -camera_transform_.m[2][2]);
			key_state_[ev.keyboard.keycode] = false;
		}
		else if(ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_UP)
		{
				grab_mouse_ = true;
		}
		else if(ev.type == ALLEGRO_EVENT_MOUSE_AXES && grab_mouse_)
		{
			float dx = ev.mouse.dx, dy = ev.mouse.dy;

			if(dy > 0 && dy < 1.5)
				dy = 0.0;

			if(dy < 0 && dy > -1.5)
				dy = 0.0;

			if(dx > 0 && dx < 1.5)
				dy = 0.0;

			if(dx < 0 && dx > -1.5)
				dx = 0.0;

			float ry = dx / al_get_display_width(dpy_), rx = dy / al_get_display_height(dpy_);

			rx_look += rx;
			al_rotate_transform_3d(&camera_transform_, 0.0, 1.0, 0.0, ry);
//			al_rotate_transform_3d(&camera_transform_, 1.0, 0.0, 0.0, rx);

			//cam_.rx += dy / al_get_display_height(dpy_);

			al_set_mouse_xy(dpy_, al_get_display_width(dpy_)/2.0, al_get_display_height(dpy_)/2.0);

			doUpdateLookPos = true;
		}

      if(redraw && al_is_event_queue_empty(queue_))
		{
			if(!loadChunkQueue.empty())
			{
				NBT_Debug("%i chunks to load", loadChunkQueue.size());

				std::pair<int32_t, int32_t> pos = loadChunkQueue.front();
				loadChunkQueue.pop();

				processChunk(pos.first, pos.second);
			}
			else
			{
				if(!cleared)
				{
					//NBT_Debug("pos: %fx%fx%f", camera_pos_.getX(), camera_pos_.getZ(), camera_pos_.getY());
					autoLoadChunks(camera_pos_.getX() / 16.0, camera_pos_.getZ() / 16.0);
				}
			}

			ALLEGRO_STATE state;
			al_store_state(&state, ALLEGRO_STATE_ALL);
			al_set_projection_transform(dpy_, &al_proj_transform_);

			glClear(GL_DEPTH_BUFFER_BIT);

         redraw = false;
			al_clear_to_color(al_map_rgb(255,255,255));
         draw();

			al_restore_state(&state);
			al_set_projection_transform(dpy_, &al_proj_transform_);

			drawHud();

			al_restore_state(&state);
         al_flip_display();
      }


	}

	NBT_Debug("stop timer");
	al_stop_timer(tmr_);

	NBT_Debug("end");


	NBT_Debug("sizeof GL_FLOAT: %i", sizeof(GLfloat));
}