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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <OpenGL/glu.h>
#else
#include <GL/gl.h>
#include <GL/glu.h>
#endif
#include "glancillary.h"
/****************************
* GL init
***************************/
void glaInit(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
//glShadeModel(GL_SMOOTH);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
// Init Model/view transformation
glMatrixMode(GL_MODELVIEW);
// Reset MV matrix
glLoadIdentity();
}
/****************************
* GL camera simulation helpers
***************************/
void glaCameraRotatef(GLfloat *cmat, GLfloat angle, GLfloat x, GLfloat y, GLfloat z)
{
glPushMatrix();
glLoadIdentity();
glRotatef(angle, x, y, z);
glMultMatrixf(cmat);
glGetFloatv(GL_MODELVIEW_MATRIX, cmat);
glPopMatrix();
}
void glaCameraTranslatef(GLfloat *cmat, GLfloat x, GLfloat y, GLfloat z)
{
glPushMatrix();
glLoadIdentity();
glTranslatef(x, y, z);
glMultMatrixf(cmat);
glGetFloatv(GL_MODELVIEW_MATRIX, cmat);
glPopMatrix();
}
/****************************
* GL box drawing example
***************************/
void glaDrawExample(void)
{
// Draw the corner dots
glPointSize(5.0);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_POINTS);
glVertex3f(-1.0, -1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);
glEnd();
// Draw a line with fixed vertices
glColor3f(0.5, 1.0, 0.5);
glBegin(GL_LINE_STRIP);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.5, 0.0);
glVertex3f(0.5, 0.5, 0.5);
glEnd();
// Draw the box boundaries
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_LINE_STRIP);
glVertex3f(-1.0, -1.0, -1.0);
glVertex3f(1.0, -1.0, -1.0);
glVertex3f(1.0, 1.0, -1.0);
glVertex3f(-1.0, 1.0, -1.0);
glVertex3f(-1.0, -1.0, -1.0);
glVertex3f(-1.0, -1.0, 1.0);
glVertex3f(-1.0, 1.0, 1.0);
glVertex3f(-1.0, 1.0, -1.0);
glEnd();
}
/****************************
* GL selection (currently defunct)
***************************/
// Selection helper, currently defunct.
void glaSelect(int x, int y)
{
int i;
GLuint namebuf[64] = {0};
GLint hits, view[4];
GLfloat projmat[16];
// Account for inverse Y coordinate
glGetIntegerv(GL_VIEWPORT, view);
y = view[3] - y;
glSelectBuffer(64, namebuf);
glRenderMode(GL_SELECT);
// Reset name stack
glInitNames();
glPushName(0);
// Restrict projection matrix to selection area
glGetFloatv(GL_PROJECTION_MATRIX, projmat);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPickMatrix(x, y, 1.0, 1.0, view);
glMultMatrixf(projmat);
// Redraw points to fill selection buffer
glMatrixMode(GL_MODELVIEW);
//glutSwapBuffers();
//drawPoints();
// Reset projection
glMatrixMode(GL_PROJECTION);
glPopMatrix();
hits = glRenderMode(GL_RENDER);
for (i = 0; i < hits; i++)
// Do something with the namebuf element here
break;
glMatrixMode(GL_MODELVIEW);
}
|