Beispiel #1
0
static void do_bloom(CTexture* t)
{
	glBindTexture(GL_TEXTURE_2D, 0);
	glViewport(0, 0, t->_size, t->_size);
	glCullFace(GL_BACK);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDepthMask(true);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glCullFace(GL_BACK);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_FOG);
	glFogf(GL_FOG_START, RenderFogDistance() / 2);
	glFogf(GL_FOG_END, RenderFogDistance());
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_TEXTURE_2D);
	EntityRender();
	CarRender();
	LightRender();
	glBindTexture(GL_TEXTURE_2D, t->_glid);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, t->_size, t->_size, 0);
}
Beispiel #2
0
void CLight::Render ()
{

    int       angle;
    GLvector  pos;
    GLvector  camera;
    GLvector  camera_position;
    GLvector2 offset;

    if (!Visible (_cell_x, _cell_z))
        return;
    camera = CameraAngle ();
    camera_position = CameraPosition ();
    if (fabs (camera_position.x - _position.x) > RenderFogDistance ())
        return;
    if (fabs (camera_position.z - _position.z) > RenderFogDistance ())
        return;
    if (_blink && (GetTickCount () % _blink_interval) > 200)
        return;
    angle = (int)MathAngle (camera.y);
    offset = angles[_size][angle];
    pos = _position;
    glColor4fv (&_color.red);
    glTexCoord2f (0, 0);
    glVertex3f (pos.x + offset.x, pos.y - _vert_size, pos.z + offset.y);
    glTexCoord2f (0, 1);
    glVertex3f (pos.x - offset.x, pos.y - _vert_size, pos.z - offset.y);
    glTexCoord2f (1, 1);
    glVertex3f (pos.x - offset.x, pos.y + _vert_size, pos.z - offset.y);
    glTexCoord2f (1, 0);
    glVertex3f (pos.x + offset.x, pos.y + _vert_size, pos.z + offset.y);

}
Beispiel #3
0
void CCar::Update (void)
{

  int       new_row, new_col;
  GLvector  old_pos;    
  GLvector  camera;

  //If the car isn't ready, place it on the map and get it moving
  camera = CameraPosition ();
  if (!m_ready) {
    //if the car isn't ready, we need to place it somewhere on the map
    m_row = DEAD_ZONE + RandomVal (WORLD_SIZE - DEAD_ZONE * 2);
    m_col = DEAD_ZONE + RandomVal (WORLD_SIZE - DEAD_ZONE * 2);
    //if there is already a car here, forget it.  
    if (carmap[m_row][m_col] > 0)
      return;
    //if this spot is not a road, forget it
    if (!(WorldCell (m_row, m_col) & CLAIM_ROAD)) 
      return;
    if (!Visible (glVector ((float)m_row, 0.0f, (float)m_col)))
      return;
    //good spot. place the car
    m_position = glVector ((float)m_row, 0.1f, (float)m_col);
    m_drive_position = m_position;
    m_ready = true;
    if (WorldCell (m_row, m_col) & MAP_ROAD_NORTH) 
      m_direction = NORTH;
    if (WorldCell (m_row, m_col) & MAP_ROAD_EAST) 
      m_direction = EAST;
    if (WorldCell (m_row, m_col) & MAP_ROAD_SOUTH) 
      m_direction = SOUTH;
    if (WorldCell (m_row, m_col) & MAP_ROAD_WEST) 
      m_direction = WEST;
    m_drive_angle = dangles[m_direction];
    m_max_speed = (float)(4 + RandomVal (6)) / 10.0f;
    m_speed = 0.0f;
    m_change = 3;
    m_stuck = 0;
    carmap[m_row][m_col]++;
  }
  //take the car off the map and move it
  carmap[m_row][m_col]--;
  old_pos = m_position;
  m_speed += m_max_speed * 0.05f;
  m_speed = MIN (m_speed, m_max_speed);
  m_position += direction[m_direction] * MOVEMENT_SPEED * m_speed;
  //If the car has moved out of view, there's no need to keep simulating it. 
  if (!Visible (glVector ((float)m_row, 0.0f, (float)m_col))) 
    m_ready = false;
  //if the car is far away, remove it.  We use manhattan units because buildings almost always
  //block views of cars on the diagonal.
  if (fabs (camera.x - m_position.x) + fabs (camera.z - m_position.z) > RenderFogDistance ())
    m_ready = false;
  //if the car gets too close to the edge of the map, take it out of play
  if (m_position.x < DEAD_ZONE || m_position.x > (WORLD_SIZE - DEAD_ZONE))
    m_ready = false;
  if (m_position.z < DEAD_ZONE || m_position.z > (WORLD_SIZE - DEAD_ZONE))
    m_ready = false;
  if (m_stuck >= STUCK_TIME)
    m_ready = false;
  if (!m_ready)
    return;
  //Check the new position and make sure its not in another car
  new_row = (int)m_position.x;
  new_col = (int)m_position.z;
  if (new_row != m_row || new_col != m_col) {
    //see if the new position places us on top of another car
    if (carmap[new_row][new_col]) {
      m_position = old_pos;
      m_speed = 0.0f;
      m_stuck++;
    } else {
      //look at the new position and decide if we're heading towards or away from the camera
      m_row = new_row;
      m_col = new_col;
      m_change--;
      m_stuck = 0;
      if (m_direction == NORTH)
        m_front = camera.z < m_position.z;
      else if (m_direction == SOUTH)
        m_front = camera.z > m_position.z;
      else if (m_direction == EAST)
        m_front = camera.x > m_position.x;
      else 
        m_front = camera.x < m_position.x;
    }
  }
  m_drive_position = (m_drive_position + m_position) / 2.0f;
  //place the car back on the map
  carmap[m_row][m_col]++;

}