# HG changeset patch # User Matti Hamalainen # Date 1610965428 -7200 # Node ID 4df8a7337e3e650bc8df9976b1057535193d2fd4 # Parent 3863ad92f8d86fde1208a2c9e9b2be2a91a1fa70 Add simple 32bit texture version. diff -r 3863ad92f8d8 -r 4df8a7337e3e dmglrender.cpp --- a/dmglrender.cpp Tue Jan 12 14:33:18 2021 +0200 +++ b/dmglrender.cpp Mon Jan 18 12:23:48 2021 +0200 @@ -177,6 +177,8 @@ "##....##" "##....##"; +static Uint32 texSrc32[TWIDTH * THEIGHT]; + bool DMGLSimpleRenderer::initRenderer2(void) { @@ -228,10 +230,10 @@ // Create texture bitmap - for (int yc = 0; yc < THEIGHT; yc++) { Uint8 *dp8 = ((Uint8 *) texSrc8) + yc * TWIDTH; + Uint32 *dp32 = ((Uint32 *) texSrc32) + yc * TWIDTH; for (int xc = 0; xc < TWIDTH; xc++) { @@ -244,6 +246,7 @@ default: col = 192; break; } dp8[xc] = col; + dp32[xc] = col | (col << 8) | (col << 16); } } @@ -255,6 +258,13 @@ glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, TWIDTH, THEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texSrc8); glBindTexture(GL_TEXTURE_2D, 0); + glGenTextures(2, &tex32); + glBindTexture(GL_TEXTURE_2D, tex32); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, TWIDTH, THEIGHT, 0, GL_RGBA, GL_UNSIGNED_BYTE, texSrc32); + glBindTexture(GL_TEXTURE_2D, 0); + return checkErrors(); } @@ -343,6 +353,8 @@ void DMGLSimpleRenderer::drawScene(const DMSimpleScene &scene, const float time) { + float qx, qy, qw, qh; + glClear(GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); @@ -370,16 +382,35 @@ } glEnd(); - // Draw texture + // Draw texture #1 glColor3ub(0xff, 0xff, 0xff); + + qh = 0.35f; + qw = qh * 0.6f; + qx = 0; + qy = 0; + glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, tex8); glBegin(GL_QUADS); - float s = 0.50f; - glTexCoord2i(-1, 0); glVertex2f(0, 0); - glTexCoord2i( 0, 0); glVertex2f(s * 0.6f, 0); - glTexCoord2i( 0, -1); glVertex2f(s * 0.6f, s); - glTexCoord2i(-1, -1); glVertex2f(0, s); + glTexCoord2i(-1, 0); glVertex2f(qx , qy); + glTexCoord2i( 0, 0); glVertex2f(qx + qw, qy); + glTexCoord2i( 0, -1); glVertex2f(qx + qw, qy + qh); + glTexCoord2i(-1, -1); glVertex2f(qx , qy + qh); + glEnd(); + + // Draw texture #2 + qh = 0.25f; + qw = qh * 0.6f; + qx = 1.0f - qw; + qy = 1.0f - qh; + + glBindTexture(GL_TEXTURE_2D, tex32); + glBegin(GL_QUADS); + glTexCoord2i(-1, 0); glVertex2f(qx , qy); + glTexCoord2i( 0, 0); glVertex2f(qx + qw, qy); + glTexCoord2i( 0, -1); glVertex2f(qx + qw, qy + qh); + glTexCoord2i(-1, -1); glVertex2f(qx , qy + qh); glEnd(); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); diff -r 3863ad92f8d8 -r 4df8a7337e3e dmglrender.h --- a/dmglrender.h Tue Jan 12 14:33:18 2021 +0200 +++ b/dmglrender.h Mon Jan 18 12:23:48 2021 +0200 @@ -17,6 +17,7 @@ { SDL_GLContext sdlGLContext; GLuint tex8; + GLuint tex32; DMGLSimpleRenderer() {