comparison gldragon.cpp @ 47:9909014498f0

Add helper functions dmError() and dmMsg() and use them.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 05 Dec 2019 23:52:45 +0200
parents 0c75c5f5c6b6
children 0ae1ff609626
comparison
equal deleted inserted replaced
46:0c75c5f5c6b6 47:9909014498f0
52 void * dmGLExtTry(const std::string &name) 52 void * dmGLExtTry(const std::string &name)
53 { 53 {
54 bool res = SDL_GL_ExtensionSupported(name.c_str()); 54 bool res = SDL_GL_ExtensionSupported(name.c_str());
55 void *ptr = SDL_GL_GetProcAddress(name.c_str()); 55 void *ptr = SDL_GL_GetProcAddress(name.c_str());
56 56
57 printf(" - Checking '%s' : %s : %p\n", 57 dmMsg(" - Checking '%s' : %s : %p\n",
58 name.c_str(), 58 name.c_str(),
59 res ? "YES" : "no", 59 res ? "YES" : "no",
60 ptr); 60 ptr);
61 61
62 res = true; 62 res = true;
108 std::string msg; 108 std::string msg;
109 109
110 // Attempt to initialize libSDL 110 // Attempt to initialize libSDL
111 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS) != 0) 111 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS) != 0)
112 { 112 {
113 printf("ERROR: Unable to initialize SDL: %s\n", 113 dmError("Unable to initialize SDL: %s\n",
114 SDL_GetError()); 114 SDL_GetError());
115 return false; 115 return false;
116 } 116 }
117 117
118 // Set GL attributes 118 // Set GL attributes
133 if ((dmWindow = SDL_CreateWindow(title, 133 if ((dmWindow = SDL_CreateWindow(title,
134 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 134 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
135 width, height, 135 width, height,
136 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)) == NULL) 136 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)) == NULL)
137 { 137 {
138 printf("ERROR: Could not create SDL window: %s", 138 dmError("Could not create SDL window: %s",
139 SDL_GetError()); 139 SDL_GetError());
140 return false; 140 return false;
141 } 141 }
142 142
143 if ((dmGLContext = SDL_GL_CreateContext(dmWindow)) == NULL) 143 if ((dmGLContext = SDL_GL_CreateContext(dmWindow)) == NULL)
144 { 144 {
145 printf("ERROR: Unable to create SDL OpenGL context: %s\n", 145 dmError("Unable to create SDL OpenGL context: %s\n",
146 SDL_GetError()); 146 SDL_GetError());
147 return false; 147 return false;
148 } 148 }
149 149
150 // Check if we want to attempt to use vsync 150 // Check if we want to attempt to use vsync
176 break; 176 break;
177 } 177 }
178 178
179 if (ret != 0) 179 if (ret != 0)
180 { 180 {
181 printf("ERROR: Could not set vsync mode to %s.\n", 181 dmError("Could not set vsync mode to %s.\n",
182 msg.c_str()); 182 msg.c_str());
183 return false; 183 return false;
184 } 184 }
185 185
186 // Get/initialize OpenGL extension function pointers 186 // Get/initialize OpenGL extension function pointers
187 if (optUseShaders && !dmInitGLExtensions()) 187 if (optUseShaders && !dmInitGLExtensions())
188 return false; 188 return false;
189 189
190 // Dump some information 190 // Dump some information
191 printf( 191 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR));
192 "GL_VENDOR : %s\n" 192 dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER));
193 "GL_RENDERER : %s\n" 193 dmMsg("GL_VERSION : %s\n", glGetString(GL_VERSION));
194 "GL_VERSION : %s\n" 194 dmMsg("VSync mode : %s\n", msg.c_str());
195 "VSync mode : %s\n",
196 glGetString(GL_VENDOR),
197 glGetString(GL_RENDERER),
198 glGetString(GL_VERSION),
199 msg.c_str());
200 195
201 // Setup the window and view port 196 // Setup the window and view port
202 glViewport(0, 0, width, height); 197 glViewport(0, 0, width, height);
203 198
204 glMatrixMode(GL_PROJECTION); 199 glMatrixMode(GL_PROJECTION);
358 353
359 if (bufLen > 0) 354 if (bufLen > 0)
360 { 355 {
361 char *buf = new char[bufLen]; 356 char *buf = new char[bufLen];
362 glGetShaderInfoLog(shader, bufLen, NULL, buf); 357 glGetShaderInfoLog(shader, bufLen, NULL, buf);
363 printf("ERROR: Shader compliation error:\n%s\n", 358 dmError("Shader compliation error:\n%s\n",
364 buf); 359 buf);
365 delete buf; 360 delete buf;
366 } 361 }
367 else 362 else
368 { 363 {
369 printf("ERROR: Shader compilation error occured, but no error information got.\n"); 364 dmError("Shader compilation error occured, but no error information got.\n");
370 } 365 }
371 return false; 366 return false;
372 } 367 }
373 } 368 }
374 369
451 } 446 }
452 else 447 else
453 { 448 {
454 if (optSetInputFilename) 449 if (optSetInputFilename)
455 { 450 {
456 printf("ERROR: Please specify only one scene file.\n"); 451 dmError("Please specify only one scene file.\n");
457 goto exit; 452 goto exit;
458 } 453 }
459 454
460 optSetInputFilename = true; 455 optSetInputFilename = true;
461 optInputFilename = std::string(arg); 456 optInputFilename = std::string(arg);
462 if (optInputFilename.empty()) 457 if (optInputFilename.empty())
463 { 458 {
464 printf("ERROR: Invalid input filename.\n"); 459 dmError("Invalid input filename.\n");
465 goto exit; 460 goto exit;
466 } 461 }
467 462
468 } 463 }
469 } 464 }
489 goto exit; 484 goto exit;
490 } 485 }
491 486
492 if (optWidth < 100 || optWidth > 8192 || optHeight < 100 || optHeight > 8192) 487 if (optWidth < 100 || optWidth > 8192 || optHeight < 100 || optHeight > 8192)
493 { 488 {
494 printf("ERROR: Invalid window width or height (%d x %d).\n", 489 dmError("Invalid window width or height (%d x %d).\n",
495 optWidth, optHeight); 490 optWidth, optHeight);
496 goto exit; 491 goto exit;
497 } 492 }
498 493
499 // Load the scene 494 // Load the scene
500 if (!scene.loadInfo(optInputFilename)) 495 if (!scene.loadInfo(optInputFilename))
501 goto exit; 496 goto exit;
502 497
503 if (scene.models.size() == 0) 498 if (scene.models.size() == 0)
504 { 499 {
505 printf("ERROR: Scenefile '%s' contains no models.\n", 500 dmError("Scenefile '%s' contains no models.\n",
506 optInputFilename.c_str()); 501 optInputFilename.c_str());
507 goto exit; 502 goto exit;
508 } 503 }
509 504
510 // Define a default light if none defined in scene file 505 // Define a default light if none defined in scene file
512 { 507 {
513 DMLight light; // Default light 508 DMLight light; // Default light
514 scene.lights.push_back(light); 509 scene.lights.push_back(light);
515 } 510 }
516 511
517 printf("INFO: Loading %ld model(s) ..\n", 512 dmMsg("Loading %ld model(s) ..\n",
518 scene.models.size()); 513 scene.models.size());
519 514
520 basePath = dmGetPath(optInputFilename); 515 basePath = dmGetPath(optInputFilename);
521 printf("INFO: Model base path '%s'\n", basePath.c_str()); 516 dmMsg("Scene base path '%s'\n", basePath.c_str());
522 517
523 for (DMModel &model : scene.models) 518 for (DMModel &model : scene.models)
524 { 519 {
525 if (!model.loadFromPLY(basePath + model.modelFile)) 520 if (!model.loadFromPLY(basePath + model.modelFile))
526 goto exit; 521 goto exit;