void GL3GraphicContextProvider::check_opengl_version() { int version_major = 0; int version_minor = 0; get_opengl_version(version_major, version_minor); if (version_major < 3) throw Exception(string_format("This application requires OpenGL 3.0 or above. Your hardware only supports OpenGL %1.%2. Try updating your drivers, or upgrade to a newer graphics card.", version_major, version_minor)); }
void GL1GraphicContextProvider::check_opengl_version() { int version_major = 0; int version_minor = 0; int version_release = 0; get_opengl_version(version_major, version_minor, version_release); bool valid_version = false; if (version_major > 1) valid_version = true; if ((version_major == 1) && (version_minor >= 3)) valid_version = true; if (!valid_version) throw Exception(string_format("This application requires OpenGL 1.3. Your hardware only supports OpenGL %1.%2.%3. Try updating your drivers, or upgrade to a newer graphics card.", version_major, version_minor, version_release)); }
void OpenGLWindowProvider::create(DisplayWindowSite *new_site, const DisplayWindowDescription &desc) { window_handle = desc.get_handle(); if (window_handle.window == nullptr) throw Exception("Window handle must exist in the display description"); ANativeWindow *window = window_handle.window; const EGLint attribs[] = { EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_BLUE_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_RED_SIZE, 8, EGL_NONE }; EGLint format; EGLint numConfigs; EGLConfig config; display = eglGetDisplay(EGL_DEFAULT_DISPLAY); eglInitialize(display, 0, 0); /* Here, the application chooses the configuration it desires. In this * sample, we have a very simplified selection process, where we pick * the first EGLConfig that matches our criteria */ if (!eglChooseConfig(display, attribs, &config, 1, &numConfigs)) throw Exception("eglChooseConfig failed"); if (numConfigs < 1) throw Exception("Found configs failed"); /* EGL_NATIVE_VISUAL_ID is an attribute of the EGLConfig that is * guaranteed to be accepted by ANativeWindow_setBuffersGeometry(). * As soon as we picked a EGLConfig, we can safely reconfigure the * ANativeWindow buffers to match, using EGL_NATIVE_VISUAL_ID. */ eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); ANativeWindow_setBuffersGeometry(window, 0, 0, format); surface = eglCreateWindowSurface(display, config, window, NULL); if (surface == EGL_NO_SURFACE) throw Exception("eglCreateWindowSurface failed"); context = eglCreateContext(display, config, NULL, NULL); if (context == EGL_NO_CONTEXT) throw Exception("eglCreateWindowSurface failed"); if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { throw Exception("Unable to eglMakeCurrent"); } bool use_gl3; int desc_version_major = opengl_desc.get_version_major(); int desc_version_minor = opengl_desc.get_version_minor(); // Do not attempt GL3, if not requested that version if (desc_version_major < 3) { use_gl3 = false; } else if (!opengl_desc.get_allow_lower_versions()) // Else, if we do not allow lower versions, only attempt GL3 { use_gl3 = true; } else { // Choose the target depending on the current opengl version int gl_version_major; int gl_version_minor; get_opengl_version(gl_version_major, gl_version_minor); if (gl_version_major < 3) { use_gl3 = false; } else { use_gl3 = true; } } if (use_gl3) { using_gl3 = true; gc = GraphicContext(new GL3GraphicContextProvider(this)); } else { using_gl3 = false; gc = GraphicContext(new GL1GraphicContextProvider(this)); } swap_interval = desc.get_swap_interval(); if (swap_interval != -1) eglSwapInterval(display, swap_interval); }
void OpenGLWindowProvider::create(DisplayWindowSite *new_site, const DisplayWindowDescription &desc) { site = new_site; fullscreen = desc.is_fullscreen(); win32_window.create(site, desc); if (!opengl_context) { HWND handle = win32_window.get_hwnd(); dwm_layered = false; if (desc.is_layered() && !DwmFunctions::is_composition_enabled()) { create_shadow_window(handle); } else { if (desc.is_layered()) dwm_layered = true; } desc.is_layered() ? double_buffered = false : double_buffered = true; // Only can use Layered windows that are single buffered with OpenGL (via shadow window) ( PFD_DOUBLEBUFFER_DONTCARE set in OpenGLCreationHelper::set_multisampling_pixel_format) device_context = GetDC(handle); HGLRC share_context = get_share_context(); OpenGLCreationHelper helper(handle, device_context); helper.set_multisampling_pixel_format(desc); int gl_major = opengl_desc.get_version_major(); int gl_minor = opengl_desc.get_version_minor(); if (opengl_desc.get_allow_lower_versions() == false) { opengl_context = helper.create_opengl3_context(share_context, gl_major, gl_minor, opengl_desc); if (!opengl_context) throw Exception(string_format("This application requires OpenGL %1.%2 or above. Try updating your drivers, or upgrade to a newer graphics card.", gl_major, gl_minor)); } else { static const char opengl_version_list[] = { // Clanlib supported version pairs 4, 5, 4, 4, 4, 3, 4, 2, 4, 1, 4, 0, 3, 3, 3, 2, 3, 1, 3, 0, 0, 0, // End of list }; const char *opengl_version_list_ptr = opengl_version_list; do { int major = *(opengl_version_list_ptr++); if (major == 0) break; int minor = *(opengl_version_list_ptr++); // Find the appropriate version in the list if (major > gl_major) continue; if (major == gl_major) { if (minor > gl_minor) continue; } opengl_context = helper.create_opengl3_context(share_context, major, minor, opengl_desc); } while (!opengl_context); if (!opengl_context) opengl_context = helper.create_opengl2_context(share_context); if (!opengl_context) throw Exception("This application requires OpenGL. Try updating your drivers, or upgrade to a newer graphics card."); } bool use_gl3; int desc_version_major = opengl_desc.get_version_major(); int desc_version_minor = opengl_desc.get_version_minor(); // Do not attempt GL3, if not requested that version if (desc_version_major < 3) { use_gl3 = false; } else if (!opengl_desc.get_allow_lower_versions()) // Else, if we do not allow lower versions, only attempt GL3 { use_gl3 = true; } else { // Choose the target depending on the current opengl version int gl_version_major; int gl_version_minor; get_opengl_version(gl_version_major, gl_version_minor); if (gl_version_major < 3) { use_gl3 = false; } else { use_gl3 = true; } } if (use_gl3) { using_gl3 = true; gc = GraphicContext(new GL3GraphicContextProvider(this)); } else { using_gl3 = false; gc = GraphicContext(new GL1GraphicContextProvider(this)); } } wglSwapIntervalEXT = (ptr_wglSwapIntervalEXT)OpenGL::get_proc_address("wglSwapIntervalEXT"); swap_interval = desc.get_swap_interval(); if (wglSwapIntervalEXT && swap_interval != -1) wglSwapIntervalEXT(swap_interval); }
void InitOpenGL(void){ int type; int err; PRINTF("%s",_("Initializing OpenGL\n")); type = GLUT_RGB|GLUT_DEPTH; if(buffertype==GLUT_DOUBLE){ type |= GLUT_DOUBLE; } else{ type |= GLUT_SINGLE; } // glutInitDisplayMode(GLUT_STEREO); if(stereoactive==1){ if(glutGet(GLUT_DISPLAY_MODE_POSSIBLE)==1){ videoSTEREO=1; type |= GLUT_STEREO; } else{ videoSTEREO=0; fprintf(stderr,"*** Error: video hardware does not support stereo\n"); } } #ifdef _DEBUG PRINTF("%s",_(" Initializing Glut display mode - ")); #endif glutInitDisplayMode(type); #ifdef _DEBUG PRINTF("%s\n",_("initialized")); #endif CheckMemory; #ifdef _DEBUG PRINTF("%s\n",_(" creating window")); #endif mainwindow_id=glutCreateWindow(""); #ifdef _DEBUG PRINTF("%s\n",_(" window created")); #endif #ifdef _DEBUG PRINTF("%s",_(" Initializing callbacks - ")); #endif glutSpecialUpFunc(specialkeyboard_up_CB); glutKeyboardUpFunc(keyboard_up_CB); glutKeyboardFunc(keyboard_CB); glutMouseFunc(mouse_CB); glutSpecialFunc(specialkeyboard_CB); glutMotionFunc(motion_CB); glutReshapeFunc(Reshape_CB); glutDisplayFunc(Display_CB); glutVisibilityFunc(NULL); glutMenuStatusFunc(MenuStatus_CB); #ifdef _DEBUG PRINTF("%s\n",_("initialized")); #endif opengl_version = get_opengl_version(opengl_version_label); err=0; #ifdef pp_GPU err=glewInit(); if(err==GLEW_OK){ err=0; } else{ PRINTF(" GLEW initialization failed\n"); err=1; } if(err==0){ if(disable_gpu==1){ err=1; } else{ err=init_shaders(); } #ifdef _DEBUG if(err==0){ PRINTF("%s\n",_(" GPU shader initialization succeeded")); } #endif if(err!=0){ PRINTF("%s\n",_(" GPU shader initialization failed")); } } #endif #ifdef pp_CULL if(err==0){ err=init_cull_exts(); #ifdef _DEBUG if(err==0){ PRINTF("%s\n",_(" Culling extension initialization succeeded")); } #endif if(err!=0){ PRINTF("%s\n",_(" Culling extension initialization failed")); } } #endif light_position0[0]=1.0f; light_position0[1]=1.0f; light_position0[2]=4.0f; light_position0[3]=0.f; light_position1[0]=-1.0f; light_position1[1]=1.0f; light_position1[2]=4.0f; light_position1[3]=0.f; glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE); updateLights(light_position0,light_position1); { glGetIntegerv(GL_RED_BITS,&nredbits); glGetIntegerv(GL_GREEN_BITS,&ngreenbits); glGetIntegerv(GL_BLUE_BITS,&nbluebits); nredshift = 8 - nredbits; if(nredshift<0)nredshift=0; ngreenshift = 8 - ngreenbits; if(ngreenshift<0)ngreenshift=0; nblueshift=8-nbluebits; if(nblueshift<0)nblueshift=0; } opengldefined=1; PRINTF("%s",_("OpenGL initialization completed\n\n")); }