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

Function initGL

cpp/0_Introduction/simpleCUDA2GL/main.cpp:703–748  ·  view source on GitHub ↗

/////////////////////////////////////////////////////////////////////////// Initialize GL ///////////////////////////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

701//! Initialize GL
702////////////////////////////////////////////////////////////////////////////////
703bool initGL(int *argc, char **argv)
704{
705 // Create GL context
706 glutInit(argc, argv);
707 glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH);
708 glutInitWindowSize(window_width, window_height);
709 iGLUTWindowHandle = glutCreateWindow("CUDA OpenGL post-processing");
710
711 // initialize necessary OpenGL extensions
712 if (!isGLVersionSupported(2, 0)
713 || !areGLExtensionsSupported("GL_ARB_pixel_buffer_object "
714 "GL_EXT_framebuffer_object")) {
715 printf("ERROR: Support for necessary OpenGL extensions missing.");
716 fflush(stderr);
717 return false;
718 }
719
720// default initialization
721#ifndef USE_TEXTURE_RGBA8UI
722 glClearColor(0.5, 0.5, 0.5, 1.0);
723#else
724 glClearColorIuiEXT(128, 128, 128, 255);
725#endif
726 glDisable(GL_DEPTH_TEST);
727
728 // viewport
729 glViewport(0, 0, window_width, window_height);
730
731 // projection
732 glMatrixMode(GL_PROJECTION);
733 glLoadIdentity();
734 gluPerspective(60.0, (GLfloat)window_width / (GLfloat)window_height, 0.1f, 10.0f);
735
736 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
737
738 glEnable(GL_LIGHT0);
739 float red[] = {1.0f, 0.1f, 0.1f, 1.0f};
740 float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
741 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
742 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
743 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0f);
744
745 SDK_CHECK_ERROR_GL();
746
747 return true;
748}

Callers 1

runStdProgramFunction · 0.70

Calls 2

isGLVersionSupportedFunction · 0.85
areGLExtensionsSupportedFunction · 0.85

Tested by

no test coverage detected