[go: up one dir, main page]

Menu

[00134f]: / media / Two_D.cc  Maximize  Restore  History

Download this file

108 lines (91 with data), 2.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
// Two_D.cc - Convenience functions for 2D OpenGl rendering.
//
// Copyright (C) 2013 Sam Varner
//
// This file is part of Vamos Automotive Simulator.
//
// Vamos is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Vamos is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Vamos. If not, see <http://www.gnu.org/licenses/>.
#include "Two_D.h"
#include <GL/glut.h>
using namespace Vamos_Media;
Two_D::Two_D (int width, int height)
{
glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
gluOrtho2D (0, width, 0, height);
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
glLoadIdentity ();
glDisable (GL_DEPTH_TEST);
glDisable (GL_LIGHTING);
glDisable (GL_TEXTURE_2D);
}
Two_D::~Two_D ()
{
glEnable (GL_DEPTH_TEST);
glEnable (GL_LIGHTING);
glEnable (GL_TEXTURE_2D);
glMatrixMode (GL_PROJECTION);
glPopMatrix ();
glMatrixMode (GL_MODELVIEW);
glPopMatrix ();
}
void Two_D::draw_string (const std::string& str, double x, double y)
{
glColor3f (1.0, 1.0, 1.0);
glRasterPos2d (x, y);
for (std::string::const_iterator it = str.begin (); it != str.end (); ++it)
{
glutBitmapCharacter (GLUT_BITMAP_8_BY_13, *it);
}
}
void Two_D::bar (const Vamos_Geometry::Rectangle& box,
double red, double green, double blue,
double fraction)
{
glColor3f (red, green, blue);
// border
glBegin (GL_LINE_LOOP);
glVertex2f (box.left (), box.bottom ());
glVertex2f (box.left (), box.top ());
glVertex2f (box.right (), box.top ());
glVertex2f (box.right (), box.bottom ());
glEnd ();
// fill
glBegin (GL_QUADS);
const double top = fraction * box.height () + box.bottom ();
glVertex2f (box.left (), box.bottom ());
glVertex2f (box.left (), top);
glVertex2f (box.right (), top);
glVertex2f (box.right (), box.bottom ());
glEnd ();
}
void Two_D::lights (double x, double y, double r, int n, int n_on,
double red_on, double green_on, double blue_on,
double red_off, double green_off, double blue_off)
{
glTranslatef (x + 6*r, y, 0.0);
GLUquadricObj* disk = gluNewQuadric();
gluQuadricDrawStyle (disk, GLU_FILL);
glColor3f (red_off, green_off, blue_off);
for (int light = 1; light <= n; light++)
{
if (light >= n_on)
glColor3f (red_on, green_on, blue_on);
glTranslatef (-2.5*r, 0.0, 0.0);
gluDisk (disk, 0.0, r, 32, 32);
}
gluDeleteQuadric (disk);
}