Mercurial > hg > forks > gldragon
comparison dmglrender.cpp @ 91:4df8a7337e3e
Add simple 32bit texture version.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 18 Jan 2021 12:23:48 +0200 |
parents | 3863ad92f8d8 |
children | 28dd29f3a65f |
comparison
equal
deleted
inserted
replaced
90:3863ad92f8d8 | 91:4df8a7337e3e |
---|---|
175 "########" | 175 "########" |
176 "##....##" | 176 "##....##" |
177 "##....##" | 177 "##....##" |
178 "##....##"; | 178 "##....##"; |
179 | 179 |
180 static Uint32 texSrc32[TWIDTH * THEIGHT]; | |
181 | |
180 | 182 |
181 bool DMGLSimpleRenderer::initRenderer2(void) | 183 bool DMGLSimpleRenderer::initRenderer2(void) |
182 { | 184 { |
183 // Dump some information | 185 // Dump some information |
184 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR)); | 186 dmMsg("GL_VENDOR : %s\n", glGetString(GL_VENDOR)); |
226 // Set correct perspective correction | 228 // Set correct perspective correction |
227 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | 229 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); |
228 | 230 |
229 | 231 |
230 // Create texture bitmap | 232 // Create texture bitmap |
231 | |
232 for (int yc = 0; yc < THEIGHT; yc++) | 233 for (int yc = 0; yc < THEIGHT; yc++) |
233 { | 234 { |
234 Uint8 *dp8 = ((Uint8 *) texSrc8) + yc * TWIDTH; | 235 Uint8 *dp8 = ((Uint8 *) texSrc8) + yc * TWIDTH; |
236 Uint32 *dp32 = ((Uint32 *) texSrc32) + yc * TWIDTH; | |
235 | 237 |
236 for (int xc = 0; xc < TWIDTH; xc++) | 238 for (int xc = 0; xc < TWIDTH; xc++) |
237 { | 239 { |
238 Uint8 col = dp8[xc]; | 240 Uint8 col = dp8[xc]; |
239 switch (col) | 241 switch (col) |
242 case '#': col = 255; break; | 244 case '#': col = 255; break; |
243 case '*': col = 128; break; | 245 case '*': col = 128; break; |
244 default: col = 192; break; | 246 default: col = 192; break; |
245 } | 247 } |
246 dp8[xc] = col; | 248 dp8[xc] = col; |
249 dp32[xc] = col | (col << 8) | (col << 16); | |
247 } | 250 } |
248 } | 251 } |
249 | 252 |
250 // Upload to GPU texture | 253 // Upload to GPU texture |
251 glGenTextures(1, &tex8); | 254 glGenTextures(1, &tex8); |
253 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | 256 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
254 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | 257 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
255 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, TWIDTH, THEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texSrc8); | 258 glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, TWIDTH, THEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texSrc8); |
256 glBindTexture(GL_TEXTURE_2D, 0); | 259 glBindTexture(GL_TEXTURE_2D, 0); |
257 | 260 |
261 glGenTextures(2, &tex32); | |
262 glBindTexture(GL_TEXTURE_2D, tex32); | |
263 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); | |
264 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); | |
265 glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TWIDTH, THEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, texSrc32); | |
266 glBindTexture(GL_TEXTURE_2D, 0); | |
267 | |
258 return checkErrors(); | 268 return checkErrors(); |
259 } | 269 } |
260 | 270 |
261 | 271 |
262 bool DMGLSimpleRenderer::compileModelShaders(DMModel &model) | 272 bool DMGLSimpleRenderer::compileModelShaders(DMModel &model) |
341 } | 351 } |
342 | 352 |
343 | 353 |
344 void DMGLSimpleRenderer::drawScene(const DMSimpleScene &scene, const float time) | 354 void DMGLSimpleRenderer::drawScene(const DMSimpleScene &scene, const float time) |
345 { | 355 { |
356 float qx, qy, qw, qh; | |
357 | |
346 glClear(GL_DEPTH_BUFFER_BIT); | 358 glClear(GL_DEPTH_BUFFER_BIT); |
347 | 359 |
348 glMatrixMode(GL_PROJECTION); | 360 glMatrixMode(GL_PROJECTION); |
349 glPushMatrix(); | 361 glPushMatrix(); |
350 glLoadIdentity(); | 362 glLoadIdentity(); |
368 glVertex2f(1.0f, 1.0f); | 380 glVertex2f(1.0f, 1.0f); |
369 glVertex2f(0.0f, 1.0f); | 381 glVertex2f(0.0f, 1.0f); |
370 } | 382 } |
371 glEnd(); | 383 glEnd(); |
372 | 384 |
373 // Draw texture | 385 // Draw texture #1 |
374 glColor3ub(0xff, 0xff, 0xff); | 386 glColor3ub(0xff, 0xff, 0xff); |
387 | |
388 qh = 0.35f; | |
389 qw = qh * 0.6f; | |
390 qx = 0; | |
391 qy = 0; | |
392 | |
375 glEnable(GL_TEXTURE_2D); | 393 glEnable(GL_TEXTURE_2D); |
376 glBindTexture(GL_TEXTURE_2D, tex8); | 394 glBindTexture(GL_TEXTURE_2D, tex8); |
377 glBegin(GL_QUADS); | 395 glBegin(GL_QUADS); |
378 float s = 0.50f; | 396 glTexCoord2i(-1, 0); glVertex2f(qx , qy); |
379 glTexCoord2i(-1, 0); glVertex2f(0, 0); | 397 glTexCoord2i( 0, 0); glVertex2f(qx + qw, qy); |
380 glTexCoord2i( 0, 0); glVertex2f(s * 0.6f, 0); | 398 glTexCoord2i( 0, -1); glVertex2f(qx + qw, qy + qh); |
381 glTexCoord2i( 0, -1); glVertex2f(s * 0.6f, s); | 399 glTexCoord2i(-1, -1); glVertex2f(qx , qy + qh); |
382 glTexCoord2i(-1, -1); glVertex2f(0, s); | 400 glEnd(); |
401 | |
402 // Draw texture #2 | |
403 qh = 0.25f; | |
404 qw = qh * 0.6f; | |
405 qx = 1.0f - qw; | |
406 qy = 1.0f - qh; | |
407 | |
408 glBindTexture(GL_TEXTURE_2D, tex32); | |
409 glBegin(GL_QUADS); | |
410 glTexCoord2i(-1, 0); glVertex2f(qx , qy); | |
411 glTexCoord2i( 0, 0); glVertex2f(qx + qw, qy); | |
412 glTexCoord2i( 0, -1); glVertex2f(qx + qw, qy + qh); | |
413 glTexCoord2i(-1, -1); glVertex2f(qx , qy + qh); | |
383 glEnd(); | 414 glEnd(); |
384 glBindTexture(GL_TEXTURE_2D, 0); | 415 glBindTexture(GL_TEXTURE_2D, 0); |
385 glDisable(GL_TEXTURE_2D); | 416 glDisable(GL_TEXTURE_2D); |
386 | 417 |
387 // Restore the 3D projection | 418 // Restore the 3D projection |