MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / displayImage

Function displayImage

cpp/5_Domain_Specific/postProcessGL/main.cpp:392–438  ·  view source on GitHub ↗

display image to the screen as textured quad

Source from the content-addressed store, hash-verified

390
391// display image to the screen as textured quad
392void displayImage(GLuint texture)
393{
394 glBindTexture(GL_TEXTURE_2D, texture);
395 glEnable(GL_TEXTURE_2D);
396 glDisable(GL_DEPTH_TEST);
397 glDisable(GL_LIGHTING);
398 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
399
400 glMatrixMode(GL_PROJECTION);
401 glPushMatrix();
402 glLoadIdentity();
403 glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
404
405 glMatrixMode(GL_MODELVIEW);
406 glLoadIdentity();
407
408 glViewport(0, 0, window_width, window_height);
409
410// if the texture is a 8 bits UI, scale the fetch with a GLSL shader
411#ifndef USE_TEXSUBIMAGE2D
412 glUseProgram(shDrawTex);
413 GLint id = glGetUniformLocation(shDrawTex, "texImage");
414 glUniform1i(id, 0); // texture unit 0 to "texImage"
415 SDK_CHECK_ERROR_GL();
416#endif
417
418 glBegin(GL_QUADS);
419 glTexCoord2f(0.0, 0.0);
420 glVertex3f(-1.0, -1.0, 0.5);
421 glTexCoord2f(1.0, 0.0);
422 glVertex3f(1.0, -1.0, 0.5);
423 glTexCoord2f(1.0, 1.0);
424 glVertex3f(1.0, 1.0, 0.5);
425 glTexCoord2f(0.0, 1.0);
426 glVertex3f(-1.0, 1.0, 0.5);
427 glEnd();
428
429 glMatrixMode(GL_PROJECTION);
430 glPopMatrix();
431
432 glDisable(GL_TEXTURE_2D);
433
434#ifndef USE_TEXSUBIMAGE2D
435 glUseProgram(0);
436#endif
437 SDK_CHECK_ERROR_GL();
438}
439
440////////////////////////////////////////////////////////////////////////////////
441//! Display callback

Callers 1

displayFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected