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

Function initGL

cpp/5_Domain_Specific/postProcessGL/main.cpp:1010–1055  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

1008//! Initialize GL
1009////////////////////////////////////////////////////////////////////////////////
1010bool initGL(int *argc, char **argv)
1011{
1012 // Create GL context
1013 glutInit(argc, argv);
1014 glutInitDisplayMode(GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE | GLUT_DEPTH);
1015 glutInitWindowSize(window_width, window_height);
1016 iGLUTWindowHandle = glutCreateWindow("CUDA OpenGL post-processing");
1017
1018 // initialize necessary OpenGL extensions
1019 if (!isGLVersionSupported(2, 0)
1020 || !areGLExtensionsSupported("GL_ARB_pixel_buffer_object "
1021 "GL_EXT_framebuffer_object")) {
1022 printf("ERROR: Support for necessary OpenGL extensions missing.");
1023 fflush(stderr);
1024 return false;
1025 }
1026
1027// default initialization
1028#ifndef USE_TEXTURE_RGBA8UI
1029 glClearColor(0.5, 0.5, 0.5, 1.0);
1030#else
1031 glClearColorIuiEXT(128, 128, 128, 255);
1032#endif
1033 glDisable(GL_DEPTH_TEST);
1034
1035 // viewport
1036 glViewport(0, 0, window_width, window_height);
1037
1038 // projection
1039 glMatrixMode(GL_PROJECTION);
1040 glLoadIdentity();
1041 gluPerspective(60.0, (GLfloat)window_width / (GLfloat)window_height, 0.1f, 10.0f);
1042
1043 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
1044
1045 glEnable(GL_LIGHT0);
1046 float red[] = {1.0f, 0.1f, 0.1f, 1.0f};
1047 float white[] = {1.0f, 1.0f, 1.0f, 1.0f};
1048 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red);
1049 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, white);
1050 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 60.0f);
1051
1052 SDK_CHECK_ERROR_GL();
1053
1054 return true;
1055}

Callers 1

runStdProgramFunction · 0.70

Calls 2

isGLVersionSupportedFunction · 0.85
areGLExtensionsSupportedFunction · 0.85

Tested by

no test coverage detected