annotate gldragon.cpp @ 98:44e3656f4c83

Fix help to display correct range for frame numbers.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 25 May 2021 09:46:06 +0300
parents 05677852afd5
children a3486ce56148
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
1 //
22
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
2 // GLDragon - OpenGL PLY model viewer / simple benchmark
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
3 // Programmed and designed by Matti 'ccr' Hämäläinen <ccr@tnsp.org>
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
4 // (C) Copyright 2019 Tecnic Software productions (TNSP)
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
5 //
22
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
6 // See file "COPYING" for license information.
0
3d74a9dd96e4 Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff changeset
7 //
22
03b86b9c2f29 Add copyright blurbs and licenses.
Matti Hamalainen <ccr@tnsp.org>
parents: 21
diff changeset
8 // Originally based on 'glxdragon' Copyright (c) 2009, Thomas Trummer
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
9 //
0
3d74a9dd96e4 Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff changeset
10 #include <SDL.h>
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
11 #include "dmutil.h"
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
12 #include "dmglrender.h"
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
13 #include "dmply.h"
0
3d74a9dd96e4 Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff changeset
14
16
c134a186912f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 15
diff changeset
15
11
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
16 /* Default settings etc. constants
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
17 */
18
b1e75c65016d Check for "too large" shader files.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
18 #define SET_DEF_WIDTH 1280
b1e75c65016d Check for "too large" shader files.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
19 #define SET_DEF_HEIGHT 960
97
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
20 #define SET_FRAMES (360)
18
b1e75c65016d Check for "too large" shader files.
Matti Hamalainen <ccr@tnsp.org>
parents: 17
diff changeset
21 #define SET_MAX_SHADER_SIZE (128 * 1024)
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
22
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
23
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
24 /* Helpers
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
25 */
64
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
26 bool dmInitSDL(DMSimpleRenderer &renderer,
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
27 const int width, const int height,
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
28 const int vsyncMode,
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
29 const char *title)
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
30 {
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
31 int ret;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
32 std::string msg;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
33
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
34 // Attempt to initialize libSDL
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
35 if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_EVENTS) != 0)
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
36 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
37 dmError("Unable to initialize SDL: %s\n",
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
38 SDL_GetError());
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
39 return false;
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
40 }
0
3d74a9dd96e4 Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff changeset
41
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
42 // Part 1 of initialization
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
43 if (!renderer.initRenderer1(title, width, height,
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
44 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
82
91a2868260bf Disable window resizability for now, as we don't actually support it.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
45 SDL_WINDOW_SHOWN// | SDL_WINDOW_RESIZABLE
91a2868260bf Disable window resizability for now, as we don't actually support it.
Matti Hamalainen <ccr@tnsp.org>
parents: 81
diff changeset
46 ))
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
47 return false;
44
d93b1c2690f8 Set SDL_GL_* attributes after initializing SDL, but before creating window or OpenGL context.
Matti Hamalainen <ccr@tnsp.org>
parents: 42
diff changeset
48
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
49 // Check if we want to attempt to use vsync
64
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
50 switch (vsyncMode)
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
51 {
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
52 case 3:
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
53 ret = SDL_GL_SetSwapInterval(-1);
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
54 msg = "adaptive vsync";
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
55 break;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
56
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
57 case 2:
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
58 ret = SDL_GL_SetSwapInterval(1);
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
59 msg = "synchronized (vsync)";
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
60 break;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
61
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
62 case 1:
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
63 ret = SDL_GL_SetSwapInterval(0);
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
64 msg = "immediate (no vsync)";
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
65 break;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
66
38
372fa249ce26 Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
67 case 0:
372fa249ce26 Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
68 msg = "vsync handling disabled";
372fa249ce26 Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
69 ret = 0;
372fa249ce26 Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
70 break;
372fa249ce26 Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents: 37
diff changeset
71
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
72 default:
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
73 ret = -1;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
74 msg = "INVALID VSYNC MODE";
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
75 break;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
76 }
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
77
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
78 if (ret != 0)
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
79 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
80 dmError("Could not set vsync mode to %s.\n",
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
81 msg.c_str());
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
82 return false;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
83 }
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
84
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
85 // Part 3 of initialization
63
d6ffc59bb84d Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents: 62
diff changeset
86 if (!renderer.initRenderer2())
55
bf73a2a70ec7 Add OpenGL error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
87 return false;
bf73a2a70ec7 Add OpenGL error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
88
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
89 dmMsg("VSync mode : %s\n", msg.c_str());
0
3d74a9dd96e4 Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff changeset
90
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
91 return true;
25
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
92 }
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
93
2403030a0352 "Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents: 24
diff changeset
94
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
95 int main(int argc, char *argv[])
0
3d74a9dd96e4 Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff changeset
96 {
89
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
97 int frameDeltas[SET_FRAMES + 1];
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
98
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
99 bool
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
100 exitFlag = false,
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
101 pauseFlag = false,
94
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
102 manualFlag = false,
97
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
103 manualChanged = false,
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
104 optShowHelp = false,
64
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
105 optSetInputFilename = false,
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
106 optUseShaders = false;
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
107
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
108 int optWidth = SET_DEF_WIDTH,
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
109 optHeight = SET_DEF_HEIGHT,
88
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
110 optVSyncMode = 1,
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
111 optPauseFrame = -1;
64
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
112
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
113 std::string optInputFilename = "dragon.scene", basePath;
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
114 DMGLSimpleRenderer renderer;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
115 DMSimpleScene scene;
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
116 int cycleTime = 0,
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
117 cycleFrames = 0,
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
118 totalTime = 0,
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
119 totalFrames = 0;
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
120
89
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
121 memset(&frameDeltas, 0, sizeof(frameDeltas));
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
122
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
123 // Check commandline argument for enabling shaders
7
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
124 for (int narg = 1; narg < argc; narg++)
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
125 {
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
126 char *arg = argv[narg];
11
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
127 if (arg[0] == '-')
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
128 {
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
129 char *opt = arg + 1;
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
130
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
131 if ((opt[0] == '-' && opt[1] == 'h' && opt[2] == 'e') ||
12
52a586c344f4 Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
132 opt[0] == '?' || (opt[0] == '-' && opt[1] == '?'))
11
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
133 {
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
134 optShowHelp = true;
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
135 break;
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
136 }
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
137 else
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
138 if (opt[0] == '-')
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
139 opt++;
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
140
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
141 switch (opt[0])
12
52a586c344f4 Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
142 {
55
bf73a2a70ec7 Add OpenGL error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
143 case 'g':
bf73a2a70ec7 Add OpenGL error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
144 optUseShaders = true;
bf73a2a70ec7 Add OpenGL error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
145 break;
bf73a2a70ec7 Add OpenGL error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
146
67
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
147 case 's':
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
148 case 'm':
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
149 case 'v':
88
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
150 case 'p':
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
151 {
67
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
152 std::string marg;
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
153 if (opt[1] == 0)
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
154 {
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
155 if (narg < argc)
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
156 marg = std::string(argv[++narg]);
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
157 else
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
158 {
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
159 printf("Option '%s' requires an argument.\n", opt);
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
160 goto exit;
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
161 }
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
162 }
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
163 else
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
164 marg = std::string(opt + 1);
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
165
67
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
166 switch (opt[0])
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
167 {
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
168 case 's':
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
169 {
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
170 std::vector<std::string> mtokens = dmStrSplit(marg, "xX:");
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
171 if (mtokens.size() != 2)
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
172 {
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
173 printf("Option expects argument of format <width>x<height> in pixels.\n"
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
174 "For example: -s 640x480\n");
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
175 goto exit;
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
176 }
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
177
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
178 optWidth = std::stoi(mtokens[0], 0, 0);
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
179 optHeight = std::stoi(mtokens[1], 0, 0);
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
180 }
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
181 break;
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
182
88
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
183 case 'v':
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
184 optVSyncMode = std::stoi(marg, 0, 0);
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
185 break;
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
186
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
187 case 'p':
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
188 optPauseFrame = std::stoi(marg, 0, 0);
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
189 break;
67
1327ef5dc9fb Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents: 64
diff changeset
190 }
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
191 }
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
192 break;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
193
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
194 default:
58
801d4c5c0f23 Print out the full argument, not trimmed option when complaining about an unknown option argument.
Matti Hamalainen <ccr@tnsp.org>
parents: 57
diff changeset
195 printf("Unknown option '%s'.\n", arg);
12
52a586c344f4 Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
196 goto exit;
52a586c344f4 Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
197 }
11
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
198 }
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
199 else
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
200 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
201 if (optSetInputFilename)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
202 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
203 dmError("Please specify only one scene file.\n");
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
204 goto exit;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
205 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
206
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
207 optSetInputFilename = true;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
208 optInputFilename = std::string(arg);
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
209 if (optInputFilename.empty())
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
210 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
211 dmError("Invalid input filename.\n");
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
212 goto exit;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
213 }
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
214
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
215 }
7
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
216 }
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
217
8
628c42e94149 Clean up variable names.
Matti Hamalainen <ccr@tnsp.org>
parents: 7
diff changeset
218 if (optShowHelp)
7
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
219 {
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
220 printf(
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
221 "Usage: %s [options] [<scenefile.scene>]\n"
87
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
222 "\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
223 " -? Show this help\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
224 " -g Use GLSL shader instead of basic OpenGL lighting\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
225 " -s<w>x<h> Set window dimensions (default %d x %d)\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
226 " -v<0-3> Set vsync mode: 0 = do not attempt to set vsync mode\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
227 " (may be required for software rendering backends),\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
228 " 1 = no vsync, 2 = vsync, 3 = adaptive.\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
229 " Using vsync (2) will result in FPS being approximately\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
230 " whatever your monitor refresh rate is. The default\n"
036e9d737ba9 Help cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 82
diff changeset
231 " value is 1 (no vsync).\n"
98
44e3656f4c83 Fix help to display correct range for frame numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
232 " -p<frameN> Start and pause at cycle frame (%d .. %d).\n"
80
98e077d9d361 List the keyboard controls in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
233 "\n"
98e077d9d361 List the keyboard controls in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
234 "Keyboard controls during runtime:\n"
98e077d9d361 List the keyboard controls in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
235 " p / space Toggle pause (does not/should not affect fps measurement)\n"
98e077d9d361 List the keyboard controls in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 73
diff changeset
236 " q / esc Quit\n"
95
59195e95c080 Improve help, document arrow key controls.
Matti Hamalainen <ccr@tnsp.org>
parents: 94
diff changeset
237 " arrow keys Enter manual mode and rotate left/right\n"
11
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
238 "\n",
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
239 argv[0],
88
8b34eab13549 Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents: 87
diff changeset
240 SET_DEF_WIDTH, SET_DEF_HEIGHT,
98
44e3656f4c83 Fix help to display correct range for frame numbers.
Matti Hamalainen <ccr@tnsp.org>
parents: 97
diff changeset
241 0, SET_FRAMES - 1
11
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
242 );
89dc8caeff41 Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 10
diff changeset
243
7
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
244 goto exit;
95dd5417e7de Add simple help.
Matti Hamalainen <ccr@tnsp.org>
parents: 6
diff changeset
245 }
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
246
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
247 if (optWidth < 100 || optWidth > 8192 || optHeight < 100 || optHeight > 8192)
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
248 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
249 dmError("Invalid window width or height (%d x %d).\n",
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
250 optWidth, optHeight);
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
251 goto exit;
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
252 }
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
253
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
254 // Load the scene
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
255 if (!scene.loadInfo(optInputFilename))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
256 goto exit;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
257
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
258 if (scene.models.size() == 0)
12
52a586c344f4 Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
259 {
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
260 dmError("Scenefile '%s' contains no models.\n",
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
261 optInputFilename.c_str());
12
52a586c344f4 Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
262 goto exit;
52a586c344f4 Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
263 }
52a586c344f4 Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents: 11
diff changeset
264
31
6847715b46cd Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
265 // Define a default light if none defined in scene file
6847715b46cd Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
266 if (scene.lights.size() == 0)
6847715b46cd Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
267 {
6847715b46cd Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
268 DMLight light; // Default light
6847715b46cd Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
269 scene.lights.push_back(light);
6847715b46cd Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
270 }
6847715b46cd Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 27
diff changeset
271
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
272 dmMsg("Loading %ld model(s) ..\n",
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
273 scene.models.size());
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
274
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
275 basePath = dmGetPath(optInputFilename);
47
9909014498f0 Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents: 46
diff changeset
276 dmMsg("Scene base path '%s'\n", basePath.c_str());
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
277
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
278 for (DMModel &model : scene.models)
2
b45d8958e5a6 Cosmetic indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
279 {
70
03aa729a9e90 Refactor PLY file parsing from dmscene.* to dmply.* and some helper functions into dmutil.h
Matti Hamalainen <ccr@tnsp.org>
parents: 69
diff changeset
280 if (!dmLoadFromPLY(model, basePath + model.modelFile))
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
281 goto exit;
21
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
282
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
283 if (optUseShaders)
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
284 {
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
285 std::string
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
286 fragFile = model.fragShaderFile.empty() ? "shader.frag" : basePath + model.fragShaderFile,
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
287 vertFile = model.vertShaderFile.empty() ? "shader.vert" : basePath + model.vertShaderFile;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
288
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
289 if (!dmReadText(fragFile, model.fragShaderStr, SET_MAX_SHADER_SIZE) ||
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
290 !dmReadText(vertFile, model.vertShaderStr, SET_MAX_SHADER_SIZE))
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
291 goto exit;
1404dfcee7b8 More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents: 20
diff changeset
292 }
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
293 }
0
3d74a9dd96e4 Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff changeset
294
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
295 // Set shader usage
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
296 renderer.useShaders = optUseShaders;
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
297
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
298 // Initialize SDL + OpenGL
64
e8100c1c5d99 Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
299 if (!dmInitSDL(renderer, optWidth, optHeight, optVSyncMode, "GLDragon"))
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
300 goto exit;
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
301
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
302 // Compile shaders for scene
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
303 if (!renderer.compileSceneShaders(scene))
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
304 goto exit;
24
c1897cfc8463 Add shader compilation error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 23
diff changeset
305
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
306 // Setup lights and camera
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
307 renderer.setupLights(scene);
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
308 renderer.setupCamera(scene.camera);
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
309
93
9fee97e7c5b6 Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
310 // Check for pause frame
9fee97e7c5b6 Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
311 if (optPauseFrame >= 0)
9fee97e7c5b6 Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
312 {
9fee97e7c5b6 Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
313 cycleFrames = optPauseFrame;
9fee97e7c5b6 Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
314 pauseFlag = true;
9fee97e7c5b6 Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
315 }
9fee97e7c5b6 Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
316
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
317 // Main loop starts
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
318 while (!exitFlag)
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
319 {
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
320 SDL_Event event;
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
321 int frameStart, frameEnd, frameDelta;
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
322
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
323 // Check for quit events
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
324 while (SDL_PollEvent(&event))
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
325 switch (event.type)
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
326 {
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
327 case SDL_QUIT:
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
328 exitFlag = true;
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
329 break;
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
330
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
331 case SDL_KEYDOWN:
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
332 switch (event.key.keysym.sym)
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
333 {
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
334 case SDLK_SPACE:
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
335 case SDLK_p:
94
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
336 if (manualFlag)
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
337 pauseFlag = manualFlag = false;
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
338 else
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
339 pauseFlag = !pauseFlag;
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
340 break;
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
341
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
342 case SDLK_ESCAPE:
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
343 case SDLK_q:
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
344 exitFlag = true;
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
345 break;
94
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
346
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
347 case SDLK_RIGHT:
97
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
348 manualChanged = manualFlag = true;
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
349 if (++cycleFrames >= SET_FRAMES)
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
350 cycleFrames = 0;
94
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
351 break;
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
352
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
353 case SDLK_LEFT:
97
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
354 manualChanged = manualFlag = true;
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
355 if (--cycleFrames < 0)
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
356 cycleFrames = SET_FRAMES - 1;
94
5191f8e571d1 Add manual control mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 93
diff changeset
357 break;
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
358 }
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
359 }
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
360
92
28dd29f3a65f Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
361 // Render the frame
28dd29f3a65f Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
362 frameStart = SDL_GetTicks();
97
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
363 renderer.drawScene(scene, (float) cycleFrames / (float) SET_FRAMES);
92
28dd29f3a65f Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
364 renderer.swapWindow();
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
365 frameEnd = SDL_GetTicks();
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
366
55
bf73a2a70ec7 Add OpenGL error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
367 // Check for errors
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
368 renderer.checkErrors();
55
bf73a2a70ec7 Add OpenGL error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 54
diff changeset
369
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
370 frameDelta = frameEnd - frameStart;
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
371
97
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
372 if (manualFlag)
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
373 {
97
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
374 // Handle manual control mode
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
375 if (manualChanged)
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
376 {
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
377 printf("%d ms frametime, frame #%d\n",
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
378 frameDelta, cycleFrames);
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
379 manualChanged = false;
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
380 }
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
381
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
382 SDL_Delay(25);
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
383 }
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
384 else
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
385 if (!pauseFlag)
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
386 {
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
387 // Handle automatic mode
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
388 totalFrames++;
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
389 cycleFrames++;
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
390
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
391 cycleTime += frameDelta;
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
392 totalTime += frameDelta;
10
c6c419861101 Use SDL_GetTicks() instead of std::clock().
Matti Hamalainen <ccr@tnsp.org>
parents: 8
diff changeset
393
89
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
394 memmove(&frameDeltas[0], &frameDeltas[1], sizeof(frameDeltas[0]) * (SET_FRAMES - 1));
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
395 frameDeltas[SET_FRAMES - 1] = frameDelta;
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
396
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
397 if (cycleFrames >= SET_FRAMES)
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
398 {
89
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
399 float avgCycleFrame = cycleTime / SET_FRAMES;
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
400 float maxJitter = 0, avgJitter = 0;
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
401
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
402 for (int n = 0; n < SET_FRAMES; n++)
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
403 {
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
404 float mjitter = fabs(avgCycleFrame - frameDeltas[n]);
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
405 if (mjitter > maxJitter)
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
406 maxJitter = mjitter;
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
407 avgJitter += mjitter;
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
408 }
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
409
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
410 avgJitter /= SET_FRAMES;
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
411
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
412 // Print the current frames per second
89
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
413 printf("%d ms for %d frames = %.1lf FPS [framejitter %.1lf ms avg, %.1lf ms max]\n",
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
414 cycleTime, cycleFrames,
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
415 (cycleFrames * 1000.0f) / cycleTime,
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
416 avgJitter, maxJitter
ff739727dfec Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents: 88
diff changeset
417 );
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
418
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
419 // Reset cycleFrames
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
420 cycleFrames = 0;
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
421 cycleTime = 0;
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
422 }
3
be31ff9e5f58 Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
423 }
81
5372b7795426 Use SDL_Delay(100) when in pause state to not consume CPU unnecessarily.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
424 else
5372b7795426 Use SDL_Delay(100) when in pause state to not consume CPU unnecessarily.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
425 {
97
05677852afd5 Improve manual mode.
Matti Hamalainen <ccr@tnsp.org>
parents: 95
diff changeset
426 SDL_Delay(100);
81
5372b7795426 Use SDL_Delay(100) when in pause state to not consume CPU unnecessarily.
Matti Hamalainen <ccr@tnsp.org>
parents: 80
diff changeset
427 }
2
b45d8958e5a6 Cosmetic indentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 0
diff changeset
428 }
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
429
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
430 // Show totals
73
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
431 printf("%d ms total for %d total frames = %.2lf FPS average\n",
3383e402817b Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents: 70
diff changeset
432 totalTime, totalFrames, ((double) totalFrames * 1000.0f) / (double) totalTime);
13
c1e8057cc4d0 Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents: 12
diff changeset
433
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
434 exit:
62
baccf2044289 Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents: 61
diff changeset
435 renderer.shutdownRenderer();
5
5dcae4dddcd9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 3
diff changeset
436
6
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
437 SDL_Quit();
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
438
4d6fec8f0c64 Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 5
diff changeset
439 return 0;
0
3d74a9dd96e4 Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff changeset
440 }