comparison dmglrender.cpp @ 90:3863ad92f8d8

Rename a variable.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 12 Jan 2021 14:33:18 +0200
parents 69d7349dc5d3
children 4df8a7337e3e
comparison
equal deleted inserted replaced
89:ff739727dfec 90:3863ad92f8d8
163 163
164 return status; 164 return status;
165 } 165 }
166 166
167 167
168 bool DMGLSimpleRenderer::initRenderer2(void)
169 {
170 // Dump some information
171 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR));
172 dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER));
173 dmMsg("GL_VERSION : %s\n", glGetString(GL_VERSION));
174
175 if (!checkErrors())
176 return false;
177
178 // Setup the window and view port
179 glViewport(0, 0, windowWidth, windowHeight);
180
181 glMatrixMode(GL_PROJECTION);
182 glLoadIdentity();
183
184 gluPerspective(45.0f, GLfloat(windowWidth) / GLfloat(windowHeight), 0.1f, 1000.0f);
185
186 glMatrixMode(GL_MODELVIEW);
187 glLoadIdentity();
188
189 // Enable back face culling
190 glEnable(GL_CULL_FACE);
191
192 // Enable smooth shading
193 glShadeModel(GL_SMOOTH);
194
195 // Enable the depth buffer
196 glEnable(GL_DEPTH_TEST);
197
198 // Enable normal rescaling
199 glEnable(GL_RESCALE_NORMAL);
200
201 glEnable(GL_COLOR_MATERIAL);
202
203 // Setup depth buffer
204 glClearDepth(1.0f);
205
206 // Set the depth buffer function
207 glDepthFunc(GL_LEQUAL);
208
209 // Enable vertex and and normal arrays
210 glEnableClientState(GL_VERTEX_ARRAY);
211 glEnableClientState(GL_NORMAL_ARRAY);
212
213 // Set correct perspective correction
214 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
215
216
217 // Create texture bitmap
218 #define TWIDTH 8 168 #define TWIDTH 8
219 #define THEIGHT 8 169 #define THEIGHT 8
220 char texSrc[TWIDTH * THEIGHT + 1] = 170 static char texSrc8[TWIDTH * THEIGHT + 1] =
221 "..%##%.." 171 "..%##%.."
222 ".%####%." 172 ".%####%."
223 "%#*..*#%" 173 "%#*..*#%"
224 "##....##" 174 "##....##"
225 "########" 175 "########"
226 "##....##" 176 "##....##"
227 "##....##" 177 "##....##"
228 "##....##"; 178 "##....##";
229 179
180
181 bool DMGLSimpleRenderer::initRenderer2(void)
182 {
183 // Dump some information
184 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR));
185 dmMsg("GL_RENDERER : %s\n", glGetString(GL_RENDERER));
186 dmMsg("GL_VERSION : %s\n", glGetString(GL_VERSION));
187
188 if (!checkErrors())
189 return false;
190
191 // Setup the window and view port
192 glViewport(0, 0, windowWidth, windowHeight);
193
194 glMatrixMode(GL_PROJECTION);
195 glLoadIdentity();
196
197 gluPerspective(45.0f, GLfloat(windowWidth) / GLfloat(windowHeight), 0.1f, 1000.0f);
198
199 glMatrixMode(GL_MODELVIEW);
200 glLoadIdentity();
201
202 // Enable back face culling
203 glEnable(GL_CULL_FACE);
204
205 // Enable smooth shading
206 glShadeModel(GL_SMOOTH);
207
208 // Enable the depth buffer
209 glEnable(GL_DEPTH_TEST);
210
211 // Enable normal rescaling
212 glEnable(GL_RESCALE_NORMAL);
213
214 glEnable(GL_COLOR_MATERIAL);
215
216 // Setup depth buffer
217 glClearDepth(1.0f);
218
219 // Set the depth buffer function
220 glDepthFunc(GL_LEQUAL);
221
222 // Enable vertex and and normal arrays
223 glEnableClientState(GL_VERTEX_ARRAY);
224 glEnableClientState(GL_NORMAL_ARRAY);
225
226 // Set correct perspective correction
227 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
228
229
230 // Create texture bitmap
231
230 for (int yc = 0; yc < THEIGHT; yc++) 232 for (int yc = 0; yc < THEIGHT; yc++)
231 { 233 {
232 Uint8 *dp = ((Uint8 *) texSrc) + yc * TWIDTH; 234 Uint8 *dp8 = ((Uint8 *) texSrc8) + yc * TWIDTH;
235
233 for (int xc = 0; xc < TWIDTH; xc++) 236 for (int xc = 0; xc < TWIDTH; xc++)
234 { 237 {
235 Uint8 col = dp[xc]; 238 Uint8 col = dp8[xc];
236 switch (col) 239 switch (col)
237 { 240 {
238 case '.': col = 0; break; 241 case '.': col = 0; break;
239 case '#': col = 255; break; 242 case '#': col = 255; break;
240 case '*': col = 128; break; 243 case '*': col = 128; break;
241 default: col = 192; break; 244 default: col = 192; break;
242 } 245 }
243 dp[xc] = col; 246 dp8[xc] = col;
244 } 247 }
245 } 248 }
246 249
247 // Upload to GPU texture 250 // Upload to GPU texture
248 glGenTextures(1, &tex); 251 glGenTextures(1, &tex8);
249 glBindTexture(GL_TEXTURE_2D, tex); 252 glBindTexture(GL_TEXTURE_2D, tex8);
250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
251 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
252 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, TWIDTH, THEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texSrc); 255 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, TWIDTH, THEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texSrc8);
253 glBindTexture(GL_TEXTURE_2D, 0); 256 glBindTexture(GL_TEXTURE_2D, 0);
254 257
255 return checkErrors(); 258 return checkErrors();
256 } 259 }
257 260
368 glEnd(); 371 glEnd();
369 372
370 // Draw texture 373 // Draw texture
371 glColor3ub(0xff, 0xff, 0xff); 374 glColor3ub(0xff, 0xff, 0xff);
372 glEnable(GL_TEXTURE_2D); 375 glEnable(GL_TEXTURE_2D);
373 glBindTexture(GL_TEXTURE_2D, tex); 376 glBindTexture(GL_TEXTURE_2D, tex8);
374 glBegin(GL_QUADS); 377 glBegin(GL_QUADS);
375 float s = 0.50f; 378 float s = 0.50f;
376 glTexCoord2i(-1, 0); glVertex2f(0, 0); 379 glTexCoord2i(-1, 0); glVertex2f(0, 0);
377 glTexCoord2i( 0, 0); glVertex2f(s * 0.6f, 0); 380 glTexCoord2i( 0, 0); glVertex2f(s * 0.6f, 0);
378 glTexCoord2i( 0, -1); glVertex2f(s * 0.6f, s); 381 glTexCoord2i( 0, -1); glVertex2f(s * 0.6f, s);