Mercurial > hg > forks > gldragon
annotate gldragon.cpp @ 102:2b22a89dd811
Add program information and copyright blurb in help.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 06 Oct 2022 05:01:45 +0300 |
parents | a3486ce56148 |
children | 6520f00c68e4 |
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 | 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 | 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 | 87 return false; |
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 | 102 manualFlag = false, |
97 | 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, |
101
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
111 optPauseFrame = -1, |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
112 optQuitFrame = -1; |
64
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
113 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
114 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
|
115 DMGLSimpleRenderer renderer; |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
116 DMSimpleScene scene; |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
117 int cycleTime = 0, |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
118 cycleFrames = 0, |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
119 totalTime = 0, |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
120 totalFrames = 0; |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
121 |
89
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
122 memset(&frameDeltas, 0, sizeof(frameDeltas)); |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
123 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
124 // Check commandline argument for enabling shaders |
7 | 125 for (int narg = 1; narg < argc; narg++) |
126 { | |
127 char *arg = argv[narg]; | |
11
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
128 if (arg[0] == '-') |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
129 { |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
130 char *opt = arg + 1; |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
131 |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
132 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
|
133 opt[0] == '?' || (opt[0] == '-' && opt[1] == '?')) |
11
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
134 { |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
135 optShowHelp = true; |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
136 break; |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
137 } |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
138 else |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
139 if (opt[0] == '-') |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
140 opt++; |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
141 |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
142 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
|
143 { |
55 | 144 case 'g': |
145 optUseShaders = true; | |
146 break; | |
147 | |
67
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
148 case 's': |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
149 case 'm': |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
150 case 'v': |
88
8b34eab13549
Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
151 case 'p': |
101
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
152 case 'q': |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
153 { |
67
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
154 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
|
155 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
|
156 { |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
157 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
|
158 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
|
159 else |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
160 { |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
161 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
|
162 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
|
163 } |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
164 } |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
165 else |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
166 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
|
167 |
67
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
168 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
|
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 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
|
171 { |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
172 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
|
173 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
|
174 { |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
175 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
|
176 "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
|
177 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
|
178 } |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
179 |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
180 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
|
181 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
|
182 } |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
183 break; |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
184 |
88
8b34eab13549
Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
185 case 'v': |
8b34eab13549
Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
186 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
|
187 break; |
8b34eab13549
Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
188 |
8b34eab13549
Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
189 case 'p': |
8b34eab13549
Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
190 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
|
191 break; |
101
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
192 |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
193 case 'q': |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
194 optQuitFrame = std::stoi(marg, 0, 0); |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
195 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
|
196 } |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
197 } |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
198 break; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
199 |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
200 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
|
201 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
|
202 goto exit; |
52a586c344f4
Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
203 } |
11
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
204 } |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
205 else |
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 if (optSetInputFilename) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
208 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
209 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
|
210 goto exit; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
211 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
212 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
213 optSetInputFilename = true; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
214 optInputFilename = std::string(arg); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
215 if (optInputFilename.empty()) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
216 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
217 dmError("Invalid input filename.\n"); |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
218 goto exit; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
219 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
220 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
221 } |
7 | 222 } |
223 | |
8 | 224 if (optShowHelp) |
7 | 225 { |
226 printf( | |
102
2b22a89dd811
Add program information and copyright blurb in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
227 "GLDragon - OpenGL PLY model viewer / simple benchmark\n" |
2b22a89dd811
Add program information and copyright blurb in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
228 "Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>\n" |
2b22a89dd811
Add program information and copyright blurb in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
229 "(C) Copyright 2019-2022 Tecnic Software productions (TNSP)\n" |
2b22a89dd811
Add program information and copyright blurb in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
230 "See file \"COPYING\" for license information.\n" |
2b22a89dd811
Add program information and copyright blurb in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
231 "Originally based on 'glxdragon' Copyright (c) 2009, Thomas Trummer\n" |
2b22a89dd811
Add program information and copyright blurb in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
101
diff
changeset
|
232 "\n" |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
233 "Usage: %s [options] [<scenefile.scene>]\n" |
87 | 234 "\n" |
235 " -? Show this help\n" | |
236 " -g Use GLSL shader instead of basic OpenGL lighting\n" | |
237 " -s<w>x<h> Set window dimensions (default %d x %d)\n" | |
238 " -v<0-3> Set vsync mode: 0 = do not attempt to set vsync mode\n" | |
239 " (may be required for software rendering backends),\n" | |
240 " 1 = no vsync, 2 = vsync, 3 = adaptive.\n" | |
241 " Using vsync (2) will result in FPS being approximately\n" | |
242 " whatever your monitor refresh rate is. The default\n" | |
243 " 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
|
244 " -p<frameN> Start and pause at cycle frame (%d .. %d).\n" |
101
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
245 " -q<frameN> Quit at frame (%d .. %d).\n" |
80
98e077d9d361
List the keyboard controls in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
246 "\n" |
98e077d9d361
List the keyboard controls in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
247 "Keyboard controls during runtime:\n" |
98e077d9d361
List the keyboard controls in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
73
diff
changeset
|
248 " 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
|
249 " q / esc Quit\n" |
95
59195e95c080
Improve help, document arrow key controls.
Matti Hamalainen <ccr@tnsp.org>
parents:
94
diff
changeset
|
250 " 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
|
251 "\n", |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
252 argv[0], |
88
8b34eab13549
Add -p -option for pausing at specific cycle frame.
Matti Hamalainen <ccr@tnsp.org>
parents:
87
diff
changeset
|
253 SET_DEF_WIDTH, SET_DEF_HEIGHT, |
101
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
254 0, SET_FRAMES - 1, |
98
44e3656f4c83
Fix help to display correct range for frame numbers.
Matti Hamalainen <ccr@tnsp.org>
parents:
97
diff
changeset
|
255 0, SET_FRAMES - 1 |
11
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
256 ); |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
257 |
7 | 258 goto exit; |
259 } | |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
260 |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
261 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
|
262 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
263 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
|
264 optWidth, optHeight); |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
265 goto exit; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
266 } |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
267 |
101
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
268 if (optQuitFrame >= 0 && optPauseFrame >= 0) |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
269 { |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
270 dmError("Only one of 'quit frame' (-q) and 'pause frame' (-p) options can be set.\n"); |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
271 goto exit; |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
272 } |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
273 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
274 // Load the scene |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
275 if (!scene.loadInfo(optInputFilename)) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
276 goto exit; |
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 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
|
279 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
280 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
|
281 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
|
282 goto exit; |
52a586c344f4
Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
283 } |
52a586c344f4
Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
284 |
31
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
285 // 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
|
286 if (scene.lights.size() == 0) |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
287 { |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
288 DMLight light; // Default light |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
289 scene.lights.push_back(light); |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
290 } |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
291 |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
292 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
|
293 scene.models.size()); |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
294 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
295 basePath = dmGetPath(optInputFilename); |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
296 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
|
297 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
298 for (DMModel &model : scene.models) |
2 | 299 { |
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
|
300 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
|
301 goto exit; |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
302 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
303 if (optUseShaders) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
304 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
305 std::string |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
306 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
|
307 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
|
308 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
309 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
|
310 !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
|
311 goto exit; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
312 } |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
313 } |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
314 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
315 // 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
|
316 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
|
317 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
318 // Initialize SDL + OpenGL |
64
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
319 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
|
320 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
|
321 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
322 // 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
|
323 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
|
324 goto exit; |
24
c1897cfc8463
Add shader compilation error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
325 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
326 // 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
|
327 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
|
328 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
|
329 |
93
9fee97e7c5b6
Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
330 // Check for pause frame |
9fee97e7c5b6
Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
331 if (optPauseFrame >= 0) |
9fee97e7c5b6
Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
332 { |
9fee97e7c5b6
Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
333 cycleFrames = optPauseFrame; |
9fee97e7c5b6
Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
334 pauseFlag = true; |
9fee97e7c5b6
Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
335 } |
9fee97e7c5b6
Handle pauseframe differently: skip straight to it.
Matti Hamalainen <ccr@tnsp.org>
parents:
92
diff
changeset
|
336 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
337 // Main loop starts |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
338 while (!exitFlag) |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
339 { |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
340 SDL_Event event; |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
341 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
|
342 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
343 // Check for quit events |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
344 while (SDL_PollEvent(&event)) |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
345 switch (event.type) |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
346 { |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
347 case SDL_QUIT: |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
348 exitFlag = true; |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
349 break; |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
350 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
351 case SDL_KEYDOWN: |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
352 switch (event.key.keysym.sym) |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
353 { |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
354 case SDLK_SPACE: |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
355 case SDLK_p: |
94 | 356 if (manualFlag) |
357 pauseFlag = manualFlag = false; | |
358 else | |
359 pauseFlag = !pauseFlag; | |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
360 break; |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
361 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
362 case SDLK_ESCAPE: |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
363 case SDLK_q: |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
364 exitFlag = true; |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
365 break; |
94 | 366 |
367 case SDLK_RIGHT: | |
97 | 368 manualChanged = manualFlag = true; |
369 if (++cycleFrames >= SET_FRAMES) | |
370 cycleFrames = 0; | |
94 | 371 break; |
372 | |
373 case SDLK_LEFT: | |
97 | 374 manualChanged = manualFlag = true; |
375 if (--cycleFrames < 0) | |
376 cycleFrames = SET_FRAMES - 1; | |
94 | 377 break; |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
378 } |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
379 } |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
380 |
92
28dd29f3a65f
Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
381 // Render the frame |
28dd29f3a65f
Remove DMSimpleRenderer::animate() and use direct time value in drawScene() etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
89
diff
changeset
|
382 frameStart = SDL_GetTicks(); |
97 | 383 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
|
384 renderer.swapWindow(); |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
385 frameEnd = SDL_GetTicks(); |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
386 |
55 | 387 // 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
|
388 renderer.checkErrors(); |
55 | 389 |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
390 frameDelta = frameEnd - frameStart; |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
391 |
101
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
392 // Check for quit frame |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
393 if (optQuitFrame >= 0 && cycleFrames == optQuitFrame) |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
394 { |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
395 exitFlag = true; |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
396 } |
a3486ce56148
Add option '-q<n>' to quit execution at frame N.
Matti Hamalainen <ccr@tnsp.org>
parents:
98
diff
changeset
|
397 else |
97 | 398 if (manualFlag) |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
399 { |
97 | 400 // Handle manual control mode |
401 if (manualChanged) | |
402 { | |
403 printf("%d ms frametime, frame #%d\n", | |
404 frameDelta, cycleFrames); | |
405 manualChanged = false; | |
406 } | |
407 | |
408 SDL_Delay(25); | |
409 } | |
410 else | |
411 if (!pauseFlag) | |
412 { | |
413 // Handle automatic mode | |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
414 totalFrames++; |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
415 cycleFrames++; |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
416 |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
417 cycleTime += frameDelta; |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
418 totalTime += frameDelta; |
10
c6c419861101
Use SDL_GetTicks() instead of std::clock().
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
419 |
89
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
420 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
|
421 frameDeltas[SET_FRAMES - 1] = frameDelta; |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
422 |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
423 if (cycleFrames >= SET_FRAMES) |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
424 { |
89
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
425 float avgCycleFrame = cycleTime / SET_FRAMES; |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
426 float maxJitter = 0, avgJitter = 0; |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
427 |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
428 for (int n = 0; n < SET_FRAMES; n++) |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
429 { |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
430 float mjitter = fabs(avgCycleFrame - frameDeltas[n]); |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
431 if (mjitter > maxJitter) |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
432 maxJitter = mjitter; |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
433 avgJitter += mjitter; |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
434 } |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
435 |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
436 avgJitter /= SET_FRAMES; |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
437 |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
438 // Print the current frames per second |
89
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
439 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
|
440 cycleTime, cycleFrames, |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
441 (cycleFrames * 1000.0f) / cycleTime, |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
442 avgJitter, maxJitter |
ff739727dfec
Compute and display frametime jitter values.
Matti Hamalainen <ccr@tnsp.org>
parents:
88
diff
changeset
|
443 ); |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
444 |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
445 // Reset cycleFrames |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
446 cycleFrames = 0; |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
447 cycleTime = 0; |
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
448 } |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
449 } |
81
5372b7795426
Use SDL_Delay(100) when in pause state to not consume CPU unnecessarily.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
450 else |
5372b7795426
Use SDL_Delay(100) when in pause state to not consume CPU unnecessarily.
Matti Hamalainen <ccr@tnsp.org>
parents:
80
diff
changeset
|
451 { |
97 | 452 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
|
453 } |
2 | 454 } |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
455 |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
456 // Show totals |
73
3383e402817b
Implement pause mode and adjust the frame/FPS calculations accordingly.
Matti Hamalainen <ccr@tnsp.org>
parents:
70
diff
changeset
|
457 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
|
458 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
|
459 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
460 exit: |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
461 renderer.shutdownRenderer(); |
5 | 462 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
463 SDL_Quit(); |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
464 |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
465 return 0; |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
466 } |