2
2
#include < GL/glew.h>
3
3
#include < GL/gl.h>
4
4
#include < GL/glext.h>
5
- #include < GL/glut .h>
5
+ #include < GL/freeglut .h>
6
6
7
7
#include < iostream>
8
8
#include < cstdlib>
@@ -41,7 +41,7 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
41
41
42
42
// NEW TYPES ALERT!
43
43
// Texture: a wrapper for a texture object in OpenGL
44
- // Framebuffer: an object, usually with some textures attached, that can replace the
44
+ // Framebuffer: an object, usually with some textures attached, that can replace the
45
45
// standard rendering target, i.e. the framebuffer associated with your OpenGL window.
46
46
static Framebuffer *fb;
47
47
static Texture *tcol,*tdepth;
@@ -62,9 +62,9 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
62
62
// change resolution of the framebuffer to be rendered to to 64x64
63
63
static void res_64 ()
64
64
{
65
- delete_fb (); // delete the current framebuffer
65
+ delete_fb (); // delete the current framebuffer
66
66
// (the method is implemented just below this section)
67
- texsize = 64 ; // change the size
67
+ texsize = 64 ; // change the size
68
68
make_fb (); // re-build the framebuffer, with of the requested size
69
69
// (the method is implemented just below this section)
70
70
}
@@ -145,12 +145,12 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
145
145
fb->attachColor (tcol);
146
146
fb->attachDepth (tdepth);
147
147
148
- // Print out the status of the frame buffer. In particular, if the textures are of
149
- // wrong type/format, the framebuffer will not be `complete', i.e. suitable for
148
+ // Print out the status of the frame buffer. In particular, if the textures are of
149
+ // wrong type/format, the framebuffer will not be `complete', i.e. suitable for
150
150
// rendering into it. If this is the case, you should get a message complaining
151
- // about it in the terminal. For example, it is wrong to use a color texture as
151
+ // about it in the terminal. For example, it is wrong to use a color texture as
152
152
// the depth texture or the other way around. The restrictions are mostly common
153
- // sense. See specification for more details.
153
+ // sense. See specification for more details.
154
154
fb->printLog ();
155
155
}
156
156
@@ -169,7 +169,7 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
169
169
static void timerFunc ( int )
170
170
{
171
171
// move light source (if it is supposed to move)
172
- if (lightMoving)
172
+ if (lightMoving)
173
173
lloc = vec3 (rotate (mat4 (),.75f ,vec3 (0.0 ,0.0 ,1.0 ))*vec4 (lloc,1.0 ));
174
174
175
175
glutTimerFunc (30 ,timerFunc,0 ); // come here again in 30ms
@@ -188,15 +188,14 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
188
188
vaSquare = new VertexArray;
189
189
vaSquare->attachAttribute (0 ,qbuf);
190
190
191
-
192
191
// we'll use the familiar Phong program and a program to apply texture to the square
193
192
194
193
pgmPhong = createProgram (ShaderFile (Vert," shaders/vtxPhong.glsl" ),
195
194
ShaderFile (Frag," shaders/frgPhong.glsl" ));
196
195
pgmSquare = createProgram (ShaderFile (Vert," shaders/vtxSquare.glsl" ),
197
196
ShaderFile (Frag," shaders/frgSquare.glsl" ));
198
197
199
- // this should look familiar: use the Mesh class to read mesh and get
198
+ // this should look familiar: use the Mesh class to read mesh and get
200
199
// vertex locations, normals and triangle table (to be used as the index buffer)
201
200
202
201
Mesh M (getArgv ()[1 ]);
@@ -211,7 +210,7 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
211
210
212
211
vaPhong = new VertexArray ();
213
212
vaPhong->attachAttribute (0 ,vloc);
214
- vaPhong->attachAttribute (1 ,vnormal);
213
+ vaPhong->attachAttribute (1 ,vnormal);
215
214
216
215
// want to use culling, depth test and white background
217
216
@@ -253,14 +252,14 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
253
252
// clear the WINDOW
254
253
255
254
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
256
-
255
+
257
256
// set up culling...
258
257
259
258
if (reor>0 )
260
259
glCullFace (GL_BACK);
261
260
else
262
261
glCullFace (GL_FRONT);
263
-
262
+
264
263
// modelview and projection matrices are as always...
265
264
266
265
mat4 ModelView = translate (mat4 (),vec3 (0 .0f ,0 .0f ,-20 .0f )) *
@@ -285,12 +284,12 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
285
284
286
285
// Here, we render into our frame buffer.
287
286
288
- fb->on (); // Turn on the framebuffer; Until it is turned off, the framebuffer will be used as
287
+ fb->on (); // Turn on the framebuffer; Until it is turned off, the framebuffer will be used as
289
288
// the rendering target.
290
289
291
- glViewport (0 ,0 ,texsize,texsize); // The framebuffer has a different resolution than the
292
- // window. This changes the viewport transformation to
293
- // scaling [-1,1]x[-1,1] (normalized coordinates, after modelview and projection transformations)
290
+ glViewport (0 ,0 ,texsize,texsize); // The framebuffer has a different resolution than the
291
+ // window. This changes the viewport transformation to
292
+ // scaling [-1,1]x[-1,1] (normalized coordinates, after modelview and projection transformations)
294
293
// --> [0,texsize]x[0,texsize]
295
294
296
295
pgmPhong->on (); // turn the Phong program on
@@ -303,7 +302,6 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
303
302
304
303
fb->off (); // turn the framebuffer off; currently active framebuffer = our window
305
304
306
-
307
305
// Here, we render the texture into the GLUT window
308
306
309
307
glCullFace (GL_BACK); // the square is oriented CCW
@@ -317,7 +315,7 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
317
315
318
316
t->bind (1 ); // bind the texture to attachment point #1; use small numbers as TAP IDs!
319
317
320
- // resolution of the framebuffer has changes, so the viewport transform needs to be
318
+ // resolution of the framebuffer has changes, so the viewport transform needs to be
321
319
// updated; we need scaling [-1,1]^2 ---> [0,width of window] x [0, height of window]
322
320
glViewport (0 ,0 ,getWindowWidth (),getWindowHeight ());
323
321
0 commit comments