Skip to content

Commit 5147bb8

Browse files
committed
Adapt to GLSL 3.3
1 parent b40a6a3 commit 5147bb8

10 files changed

+40
-38
lines changed

glutwrapper.cpp

+11-9
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,23 @@ GLUTwrapper::GLUTwrapper ( EventHandlerBase *h )
165165

166166
int a = h->getArgc();
167167
glutInit(&a,h->getArgv());
168+
glutInitContextVersion (3, 3);
169+
glutInitContextFlags (GLUT_CORE_PROFILE | GLUT_DEBUG);
168170

169171
glutInitWindowSize(h->getWindowWidth(),h->getWindowHeight());
170172
glutInitWindowPosition(10,10);
171173
glutInitDisplayMode(h->getWindowMode());
172174
windowID = glutCreateWindow("A window");
173175

174-
// initialize glew and check for OpenGL 4.0 support
175-
glewInit();
176-
if (glewIsSupported("GL_VERSION_4_0"))
177-
cout << "Ready for OpenGL 4.0" << endl;
178-
else
179-
{
180-
cerr << "OpenGL 4.0 not supported" << endl;
181-
exit(1);
182-
}
176+
glewExperimental=GL_TRUE;
177+
GLenum err=glewInit();
178+
if(err!=GLEW_OK)
179+
{
180+
//Problem: glewInit failed, something is seriously wrong.
181+
cout<<"glewInit failed, aborting."<<endl;
182+
exit(1);
183+
}
184+
183185

184186
handler = h;
185187

glutwrapper.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <GL/glew.h>
33
#include <GL/gl.h>
44
#include <GL/glext.h>
5-
#include <GL/glut.h>
5+
#include <GL/freeglut.h>
66
#include <cstdlib>
77
#include <iostream>
88
#include <handlerbase.h>

handlerbase.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <GL/glew.h>
33
#include <GL/gl.h>
44
#include <GL/glext.h>
5-
#include <GL/glut.h>
5+
#include <GL/freeglut.h>
66

77
#include <iostream>
88
#include <cstdlib>

menucreator.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#include <GL/glew.h>
3-
#include <GL/glut.h>
3+
#include <GL/freeglut.h>
44
#include <menucreator.h>
55
#include <cstdlib>
66
#include <iostream>
@@ -121,7 +121,7 @@ int MenuCreator::endMenu()
121121
case ENTRY:
122122
glutAddMenuEntry((*i).first.first.c_str(),(*i).second.first);
123123
HandlerFunc[(*i).second.first] = (*i).second.second;
124-
124+
125125
break;
126126
case COLLAPSEDSUB:
127127
glutAddSubMenu((*i).first.first.c_str(),(*i).second.first);

shaders/frgPhong.glsl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#version 420
1+
#version 330
2+
#extension GL_ARB_shading_language_420pack: enable
23

34
// this is a standard Phong fragment shader...
45

shaders/frgSquare.glsl

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#version 420
1+
#version 330
2+
#extension GL_ARB_shading_language_420pack: enable
23

34
// output fragment color
45
out vec3 color;

shaders/vtxPhong.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 420
1+
#version 330
22

33
// this is a standard Phong vertex shader...
44

shaders/vtxSquare.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#version 420
1+
#version 330
22

33
// locations of vertices of the square, in range -1..1 (see C++ code)
44
layout(location=0) in vec2 coord;

trackballhandler.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <GL/glew.h>
33
#include <GL/gl.h>
44
#include <GL/glext.h>
5-
#include <GL/glut.h>
5+
#include <GL/freeglut.h>
66

77
#include <iostream>
88
#include <cstdlib>

viewer.cpp

+18-20
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <GL/glew.h>
33
#include <GL/gl.h>
44
#include <GL/glext.h>
5-
#include <GL/glut.h>
5+
#include <GL/freeglut.h>
66

77
#include <iostream>
88
#include <cstdlib>
@@ -41,7 +41,7 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
4141

4242
// NEW TYPES ALERT!
4343
// 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
4545
// standard rendering target, i.e. the framebuffer associated with your OpenGL window.
4646
static Framebuffer *fb;
4747
static Texture *tcol,*tdepth;
@@ -62,9 +62,9 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
6262
// change resolution of the framebuffer to be rendered to to 64x64
6363
static void res_64()
6464
{
65-
delete_fb(); // delete the current framebuffer
65+
delete_fb(); // delete the current framebuffer
6666
// (the method is implemented just below this section)
67-
texsize = 64; // change the size
67+
texsize = 64; // change the size
6868
make_fb(); // re-build the framebuffer, with of the requested size
6969
// (the method is implemented just below this section)
7070
}
@@ -145,12 +145,12 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
145145
fb->attachColor(tcol);
146146
fb->attachDepth(tdepth);
147147

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
150150
// 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
152152
// 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.
154154
fb->printLog();
155155
}
156156

@@ -169,7 +169,7 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
169169
static void timerFunc( int )
170170
{
171171
// move light source (if it is supposed to move)
172-
if (lightMoving)
172+
if (lightMoving)
173173
lloc = vec3(rotate(mat4(),.75f,vec3(0.0,0.0,1.0))*vec4(lloc,1.0));
174174

175175
glutTimerFunc(30,timerFunc,0); // come here again in 30ms
@@ -188,15 +188,14 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
188188
vaSquare = new VertexArray;
189189
vaSquare->attachAttribute(0,qbuf);
190190

191-
192191
// we'll use the familiar Phong program and a program to apply texture to the square
193192

194193
pgmPhong = createProgram(ShaderFile(Vert,"shaders/vtxPhong.glsl"),
195194
ShaderFile(Frag,"shaders/frgPhong.glsl"));
196195
pgmSquare = createProgram(ShaderFile(Vert,"shaders/vtxSquare.glsl"),
197196
ShaderFile(Frag,"shaders/frgSquare.glsl"));
198197

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
200199
// vertex locations, normals and triangle table (to be used as the index buffer)
201200

202201
Mesh M(getArgv()[1]);
@@ -211,7 +210,7 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
211210

212211
vaPhong = new VertexArray();
213212
vaPhong->attachAttribute(0,vloc);
214-
vaPhong->attachAttribute(1,vnormal);
213+
vaPhong->attachAttribute(1,vnormal);
215214

216215
// want to use culling, depth test and white background
217216

@@ -253,14 +252,14 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
253252
// clear the WINDOW
254253

255254
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
256-
255+
257256
// set up culling...
258257

259258
if (reor>0)
260259
glCullFace(GL_BACK);
261260
else
262261
glCullFace(GL_FRONT);
263-
262+
264263
// modelview and projection matrices are as always...
265264

266265
mat4 ModelView = translate(mat4(),vec3(0.0f,0.0f,-20.0f)) *
@@ -285,12 +284,12 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
285284

286285
// Here, we render into our frame buffer.
287286

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
289288
// the rendering target.
290289

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)
294293
// --> [0,texsize]x[0,texsize]
295294

296295
pgmPhong->on(); // turn the Phong program on
@@ -303,7 +302,6 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
303302

304303
fb->off(); // turn the framebuffer off; currently active framebuffer = our window
305304

306-
307305
// Here, we render the texture into the GLUT window
308306

309307
glCullFace(GL_BACK); // the square is oriented CCW
@@ -317,7 +315,7 @@ class ViewerEventHandlers : public TrackballHandler, public MenuCreator {
317315

318316
t->bind(1); // bind the texture to attachment point #1; use small numbers as TAP IDs!
319317

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
321319
// updated; we need scaling [-1,1]^2 ---> [0,width of window] x [0, height of window]
322320
glViewport(0,0,getWindowWidth(),getWindowHeight());
323321

0 commit comments

Comments
 (0)