Mercurial > hg > forks > gldragon
changeset 83:69d7349dc5d3
Render a textured quad with bitmap letter 'A' in the bottom left corner as
an additional test - this does not render correctly with Zink (on Intel
Haswell at least).
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 09 Mar 2020 09:40:28 +0200 |
parents | 91a2868260bf |
children | 7747659639b6 |
files | dmglrender.cpp dmglrender.h |
diffstat | 2 files changed, 54 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/dmglrender.cpp Mon Mar 09 09:21:55 2020 +0200 +++ b/dmglrender.cpp Mon Mar 09 09:40:28 2020 +0200 @@ -213,6 +213,45 @@ // Set correct perspective correction glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); + + // Create texture bitmap +#define TWIDTH 8 +#define THEIGHT 8 + char texSrc[TWIDTH * THEIGHT + 1] = + "..%##%.." + ".%####%." + "%#*..*#%" + "##....##" + "########" + "##....##" + "##....##" + "##....##"; + + for (int yc = 0; yc < THEIGHT; yc++) + { + Uint8 *dp = ((Uint8 *) texSrc) + yc * TWIDTH; + for (int xc = 0; xc < TWIDTH; xc++) + { + Uint8 col = dp[xc]; + switch (col) + { + case '.': col = 0; break; + case '#': col = 255; break; + case '*': col = 128; break; + default: col = 192; break; + } + dp[xc] = col; + } + } + + // Upload to GPU texture + glGenTextures(1, &tex); + glBindTexture(GL_TEXTURE_2D, tex); + 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_LUMINANCE, TWIDTH, THEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, texSrc); + glBindTexture(GL_TEXTURE_2D, 0); + return checkErrors(); } @@ -328,6 +367,20 @@ } glEnd(); + // Draw texture + glColor3ub(0xff, 0xff, 0xff); + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, tex); + 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); + glEnd(); + glBindTexture(GL_TEXTURE_2D, 0); + glDisable(GL_TEXTURE_2D); + // Restore the 3D projection glMatrixMode(GL_PROJECTION); glPopMatrix();