-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglut_window.cpp
More file actions
executable file
·119 lines (96 loc) · 3.17 KB
/
Copy pathglut_window.cpp
File metadata and controls
executable file
·119 lines (96 loc) · 3.17 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
108
109
110
111
112
113
114
115
116
117
118
119
/*=================================================
* glutapp
* Example program illustrating OpenGL and freeglut
* UC Merced, M. Kallmann
*=================================================*/
#include <stdlib.h>
#include <stdio.h>
#include "glut_window.h"
//===== static members =====
static GlutWindow* Singleton; // we make it statice so that this pointer is hidden from other source files
static GlutWindow::Event CurEvent; // global event to speed-up event creation and keep track of events
//===== GlutWindow =====
GlutWindow::GlutWindow ( const char* label, int x, int y, int w, int h )
{
// First store this instance in our singleton pointer
Singleton = this;
// Set window position (from top corner), and size (width and height)
glutInitWindowPosition ( x, y );
glutInitWindowSize ( w, h );
glutCreateWindow ( label );
//glutFullScreen();
// Initialize OpenGL settings as we want
glEnable ( GL_DEPTH_TEST );
glEnable ( GL_POINT_SMOOTH );
glEnable ( GL_LINE_SMOOTH );
glHint ( GL_LINE_SMOOTH_HINT, GL_NICEST );
glHint ( GL_POINT_SMOOTH_HINT, GL_NICEST );
glPointSize ( 4 );
glLineWidth ( 2 );
// Set up GLUT callback functions to receive events:
::glutKeyboardFunc ( glutKeyboardCB );
::glutSpecialFunc ( glutSpecialCB );
::glutMouseFunc ( glutMouseCB );
::glutMotionFunc ( glutMotionCB );
// Set up idle callback for background processing if needed:
::glutIdleFunc ( glutIdleCB );
// Set up GLUT callback function for resizing window:
::glutReshapeFunc ( glutReshapeCB );
// Set up GLUT callback for drawing the scene:
::glutDisplayFunc ( glutDisplayCB );
// GLUT also supports a simple menu system, you may try this:
int id = ::glutCreateMenu ( glutMenuCB ); // the returned id could be used for adding submenus if needed
glutAttachMenu ( GLUT_RIGHT_BUTTON );
}
//===== freeglut callbacks =====
void GlutWindow::glutKeyboardCB ( unsigned char key, int x, int y )
{
CurEvent.type = Keyboard;
CurEvent.key = key;
CurEvent.mx = x;
CurEvent.my = y;
Singleton->handle ( CurEvent );
}
void GlutWindow::glutSpecialCB ( int key, int x, int y )
{
CurEvent.type = SpecialKey;
CurEvent.key = key;
CurEvent.mx = x;
CurEvent.my = y;
Singleton->handle ( CurEvent );
}
void GlutWindow::glutMouseCB ( int b, int s, int x, int y )
{
CurEvent.type = s==GLUT_UP? MouseUp:MouseDown;
CurEvent.button = b;
CurEvent.mx = x;
CurEvent.my = y;
Singleton->handle ( CurEvent );
}
void GlutWindow::glutMotionCB ( int x, int y )
{
// use this to ignore a mouse event right after menu selection:
//if ( CurEvent.type==Menu ) return;
CurEvent.type = Motion;
CurEvent.mx = x;
CurEvent.my = y;
Singleton->handle ( CurEvent );
}
void GlutWindow::glutMenuCB ( int m )
{
CurEvent.type = Menu;
CurEvent.menuev = m;
Singleton->handle ( CurEvent );
}
void GlutWindow::glutIdleCB ()
{
Singleton->idle();
}
void GlutWindow::glutReshapeCB ( int w, int h )
{
Singleton->resize ( w, h );
}
void GlutWindow::glutDisplayCB ()
{
Singleton->draw();
}