display image to the screen as textured quad
| 278 | |
| 279 | // display image to the screen as textured quad |
| 280 | void displayImage(GLuint texture) |
| 281 | { |
| 282 | glBindTexture(GL_TEXTURE_2D, texture); |
| 283 | glEnable(GL_TEXTURE_2D); |
| 284 | glDisable(GL_DEPTH_TEST); |
| 285 | glDisable(GL_LIGHTING); |
| 286 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 287 | |
| 288 | glMatrixMode(GL_PROJECTION); |
| 289 | glPushMatrix(); |
| 290 | glLoadIdentity(); |
| 291 | glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); |
| 292 | |
| 293 | glMatrixMode(GL_MODELVIEW); |
| 294 | glLoadIdentity(); |
| 295 | |
| 296 | glViewport(0, 0, window_width, window_height); |
| 297 | |
| 298 | // if the texture is a 8 bits UI, scale the fetch with a GLSL shader |
| 299 | #ifndef USE_TEXSUBIMAGE2D |
| 300 | glUseProgram(shDrawTex); |
| 301 | GLint id = glGetUniformLocation(shDrawTex, "texImage"); |
| 302 | glUniform1i(id, 0); // texture unit 0 to "texImage" |
| 303 | SDK_CHECK_ERROR_GL(); |
| 304 | #endif |
| 305 | |
| 306 | glBegin(GL_QUADS); |
| 307 | glTexCoord2f(0.0, 0.0); |
| 308 | glVertex3f(-1.0, -1.0, 0.5); |
| 309 | glTexCoord2f(1.0, 0.0); |
| 310 | glVertex3f(1.0, -1.0, 0.5); |
| 311 | glTexCoord2f(1.0, 1.0); |
| 312 | glVertex3f(1.0, 1.0, 0.5); |
| 313 | glTexCoord2f(0.0, 1.0); |
| 314 | glVertex3f(-1.0, 1.0, 0.5); |
| 315 | glEnd(); |
| 316 | |
| 317 | glMatrixMode(GL_PROJECTION); |
| 318 | glPopMatrix(); |
| 319 | |
| 320 | glDisable(GL_TEXTURE_2D); |
| 321 | |
| 322 | #ifndef USE_TEXSUBIMAGE2D |
| 323 | glUseProgram(0); |
| 324 | #endif |
| 325 | SDK_CHECK_ERROR_GL(); |
| 326 | } |
| 327 | |
| 328 | //////////////////////////////////////////////////////////////////////////////// |
| 329 | //! Display callback |