61 #include "GlutViewer.hh"
74 std::map<int, GlutViewer*> GlutViewer::windows__;
80 GlutViewer::GlutViewer(
const char* _title,
int _width,
int _height) :
90 glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE | GLUT_ALPHA);
91 glutInitWindowSize(_width, _height);
92 glViewport(0, 0, _width, _height);
93 windowID_ = glutCreateWindow(_title);
94 windows__[windowID_] =
this;
98 glutDisplayFunc(display__);
99 glutKeyboardFunc(keyboard__);
100 glutSpecialFunc(special__);
101 glutMouseFunc(mouse__);
102 glutMotionFunc(motion__);
103 glutPassiveMotionFunc(passivemotion__);
104 glutReshapeFunc(reshape__);
105 glutVisibilityFunc(visibility__);
119 glutDestroyWindow(windowID_);
143 GLfloat pos[4], col[4];
144 col[0] = col[1] = col[2] = 0.6f;
148 #define SET_LIGHT(i,x,y,z) { \
149 pos[0]=x; pos[1]=y; pos[2]=z; \
150 glLightfv(GL_LIGHT##i, GL_POSITION, pos); \
151 glLightfv(GL_LIGHT##i, GL_DIFFUSE, col); \
152 glLightfv(GL_LIGHT##i, GL_SPECULAR, col); \
153 ACG::GLState::enable(GL_LIGHT##i); \
156 SET_LIGHT(0, 0.0f, 0.0f, 1.0f);
157 SET_LIGHT(1, -1.0f, 1.0f, 0.7f);
158 SET_LIGHT(2, 1.0f, 1.0f, 0.7f);
167 glstate_.
viewport(0, 0, width_, height_);
176 GlutViewer::update_projection()
180 (GLfloat) width_ / (GLfloat) height_,
188 GlutViewer* GlutViewer::current_window() {
189 return windows__[glutGetWindow()];
192 void GlutViewer::display__(
void) {
193 current_window()->display();
196 void GlutViewer::idle__(
void) {
197 current_window()->idle();
200 void GlutViewer::keyboard__(
unsigned char key,
int x,
int y) {
201 current_window()->keyboard((
int)key, x, y);
204 void GlutViewer::motion__(
int x,
int y) {
205 current_window()->motion(x, y);
208 void GlutViewer::mouse__(
int button,
int state,
int x,
int y) {
209 current_window()->mouse(button, state, x, y);
212 void GlutViewer::passivemotion__(
int x,
int y) {
213 current_window()->passivemotion(x, y);
216 void GlutViewer::reshape__(
int w,
int h) {
217 current_window()->reshape(w, h);
220 void GlutViewer::special__(
int key,
int x,
int y) {
221 current_window()->keyboard(key, x, y);
224 void GlutViewer::visibility__(
int visible) {
225 current_window()->visibility(visible);
232 void GlutViewer::idle(
void) {
235 void GlutViewer::keyboard(
int key,
int ,
int )
244 bak_left_ = glutGet(GLUT_WINDOW_X);
245 bak_top_ = glutGet(GLUT_WINDOW_Y);
246 bak_width_ = glutGet(GLUT_WINDOW_WIDTH);
247 bak_height_ = glutGet(GLUT_WINDOW_HEIGHT);
251 glutReshapeWindow(bak_width_, bak_height_);
252 glutPositionWindow(bak_left_, bak_top_);
260 void GlutViewer::motion(
int ,
int ) {
263 void GlutViewer::mouse(
int ,
int ,
int ,
int ) {
266 void GlutViewer::passivemotion(
int ,
int ) {
269 void GlutViewer::visibility(
int ) {
272 void GlutViewer::reshape(
int w,
int h)
275 glstate_.
viewport(0, 0, width_, height_);
279 (GLfloat) width_ / (GLfloat) height_,
285 void GlutViewer::display(
void)
287 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
static void enable(GLenum _cap)
replaces glEnable, but supports locking
Namespace providing different geometric functions concerning angles.
void initialize()
initialize all state variables (called by constructor)
void translate(double _x, double _y, double _z, MultiplyFrom _mult_from=MULT_FROM_RIGHT)
translate by (_x, _y, _z)
void reset_projection()
reset projection matrix (load identity)
static void shadeModel(GLenum _mode)
replaces glShadeModel, supports locking
static void disable(GLenum _cap)
replaces glDisable, but supports locking
void viewport(int _left, int _bottom, int _width, int _height, int _glwidth=0, int _glheight=0)
set viewport (lower left corner, width, height, glcontext width, height)
void perspective(double _fovY, double _aspect, double _near_plane, double _far_plane)
perspective projection