Mercurial > hg > forks > gldragon
comparison gldragon.cpp @ 55:bf73a2a70ec7
Add OpenGL error checking.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 06 Dec 2019 23:29:26 +0200 |
parents | 73fa5fb437a0 |
children | 3f635b7ea2cf |
comparison
equal
deleted
inserted
replaced
54:73fa5fb437a0 | 55:bf73a2a70ec7 |
---|---|
37 SDL_GLContext dmGLContext = NULL; | 37 SDL_GLContext dmGLContext = NULL; |
38 | 38 |
39 | 39 |
40 /* Helpers | 40 /* Helpers |
41 */ | 41 */ |
42 bool dmGLCheckErrors(void) | |
43 { | |
44 bool ok = true; | |
45 GLenum err; | |
46 while ((err = glGetError()) != GL_NO_ERROR) | |
47 { | |
48 dmError("OpenGL error code: 0x%x (%d)\n", err); | |
49 ok = false; | |
50 } | |
51 return ok; | |
52 } | |
53 | |
54 | |
42 #ifdef GL_GLEXT_PROTOTYPES | 55 #ifdef GL_GLEXT_PROTOTYPES |
43 #define DM_GLEXT_INIT(extproctype, extprocname) /* stub */ | 56 #define DM_GLEXT_INIT(extproctype, extprocname) /* stub */ |
44 #else | 57 #else |
45 #define DM_GLEXT_INIT(extproctype, extprocname) extproctype extprocname = NULL; | 58 #define DM_GLEXT_INIT(extproctype, extprocname) extproctype extprocname = NULL; |
46 #include "dmglexts.h" | 59 #include "dmglexts.h" |
199 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR)); | 212 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR)); |
200 dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER)); | 213 dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER)); |
201 dmMsg("GL_VERSION : %s\n", glGetString(GL_VERSION)); | 214 dmMsg("GL_VERSION : %s\n", glGetString(GL_VERSION)); |
202 dmMsg("VSync mode : %s\n", msg.c_str()); | 215 dmMsg("VSync mode : %s\n", msg.c_str()); |
203 | 216 |
217 if (!dmGLCheckErrors()) | |
218 return false; | |
219 | |
204 // Setup the window and view port | 220 // Setup the window and view port |
205 glViewport(0, 0, width, height); | 221 glViewport(0, 0, width, height); |
206 | 222 |
207 glMatrixMode(GL_PROJECTION); | 223 glMatrixMode(GL_PROJECTION); |
208 glLoadIdentity(); | 224 glLoadIdentity(); |
221 // Enable the depth buffer | 237 // Enable the depth buffer |
222 glEnable(GL_DEPTH_TEST); | 238 glEnable(GL_DEPTH_TEST); |
223 | 239 |
224 // Enable normal rescaling | 240 // Enable normal rescaling |
225 glEnable(GL_RESCALE_NORMAL); | 241 glEnable(GL_RESCALE_NORMAL); |
226 | |
227 | 242 |
228 // Setup depth buffer | 243 // Setup depth buffer |
229 glClearDepth(1.0f); | 244 glClearDepth(1.0f); |
230 | 245 |
231 // Set the depth buffer function | 246 // Set the depth buffer function |
236 glEnableClientState(GL_NORMAL_ARRAY); | 251 glEnableClientState(GL_NORMAL_ARRAY); |
237 | 252 |
238 // Set correct perspective correction | 253 // Set correct perspective correction |
239 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | 254 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
240 | 255 |
241 return true; | 256 return dmGLCheckErrors(); |
242 } | 257 } |
243 | 258 |
244 | 259 |
245 void dmDrawModel(const DMSimpleScene &scene, const DMModel &model) | 260 void dmDrawModel(const DMSimpleScene &scene, const DMModel &model) |
246 { | 261 { |
423 } | 438 } |
424 else | 439 else |
425 if (opt[0] == '-') | 440 if (opt[0] == '-') |
426 opt++; | 441 opt++; |
427 | 442 |
428 if (opt[0] == 'g') | |
429 optUseShaders = true; | |
430 else | |
431 switch (opt[0]) | 443 switch (opt[0]) |
432 { | 444 { |
445 case 'g': | |
446 optUseShaders = true; | |
447 break; | |
448 | |
433 case 'w': | 449 case 'w': |
434 case 'h': | 450 case 'h': |
435 case 'm': | 451 case 'm': |
436 case 'v': | 452 case 'v': |
437 if (opt[1] == 0) | 453 if (opt[1] == 0) |
599 SDL_GL_SwapWindow(dmWindow); | 615 SDL_GL_SwapWindow(dmWindow); |
600 | 616 |
601 // Rotate for 2 degrees | 617 // Rotate for 2 degrees |
602 glRotatef(2.0f, 0, 1, 0); | 618 glRotatef(2.0f, 0, 1, 0); |
603 | 619 |
620 // Check for errors | |
621 dmGLCheckErrors(); | |
622 | |
604 // Return true if a full rotation was done | 623 // Return true if a full rotation was done |
605 totalFrames++; | 624 totalFrames++; |
606 if (cycleFrames++ == SET_FRAMES) | 625 if (cycleFrames++ == SET_FRAMES) |
607 { | 626 { |
608 // Reset cycleFrames | 627 // Reset cycleFrames |