comparison dmglrender.cpp @ 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 701bef61dcf1
children 3863ad92f8d8
comparison
equal deleted inserted replaced
82:91a2868260bf 83:69d7349dc5d3
211 glEnableClientState(GL_NORMAL_ARRAY); 211 glEnableClientState(GL_NORMAL_ARRAY);
212 212
213 // Set correct perspective correction 213 // Set correct perspective correction
214 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); 214 glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
215 215
216
217 // Create texture bitmap
218 #define TWIDTH 8
219 #define THEIGHT 8
220 char texSrc[TWIDTH * THEIGHT + 1] =
221 "..%##%.."
222 ".%####%."
223 "%#*..*#%"
224 "##....##"
225 "########"
226 "##....##"
227 "##....##"
228 "##....##";
229
230 for (int yc = 0; yc < THEIGHT; yc++)
231 {
232 Uint8 *dp = ((Uint8 *) texSrc) + yc * TWIDTH;
233 for (int xc = 0; xc < TWIDTH; xc++)
234 {
235 Uint8 col = dp[xc];
236 switch (col)
237 {
238 case '.': col = 0; break;
239 case '#': col = 255; break;
240 case '*': col = 128; break;
241 default: col = 192; break;
242 }
243 dp[xc] = col;
244 }
245 }
246
247 // Upload to GPU texture
248 glGenTextures(1, &tex);
249 glBindTexture(GL_TEXTURE_2D, tex);
250 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
251 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);
253 glBindTexture(GL_TEXTURE_2D, 0);
254
216 return checkErrors(); 255 return checkErrors();
217 } 256 }
218 257
219 258
220 bool DMGLSimpleRenderer::compileModelShaders(DMModel &model) 259 bool DMGLSimpleRenderer::compileModelShaders(DMModel &model)
326 glVertex2f(1.0f, 1.0f); 365 glVertex2f(1.0f, 1.0f);
327 glVertex2f(0.0f, 1.0f); 366 glVertex2f(0.0f, 1.0f);
328 } 367 }
329 glEnd(); 368 glEnd();
330 369
370 // Draw texture
371 glColor3ub(0xff, 0xff, 0xff);
372 glEnable(GL_TEXTURE_2D);
373 glBindTexture(GL_TEXTURE_2D, tex);
374 glBegin(GL_QUADS);
375 float s = 0.50f;
376 glTexCoord2i(-1, 0); glVertex2f(0, 0);
377 glTexCoord2i( 0, 0); glVertex2f(s * 0.6f, 0);
378 glTexCoord2i( 0, -1); glVertex2f(s * 0.6f, s);
379 glTexCoord2i(-1, -1); glVertex2f(0, s);
380 glEnd();
381 glBindTexture(GL_TEXTURE_2D, 0);
382 glDisable(GL_TEXTURE_2D);
383
331 // Restore the 3D projection 384 // Restore the 3D projection
332 glMatrixMode(GL_PROJECTION); 385 glMatrixMode(GL_PROJECTION);
333 glPopMatrix(); 386 glPopMatrix();
334 387
335 glMatrixMode(GL_MODELVIEW); 388 glMatrixMode(GL_MODELVIEW);