Mercurial > hg > forks > gldragon
comparison dmglrender.cpp @ 63:d6ffc59bb84d
Move more of the SDL and GL setup code to the renderer class.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 14 Dec 2019 20:13:32 +0200 |
parents | baccf2044289 |
children | 71f6c5cc8eec |
comparison
equal
deleted
inserted
replaced
62:baccf2044289 | 63:d6ffc59bb84d |
---|---|
101 } | 101 } |
102 return ok; | 102 return ok; |
103 } | 103 } |
104 | 104 |
105 | 105 |
106 bool DMGLSimpleRenderer::initRender1(void) | 106 bool DMGLSimpleRenderer::initRenderer1(const char *title, |
107 const int width, const int height, | |
108 const int sdlWindowHPos, const int sdlWindowVPos, | |
109 const int sdlFlags) | |
107 { | 110 { |
108 // Set GL attributes | 111 // Set GL attributes |
109 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); | 112 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); |
110 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); | 113 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); |
111 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); | 114 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); |
117 | 120 |
118 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); | 121 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); |
119 //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); | 122 //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32); |
120 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | 123 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); |
121 | 124 |
122 return true; | 125 // Attempt to create a window |
123 } | 126 if (!DMSimpleRenderer::initRenderer1( |
124 | 127 title, |
125 | 128 width, height, |
126 bool DMGLSimpleRenderer::initRender2(SDL_Window *window) | 129 sdlWindowHPos, sdlWindowVPos, |
127 { | 130 sdlFlags | SDL_WINDOW_OPENGL)) |
131 return false; | |
132 | |
128 // Create OpenGL context | 133 // Create OpenGL context |
129 if ((glContext = SDL_GL_CreateContext(window)) == NULL) | 134 if ((sdlGLContext = SDL_GL_CreateContext(sdlWindow)) == NULL) |
130 { | 135 { |
131 dmError("Unable to create SDL OpenGL context: %s\n", | 136 dmError("Unable to create SDL OpenGL context: %s\n", |
132 SDL_GetError()); | 137 SDL_GetError()); |
133 return false; | 138 return false; |
134 } | 139 } |
158 | 163 |
159 return status; | 164 return status; |
160 } | 165 } |
161 | 166 |
162 | 167 |
163 bool DMGLSimpleRenderer::initRender3(const int width, const int height) | 168 bool DMGLSimpleRenderer::initRenderer2(void) |
164 { | 169 { |
165 // Dump some information | 170 // Dump some information |
166 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR)); | 171 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR)); |
167 dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER)); | 172 dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER)); |
168 dmMsg("GL_VERSION : %s\n", glGetString(GL_VERSION)); | 173 dmMsg("GL_VERSION : %s\n", glGetString(GL_VERSION)); |
169 | 174 |
170 if (!checkErrors()) | 175 if (!checkErrors()) |
171 return false; | 176 return false; |
172 | 177 |
173 // Setup the window and view port | 178 // Setup the window and view port |
174 glViewport(0, 0, width, height); | 179 glViewport(0, 0, windowWidth, windowHeight); |
175 | 180 |
176 glMatrixMode(GL_PROJECTION); | 181 glMatrixMode(GL_PROJECTION); |
177 glLoadIdentity(); | 182 glLoadIdentity(); |
178 | 183 |
179 gluPerspective(45.0f, GLfloat(width) / GLfloat(height), 0.1f, 1000.0f); | 184 gluPerspective(45.0f, GLfloat(windowWidth) / GLfloat(windowHeight), 0.1f, 1000.0f); |
180 | 185 |
181 glMatrixMode(GL_MODELVIEW); | 186 glMatrixMode(GL_MODELVIEW); |
182 glLoadIdentity(); | 187 glLoadIdentity(); |
183 | 188 |
184 // Enable back face culling | 189 // Enable back face culling |
229 } | 234 } |
230 | 235 |
231 | 236 |
232 void DMGLSimpleRenderer::shutdownRenderer(void) | 237 void DMGLSimpleRenderer::shutdownRenderer(void) |
233 { | 238 { |
234 if (glContext != NULL) | 239 if (sdlGLContext != NULL) |
235 SDL_GL_DeleteContext(glContext); | 240 SDL_GL_DeleteContext(sdlGLContext); |
241 | |
242 DMSimpleRenderer::shutdownRenderer(); | |
236 } | 243 } |
237 | 244 |
238 | 245 |
239 void DMGLSimpleRenderer::drawModel(const DMSimpleScene &scene, const DMModel &model, const float time) | 246 void DMGLSimpleRenderer::drawModel(const DMSimpleScene &scene, const DMModel &model, const float time) |
240 { | 247 { |