Mercurial > hg > forks > gldragon
comparison glxdragon.cpp @ 10:c6c419861101
Use SDL_GetTicks() instead of std::clock().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 28 Oct 2019 12:59:18 +0200 |
parents | 628c42e94149 |
children | 89dc8caeff41 |
comparison
equal
deleted
inserted
replaced
9:87cb16492d91 | 10:c6c419861101 |
---|---|
36 #include <iostream> | 36 #include <iostream> |
37 #include <fstream> | 37 #include <fstream> |
38 #include <string> | 38 #include <string> |
39 #include <vector> | 39 #include <vector> |
40 #include <cstdio> | 40 #include <cstdio> |
41 #include <ctime> | |
42 | 41 |
43 | 42 |
44 #define SET_FRAMES (180 * 2) | 43 #define SET_FRAMES (180 * 2) |
45 | 44 |
46 | 45 |
291 | 290 |
292 int main(int argc, char *argv[]) | 291 int main(int argc, char *argv[]) |
293 { | 292 { |
294 struct Mesh dragonMesh; | 293 struct Mesh dragonMesh; |
295 std::string dragonVS, dragonFS; | 294 std::string dragonVS, dragonFS; |
296 std::clock_t startTime; | |
297 bool exitFlag = false, optShowHelp = false; | 295 bool exitFlag = false, optShowHelp = false; |
298 int nframes = 0; | 296 int startTime, nframes = 0; |
299 | 297 |
300 // Check commandline argument for enabling shaders | 298 // Check commandline argument for enabling shaders |
301 | 299 |
302 for (int narg = 1; narg < argc; narg++) | 300 for (int narg = 1; narg < argc; narg++) |
303 { | 301 { |
371 // Define the camera | 369 // Define the camera |
372 gluLookAt(0, 0.12, 0.24, 0, 0.12, 0, 0, 1, 0); | 370 gluLookAt(0, 0.12, 0.24, 0, 0.12, 0, 0, 1, 0); |
373 | 371 |
374 | 372 |
375 // Main loop starts | 373 // Main loop starts |
376 startTime = std::clock(); | 374 startTime = SDL_GetTicks(); |
377 | 375 |
378 while (!exitFlag) | 376 while (!exitFlag) |
379 { | 377 { |
380 SDL_Event event; | 378 SDL_Event event; |
381 | 379 |
411 { | 409 { |
412 // Reset nframes | 410 // Reset nframes |
413 nframes = 0; | 411 nframes = 0; |
414 | 412 |
415 // Get the time it took to render a full turn | 413 // Get the time it took to render a full turn |
416 double time = (double(std::clock() - startTime) * 1000.0f) / CLOCKS_PER_SEC; | 414 double time = SDL_GetTicks() - startTime; |
415 | |
416 // Restart the timer | |
417 startTime = SDL_GetTicks(); | |
417 | 418 |
418 // Print the current frames per second | 419 // Print the current frames per second |
419 printf("%.1lf ms for %d frames = %.1lf FPS\n", | 420 printf("%.1lf ms for %d frames = %.1lf FPS\n", |
420 time, SET_FRAMES, (SET_FRAMES * 1000.0f) / time); | 421 time, SET_FRAMES, (SET_FRAMES * 1000.0f) / time); |
421 | 422 |
422 // Restart the timer | |
423 startTime = std::clock(); | |
424 } | 423 } |
425 } | 424 } |
426 | 425 |
427 exit: | 426 exit: |
428 if (dmGLContext != NULL) | 427 if (dmGLContext != NULL) |