Mercurial > hg > forks > gldragon
annotate glxdragon.cpp @ 5:5dcae4dddcd9
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 27 Oct 2019 18:29:23 +0200 |
parents | be31ff9e5f58 |
children | 4d6fec8f0c64 |
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 // |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
2 // Copyright (c) 2009, Thomas Trummer |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
3 // All rights reserved. |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
4 // |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
5 // Port to libSDL2 and cleanups by Matti Hämäläinen <ccr@tnsp.org> |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
6 // (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
|
7 // |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
8 // Redistribution and use in source and binary forms, with or without |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
9 // modification, are permitted provided that the following conditions are met: |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
10 // * Redistributions of source code must retain the above copyright |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
11 // notice, this list of conditions and the following disclaimer. |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
12 // * Redistributions in binary form must reproduce the above copyright |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
13 // notice, this list of conditions and the following disclaimer in the |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
14 // documentation and/or other materials provided with the distribution. |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
15 // * Neither the name of the <organization> nor the |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
16 // names of its contributors may be used to endorse or promote products |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
17 // derived from this software without specific prior written permission. |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
18 // |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
19 // THIS SOFTWARE IS PROVIDED BY Thomas Trummer ''AS IS'' AND ANY |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
21 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
22 // DISCLAIMED. IN NO EVENT SHALL <copyright holder> BE LIABLE FOR ANY |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
23 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
24 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
25 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
26 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
28 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
29 // |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
30 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
31 #include <SDL.h> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
32 #include <SDL_opengl.h> |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
33 #include <GL/glu.h> |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
34 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
35 #include <iostream> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
36 #include <sstream> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
37 #include <fstream> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
38 #include <stdexcept> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
39 #include <string> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
40 #include <vector> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
41 #include <algorithm> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
42 #include <cstdio> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
43 #include <ctime> |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
44 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
45 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
46 #define SET_FRAMES (180 * 2) |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
47 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
48 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
49 SDL_Window *s_window = NULL; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
50 SDL_GLContext s_context; |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
51 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
52 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
53 struct Mesh |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
54 { |
5 | 55 int nvertices, nfaces; |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
56 std::vector<float> vertices; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
57 std::vector<unsigned> faces; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
58 }; |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
59 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
60 |
5 | 61 |
62 bool dmInitSDLGL(const int width, const int height, 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
|
63 { |
2 | 64 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); |
65 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); | |
66 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); | |
67 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); | |
68 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
69 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
70 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
|
71 { |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
72 printf("ERROR: Unable to initialize SDL: %s\n", |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
73 SDL_GetError()); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
74 return false; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
75 } |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
76 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
77 if ((s_window = SDL_CreateWindow(title, |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
78 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
79 width, height, |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
80 SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE)) == NULL) |
2 | 81 { |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
82 printf("ERROR: Could not create SDL window: %s", |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
83 SDL_GetError()); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
84 return false; |
2 | 85 } |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
86 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
87 if ((s_context = SDL_GL_CreateContext(s_window)) == NULL) |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
88 { |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
89 printf("ERROR: Unable to create SDL OpenGL context: %s\n", |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
90 SDL_GetError()); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
91 return false; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
92 } |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
93 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
94 printf( |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
95 "GL_VENDOR : %s\n" |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
96 "GL_RENDERER : %s\n" |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
97 "GL_VERSION : %s\n", |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
98 glGetString(GL_VENDOR), |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
99 glGetString(GL_RENDERER), |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
100 glGetString(GL_VERSION)); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
101 |
2 | 102 // Setup the window and view port |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
103 glViewport(0, 0, width, height); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
104 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
105 glMatrixMode(GL_PROJECTION); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
106 glLoadIdentity(); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
107 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
108 gluPerspective(45.0f, GLfloat(width) / GLfloat(height), 0.1f, 1000.0f); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
109 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
110 glMatrixMode(GL_MODELVIEW); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
111 glLoadIdentity(); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
112 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
113 |
2 | 114 // Enable back face culling |
115 glEnable(GL_CULL_FACE); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
116 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
117 // Enable smooth shading |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
118 glShadeModel(GL_SMOOTH); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
119 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
120 // Enable the depth buffer |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
121 glEnable(GL_DEPTH_TEST); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
122 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
123 // Setup depth buffer |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
124 glClearDepth(1.0f); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
125 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
126 // Set the depth buffer function |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
127 glDepthFunc(GL_LEQUAL); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
128 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
129 // Enable vertex and and normal arrays |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
130 glEnableClientState(GL_VERTEX_ARRAY); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
131 glEnableClientState(GL_NORMAL_ARRAY); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
132 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
133 // Set correct perspective correction |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
134 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
135 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
136 return true; |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
137 } |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
138 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
139 |
5 | 140 void dmInitScene(void) |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
141 { |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
142 glEnable(GL_COLOR_MATERIAL); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
143 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
144 glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
145 glMateriali(GL_FRONT, GL_SHININESS, 96); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
146 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
147 float specReflection[] = { 0.8f, 0.8f, 0.8f, 1.0f }; |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
148 glMaterialfv(GL_FRONT, GL_SPECULAR, specReflection); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
149 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
150 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
151 glEnable(GL_LIGHT0); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
152 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
153 // Define the light components and position |
2 | 154 GLfloat ambient[] = { 0.2f, 0.2f, 0.2f, 1.0f }; |
155 GLfloat diffuse[] = { 0.8f, 0.8f, 0.8f, 1.0f }; | |
156 GLfloat specular[] = { 0.5f, 0.5f, 0.5f, 1.0f }; | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
157 GLfloat position[] = { 10.0f, 10.0f, 0.0f, 0.0f }; |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
158 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
159 // Define the light components and position |
2 | 160 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient); |
161 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
162 glLightfv(GL_LIGHT0, GL_SPECULAR, specular); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
163 glLightfv(GL_LIGHT0, GL_POSITION, position); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
164 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
165 // Define the camera |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
166 gluLookAt(0, 0.12, 0.24, 0, 0.12, 0, 0, 1, 0); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
167 } |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
168 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
169 |
5 | 170 void dmFinish() |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
171 { |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
172 SDL_GL_DeleteContext(s_context); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
173 SDL_DestroyWindow(s_window); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
174 s_window = NULL; |
2 | 175 SDL_Quit(); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
176 } |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
177 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
178 |
5 | 179 void dmDrawModelVA(const Mesh &mesh) |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
180 { |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
181 int maxIndices; |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
182 |
2 | 183 glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &maxIndices); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
184 |
2 | 185 glVertexPointer(3, GL_FLOAT, 24, &mesh.vertices[0]); |
186 glNormalPointer(GL_FLOAT, 24, &mesh.vertices[3]); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
187 |
5 | 188 for (int n = 0; n < mesh.nfaces; n += maxIndices) |
2 | 189 { |
5 | 190 const int count = std::min(maxIndices, int(mesh.nfaces - n)); |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
191 glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_INT, &mesh.faces[n * 3]); |
2 | 192 } |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
193 } |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
194 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
195 |
5 | 196 void dmPaintGL(Mesh &mesh) |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
197 { |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
198 glClear(GL_DEPTH_BUFFER_BIT); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
199 |
2 | 200 glMatrixMode(GL_PROJECTION); |
201 glPushMatrix(); | |
202 glLoadIdentity(); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
203 |
2 | 204 glOrtho(0.0, 1.0, 0.0, 1.0, -1, 1); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
205 |
2 | 206 glMatrixMode(GL_MODELVIEW); |
207 glPushMatrix(); | |
208 glLoadIdentity(); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
209 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
210 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
211 glDisable(GL_DEPTH_TEST); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
212 glDisable(GL_LIGHTING); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
213 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
214 // Draw the background gradient |
2 | 215 glBegin(GL_QUADS); |
216 { | |
217 glColor3ub(0x3B, 0x3B, 0x75); | |
218 glVertex2f(0.0f, 0.0f); | |
219 glVertex2f(1.0f, 0.0f); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
220 |
2 | 221 glColor3ub(0x00, 0x00, 0x00); |
222 glVertex2f(1.0f, 1.0f); | |
223 glVertex2f(0.0f, 1.0f); | |
224 } | |
225 glEnd(); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
226 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
227 |
2 | 228 // Restore the 3D projection |
229 glMatrixMode(GL_PROJECTION); | |
230 glPopMatrix(); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
231 |
2 | 232 glMatrixMode(GL_MODELVIEW); |
233 glPopMatrix(); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
234 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
235 glEnable(GL_DEPTH_TEST); |
5 | 236 glEnable(GL_LIGHTING); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
237 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
238 // Set the color of the model |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
239 glColor3ub(0x90, 0x80, 0x90); |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
240 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
241 // Draw the model using vertex arrays |
5 | 242 dmDrawModelVA(mesh); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
243 } |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
244 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
245 |
5 | 246 void dmLoadMesh(const std::string &filename, Mesh &mesh, int nvertices, int nfaces) |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
247 { |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
248 std::ifstream in(filename.c_str(), std::ios::binary); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
249 |
2 | 250 if (!in.is_open()) |
251 { | |
252 std::stringstream ss; | |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
253 ss << "Unable to open file: " << filename << '\n'; |
2 | 254 throw std::runtime_error(ss.str()); |
255 } | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
256 |
5 | 257 mesh.nvertices = nvertices; |
258 mesh.vertices.resize(mesh.nvertices * 6); | |
259 in.read(reinterpret_cast<char*>(&mesh.vertices[0]), mesh.nvertices * 6 * 4); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
260 |
5 | 261 mesh.nfaces = nfaces; |
262 mesh.faces.resize(mesh.nfaces * 3); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
263 |
5 | 264 for (int i = 0; i < nfaces; i++) |
2 | 265 { |
266 in.seekg(1, std::ios::cur); | |
267 in.read(reinterpret_cast<char*>(&mesh.faces[i * 3]), 3 * 4); | |
268 } | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
269 } |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
270 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
271 |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
272 int main() |
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
273 { |
2 | 274 try |
275 { | |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
276 struct Mesh dragonMesh; |
5 | 277 dmLoadMesh("dragon.mesh", dragonMesh, 100139, 200198); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
278 |
5 | 279 //if (!dmInitSDLGL(640, 480, "glxdragon")) |
280 if (!dmInitSDLGL(1280, 960, "glxdragon")) | |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
281 throw std::runtime_error("Fatal error."); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
282 |
5 | 283 dmInitScene(); |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
284 |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
285 bool exitFlag = false; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
286 int steps = 0; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
287 std::clock_t startTime = std::clock(); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
288 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
289 while (!exitFlag) |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
290 { |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
291 SDL_Event event; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
292 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
293 // Check for quit events |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
294 while (SDL_PollEvent(&event)) |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
295 switch (event.type) |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
296 { |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
297 case SDL_QUIT: |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
298 exitFlag = true; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
299 break; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
300 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
301 case SDL_KEYDOWN: |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
302 switch (event.key.keysym.sym) |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
303 { |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
304 case SDLK_ESCAPE: |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
305 case SDLK_q: |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
306 exitFlag = true; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
307 break; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
308 } |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
309 } |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
310 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
311 // Render the next frame |
5 | 312 dmPaintGL(dragonMesh); |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
313 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
314 // Draw the current frame |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
315 SDL_GL_SwapWindow(s_window); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
316 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
317 // Rotate for 2 degrees |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
318 glRotatef(2.0f, 0, 1, 0); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
319 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
320 // Return true if a full rotation was done |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
321 if (steps++ == SET_FRAMES) |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
322 { |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
323 // Reset steps |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
324 steps = 0; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
325 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
326 // Get the time it took to render a full turn |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
327 double time = (double(std::clock() - startTime) * 1000.0f) / CLOCKS_PER_SEC; |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
328 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
329 // Print the current frames per second |
5 | 330 printf("%.1lf ms for %d frames = %.1lf FPS\n", |
3
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
331 time, SET_FRAMES, (SET_FRAMES * 1000.0f) / time); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
332 |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
333 // Restart the timer |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
334 startTime = std::clock(); |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
335 } |
be31ff9e5f58
Port to libSDL2, clean up the code and some de-C++-ifications.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
336 } |
2 | 337 } |
338 catch(std::runtime_error & e) | |
339 { | |
340 std::cerr << e.what(); | |
341 } | |
5 | 342 |
343 dmFinish(); | |
0
3d74a9dd96e4
Initial import of Thomas Trummer's original code.
Thomas Trummer
parents:
diff
changeset
|
344 } |