Mercurial > hg > forks > gldragon
annotate gldragon.cpp @ 72:a21f3cbaf20e
Use -mconsole for windows gldragon binaries.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 16 Dec 2019 10:23:46 +0200 |
parents | 03aa729a9e90 |
children | 3383e402817b |
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 |
b1e75c65016d
Check for "too large" shader files.
Matti Hamalainen <ccr@tnsp.org>
parents:
17
diff
changeset
|
20 #define SET_FRAMES (180) |
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, |
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
45 SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)) |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
46 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
|
47 |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
48 // 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
|
49 switch (vsyncMode) |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
50 { |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
51 case 3: |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
52 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
|
53 msg = "adaptive vsync"; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
54 break; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
55 |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
56 case 2: |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
57 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
|
58 msg = "synchronized (vsync)"; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
59 break; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
60 |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
61 case 1: |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
62 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
|
63 msg = "immediate (no vsync)"; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
64 break; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
65 |
38
372fa249ce26
Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
66 case 0: |
372fa249ce26
Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
67 msg = "vsync handling disabled"; |
372fa249ce26
Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
68 ret = 0; |
372fa249ce26
Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
69 break; |
372fa249ce26
Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
70 |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
71 default: |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
72 ret = -1; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
73 msg = "INVALID VSYNC MODE"; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
74 break; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
75 } |
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 if (ret != 0) |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
78 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
79 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
|
80 msg.c_str()); |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
81 return false; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
82 } |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
83 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
84 // 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
|
85 if (!renderer.initRenderer2()) |
55 | 86 return false; |
87 | |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
88 dmMsg("VSync mode : %s\n", msg.c_str()); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
89 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
90 return true; |
25
2403030a0352
"Finish" implementing multiple lights support in scene files.
Matti Hamalainen <ccr@tnsp.org>
parents:
24
diff
changeset
|
91 } |
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 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
94 int main(int argc, char *argv[]) |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
95 { |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
96 bool |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
97 exitFlag = false, |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
98 optShowHelp = false, |
64
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
99 optSetInputFilename = false, |
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
100 optUseShaders = false; |
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
101 |
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
102 int optWidth = SET_DEF_WIDTH, |
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
103 optHeight = SET_DEF_HEIGHT, |
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
104 optVSyncMode = 1; |
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
105 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
106 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
|
107 DMGLSimpleRenderer renderer; |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
108 DMSimpleScene scene; |
64
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
109 int startTime, cycleStart, cycleFrames = 0, totalFrames = 0; |
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
110 double totalTime; |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
111 |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
112 // Check commandline argument for enabling shaders |
7 | 113 for (int narg = 1; narg < argc; narg++) |
114 { | |
115 char *arg = argv[narg]; | |
11
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
116 if (arg[0] == '-') |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
117 { |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
118 char *opt = arg + 1; |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
119 |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
120 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
|
121 opt[0] == '?' || (opt[0] == '-' && opt[1] == '?')) |
11
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
122 { |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
123 optShowHelp = true; |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
124 break; |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
125 } |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
126 else |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
127 if (opt[0] == '-') |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
128 opt++; |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
129 |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
130 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
|
131 { |
55 | 132 case 'g': |
133 optUseShaders = true; | |
134 break; | |
135 | |
67
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
136 case 's': |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
137 case 'm': |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
138 case 'v': |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
139 { |
67
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
140 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
|
141 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
|
142 { |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
143 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
|
144 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
|
145 else |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
146 { |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
147 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
|
148 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
|
149 } |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
150 } |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
151 else |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
152 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
|
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 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
|
155 { |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
156 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
|
157 { |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
158 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
|
159 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
|
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 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
|
162 "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
|
163 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
|
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 |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
166 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
|
167 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
|
168 } |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
169 break; |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
170 |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
171 case 'v': optVSyncMode = std::stoi(marg, 0, 0); break; |
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
172 } |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
173 } |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
174 break; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
175 |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
176 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
|
177 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
|
178 goto exit; |
52a586c344f4
Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
179 } |
11
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
180 } |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
181 else |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
182 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
183 if (optSetInputFilename) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
184 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
185 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
|
186 goto exit; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
187 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
188 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
189 optSetInputFilename = true; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
190 optInputFilename = std::string(arg); |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
191 if (optInputFilename.empty()) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
192 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
193 dmError("Invalid input filename.\n"); |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
194 goto exit; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
195 } |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
196 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
197 } |
7 | 198 } |
199 | |
8 | 200 if (optShowHelp) |
7 | 201 { |
202 printf( | |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
203 "Usage: %s [options] [<scenefile.scene>]\n" |
12
52a586c344f4
Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
204 "-? Show this help\n" |
52a586c344f4
Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
205 "-g Use GLSL shader instead of basic OpenGL lighting\n" |
67
1327ef5dc9fb
Remove -w and -h options and replace them with -s <width>x<height>.
Matti Hamalainen <ccr@tnsp.org>
parents:
64
diff
changeset
|
206 "-s<w>x<h> Set window dimensions (default %d x %d)\n" |
38
372fa249ce26
Add vsync option 0 (disable attempts of setting vsync mode.)
Matti Hamalainen <ccr@tnsp.org>
parents:
37
diff
changeset
|
207 "-v<0-3> Set vsync mode: 0 = do not attempt to set vsync mode\n" |
50
d4232c89145f
Clarify the help for -v option.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
208 " (may be required for software rendering backends),\n" |
d4232c89145f
Clarify the help for -v option.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
209 " 1 = no vsync, 2 = vsync, 3 = adaptive.\n" |
d4232c89145f
Clarify the help for -v option.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
210 " Using vsync (2) will result in FPS being approximately\n" |
d4232c89145f
Clarify the help for -v option.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
211 " whatever your monitor refresh rate is. The default\n" |
d4232c89145f
Clarify the help for -v option.
Matti Hamalainen <ccr@tnsp.org>
parents:
49
diff
changeset
|
212 " value is 1 (no vsync).\n" |
11
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
213 "\n", |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
214 argv[0], |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
215 SET_DEF_WIDTH, SET_DEF_HEIGHT |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
216 ); |
89dc8caeff41
Improve option handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
10
diff
changeset
|
217 |
7 | 218 goto exit; |
219 } | |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
220 |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
221 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
|
222 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
223 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
|
224 optWidth, optHeight); |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
225 goto exit; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
226 } |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
227 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
228 // Load the scene |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
229 if (!scene.loadInfo(optInputFilename)) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
230 goto exit; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
231 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
232 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
|
233 { |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
234 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
|
235 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
|
236 goto exit; |
52a586c344f4
Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
237 } |
52a586c344f4
Add option -m<filename prefix> to specify mesh/shader filename prefix.
Matti Hamalainen <ccr@tnsp.org>
parents:
11
diff
changeset
|
238 |
31
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
239 // 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
|
240 if (scene.lights.size() == 0) |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
241 { |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
242 DMLight light; // Default light |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
243 scene.lights.push_back(light); |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
244 } |
6847715b46cd
Move piece of code a bit as a cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents:
27
diff
changeset
|
245 |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
246 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
|
247 scene.models.size()); |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
248 |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
249 basePath = dmGetPath(optInputFilename); |
47
9909014498f0
Add helper functions dmError() and dmMsg() and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
46
diff
changeset
|
250 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
|
251 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
252 for (DMModel &model : scene.models) |
2 | 253 { |
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
|
254 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
|
255 goto exit; |
21
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
256 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
257 if (optUseShaders) |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
258 { |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
259 std::string |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
260 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
|
261 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
|
262 |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
263 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
|
264 !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
|
265 goto exit; |
1404dfcee7b8
More work on scenefile and model loading support.
Matti Hamalainen <ccr@tnsp.org>
parents:
20
diff
changeset
|
266 } |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
267 } |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
268 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
269 // 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
|
270 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
|
271 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
272 // Initialize SDL + OpenGL |
64
e8100c1c5d99
Move option settings from globals to main().
Matti Hamalainen <ccr@tnsp.org>
parents:
63
diff
changeset
|
273 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
|
274 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
|
275 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
276 // 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
|
277 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
|
278 goto exit; |
24
c1897cfc8463
Add shader compilation error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
23
diff
changeset
|
279 |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
280 // 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
|
281 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
|
282 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
|
283 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
284 // Main loop starts |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
285 startTime = cycleStart = SDL_GetTicks(); |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
286 |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
287 while (!exitFlag) |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
288 { |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
289 SDL_Event event; |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
290 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
291 // Check for quit events |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
292 while (SDL_PollEvent(&event)) |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
293 switch (event.type) |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
294 { |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
295 case SDL_QUIT: |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
296 exitFlag = true; |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
297 break; |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
298 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
299 case SDL_KEYDOWN: |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
300 switch (event.key.keysym.sym) |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
301 { |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
302 case SDLK_ESCAPE: |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
303 case SDLK_q: |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
304 exitFlag = true; |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
305 break; |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
306 } |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
307 } |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
308 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
309 // Render the next frame |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
310 totalTime = SDL_GetTicks() - startTime; |
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
311 renderer.drawScene(scene, totalTime); |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
312 |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
313 // Draw the current frame |
63
d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
Matti Hamalainen <ccr@tnsp.org>
parents:
62
diff
changeset
|
314 renderer.swapWindow(); |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
315 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
316 // Rotate for 2 degrees |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
317 renderer.animate(scene, totalTime); |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
318 |
55 | 319 // 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
|
320 renderer.checkErrors(); |
55 | 321 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
322 // Return true if a full rotation was done |
15
2d2aadfa3df3
Fix calculation of totalFrames.
Matti Hamalainen <ccr@tnsp.org>
parents:
14
diff
changeset
|
323 totalFrames++; |
69 | 324 cycleFrames++; |
325 if (cycleFrames >= SET_FRAMES) | |
6
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 // Get the time it took to render a full turn |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
328 int cycleEnd = SDL_GetTicks(); |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
329 double cycleTime = cycleEnd - cycleStart; |
10
c6c419861101
Use SDL_GetTicks() instead of std::clock().
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
330 |
c6c419861101
Use SDL_GetTicks() instead of std::clock().
Matti Hamalainen <ccr@tnsp.org>
parents:
8
diff
changeset
|
331 // Restart the timer |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
332 cycleStart = SDL_GetTicks(); |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
333 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
334 // Print the current frames per second |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
335 printf("%.1lf ms for %d frames = %.1lf FPS\n", |
69 | 336 cycleTime, cycleFrames, (cycleFrames * 1000.0f) / cycleTime); |
337 | |
338 // Reset cycleFrames | |
339 cycleFrames = 0; | |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
340 } |
2 | 341 } |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
342 |
13
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
343 // Show totals |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
344 totalTime = SDL_GetTicks() - startTime; |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
345 printf("%.1lf ms total for %d total frames = %.2lf FPS average\n", |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
346 totalTime, totalFrames, (totalFrames * 1000.0f) / totalTime); |
c1e8057cc4d0
Improvements to option handling, add option for setting preferred vsync
Matti Hamalainen <ccr@tnsp.org>
parents:
12
diff
changeset
|
347 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
348 exit: |
62
baccf2044289
Move the OpenGL rendering, setup etc. into a separate module/class, perhaps
Matti Hamalainen <ccr@tnsp.org>
parents:
61
diff
changeset
|
349 renderer.shutdownRenderer(); |
5 | 350 |
6
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
351 SDL_Quit(); |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
352 |
4d6fec8f0c64
Implement optional support for vertex/fragment shaders. Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
5
diff
changeset
|
353 return 0; |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
354 } |