void GLSupport::initializeExtensions() { glewContextInit(this); glGetError(); // Set version string const GLubyte* pcVer = glGetString(GL_VERSION); assert(pcVer && "Problems getting GL version string using glGetString"); String tmpStr = (const char*)pcVer; mVersion = tmpStr.substr(0, tmpStr.find(" ")); // Get vendor const GLubyte* pcVendor = glGetString(GL_VENDOR); tmpStr = (const char*)pcVendor; mVendor = tmpStr.substr(0, tmpStr.find(" ")); // Set extension list int numExtensions = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &numExtensions); for (int i = 0; i < numExtensions; i++) { extensionList.insert(String((char*)glGetStringi(GL_EXTENSIONS, i))); } }
GLenum GLEWAPIENTRY glewInit (void) { GLenum r; r = glewContextInit(); if ( r != 0 ) return r; #if defined(_WIN32) return wglewInit(); #elif !defined(__ANDROID__) && !defined(__native_client__) && !defined(__HAIKU__) && (!defined(__APPLE__) || defined(GLEW_APPLE_GLX)) /* _UNIX */ return glxewInit(); #else return r; #endif /* _WIN32 */ }
GLenum glewInit () { GLenum r; if ( (r = glewContextInit()) ) return r; #if defined(GLEW_USE_LIB_ES) # if defined (GLEW_INC_EGL) return eglewContextInit(); # endif #elif defined(_WIN32) return wglewContextInit(); #elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) /* _UNIX */ return glxewContextInit(); #endif /* GLEW_USE_LIB_ES */ return r; }
Renderer::Renderer( RessourceManager const& mgr ) : mGlewContext( new GLEWContext ), mManager( mgr ) { GLenum success = glewContextInit( mGlewContext.get() ); if ( success != GLEW_OK ) { throw std::exception( "could not create GLEW context" ); } else { success = glewInit(); if ( success != GLEW_OK ) { throw std::exception( "could not initialize GLEW" ); } } }
Context::Context( RenderSettings const& s, RessourceManager const& mgr ) : mManager( mgr ), mGlewContext( new GLEWContext ), mSfContext( sf::ContextSettings( s.depthBits, s.stencilBits, s.aaSamples, s.glMajor, s.glMinor ), s.width, s.height ) { GLenum success = glewContextInit( mGlewContext.get() ); if ( success != GLEW_OK ) { throw std::exception( "could not create GLEW context" ); } else { success = glewInit(); if ( success != GLEW_OK ) { throw std::exception( "could not initialize GLEW" ); } } }
GLenum GLEWAPIENTRY glewInit (void) { GLenum r; #if defined(GLEW_EGL) PFNEGLGETCURRENTDISPLAYPROC getCurrentDisplay = NULL; #endif r = glewContextInit(); if ( r != 0 ) return r; #if defined(GLEW_EGL) getCurrentDisplay = (PFNEGLGETCURRENTDISPLAYPROC) glewGetProcAddress("eglGetCurrentDisplay"); return eglewInit(getCurrentDisplay()); #elif defined(GLEW_OSMESA) || defined(__ANDROID__) || defined(__native_client__) || defined(__HAIKU__) return r; #elif defined(_WIN32) return wglewInit(); #elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) /* _UNIX */ return glxewInit(); #else return r; #endif /* _WIN32 */ }
//\brief // initialize the gl extension functions address. static bool InitializeGlew() { GLenum err; GLContext ctx; /* create OpenGL rendering context */ InitContext(&ctx); if (GL_TRUE == CreateContext(&ctx)) { std::cout << "Error: CreateContext failed" << std::endl; DestroyContext(&ctx); return false; } /* initialize GLEW */ glewExperimental = GL_TRUE; #ifdef GLEW_MX err = glewContextInit(glewGetContext()); # ifdef _WIN32 err = err || wglewContextInit(wglewGetContext()); # elif !defined(__APPLE__) && !defined(__HAIKU__) || defined(GLEW_APPLE_GLX) err = err || glxewContextInit(glxewGetContext()); # endif #else err = glewInit(); #endif if (GLEW_OK != err) { std::cout << "Error [main]: glewInit failed: " << glewGetErrorString(err) << std::endl; DestroyContext(&ctx); return false; } DestroyContext(&ctx); return true; }
int main (int argc, char** argv) { GLuint err; struct createParams params = { #if defined(__OSMESA__) -1, /* bit depth */ #elif defined(_WIN32) -1, /* pixelformat */ #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) "", /* display */ -1, /* visual */ #endif 0, /* major */ 0, /* minor */ 0, /* profile mask */ 0 /* flags */ }; if (glewParseArgs(argc-1, argv+1, ¶ms)) { fprintf(stderr, "Usage: glewinfo " #if defined(__OSMESA__) #elif defined(_WIN32) "[-pf <pixelformat>] " #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) "[-display <display>] " "[-visual <visual id>] " #endif "[-version <OpenGL version>] " "[-profile core|compatibility] " "[-flag debug|forward]" "\n"); return 1; } if (GL_TRUE == glewCreateContext(¶ms)) { fprintf(stderr, "Error: glewCreateContext failed\n"); glewDestroyContext(); return 1; } glewExperimental = GL_TRUE; #ifdef GLEW_MX err = glewContextInit(glewGetContext()); #if defined(__OSMESA__) err = err || osmewContextInit(osmewGetContext()); #elif defined(_WIN32) err = err || wglewContextInit(wglewGetContext()); #elif !defined(__HAIKU__) && !defined(__APPLE__) || defined(GLEW_APPLE_GLX) err = err || glxewContextInit(glxewGetContext()); #endif #else err = glewInit(); #endif if (GLEW_OK != err) { fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err)); glewDestroyContext(); return 1; } #if defined(_WIN32) #if defined(_MSC_VER) && (_MSC_VER >= 1400) if (fopen_s(&f, "glewinfo.txt", "w") != 0) f = stdout; #else f = fopen("glewinfo.txt", "w"); #endif /* _MSC_VER */ if (f == NULL) f = stdout; #else f = stdout; #endif /* _WIN32 */ fprintf(f, "---------------------------\n"); fprintf(f, " GLEW Extension Info\n"); fprintf(f, "---------------------------\n\n"); fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION)); #if defined(__OSMESA__) fprintf(f, "Reporting capabilitiees of OSMesa\n"); #elif defined(_WIN32) fprintf(f, "Reporting capabilities of pixelformat %d\n", params.pixelformat); #elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n", params.display == NULL ? getenv("DISPLAY") : params.display, params.visual); #endif /* __OSMESA__ */ fprintf(f, "Running on a %s from %s\n", glGetString(GL_RENDERER), glGetString(GL_VENDOR)); fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION)); glewInfo(); #if defined(__OSMESA__) osmewInfo(); #elif defined(_WIN32) wglewInfo(); #else glxewInfo(); #endif /* __OSMESA__ */ if (f != stdout) fclose(f); glewDestroyContext(); return 0; }
int main (int argc, char** argv) { GLenum err; GLContext ctx; /* ---------------------------------------------------------------------- */ /* parse arguments */ if (GL_TRUE == ParseArgs(argc-1, argv+1)) { #if defined(_WIN32) fprintf(stderr, "Usage: visualinfo [-a] [-s] [-h] [-pf <id>]\n"); fprintf(stderr, " -a: show all visuals\n"); fprintf(stderr, " -s: display to stdout instead of visualinfo.txt\n"); fprintf(stderr, " -pf <id>: use given pixelformat\n"); fprintf(stderr, " -h: this screen\n"); #else fprintf(stderr, "Usage: visualinfo [-h] [-display <display>] [-visual <id>]\n"); fprintf(stderr, " -h: this screen\n"); fprintf(stderr, " -display <display>: use given display\n"); fprintf(stderr, " -visual <id>: use given visual\n"); #endif return 1; } /* ---------------------------------------------------------------------- */ /* create OpenGL rendering context */ InitContext(&ctx); if (GL_TRUE == CreateContext(&ctx)) { fprintf(stderr, "Error: CreateContext failed\n"); DestroyContext(&ctx); return 1; } /* ---------------------------------------------------------------------- */ /* initialize GLEW */ glewExperimental = GL_TRUE; #ifdef GLEW_MX err = glewContextInit(glewGetContext()); # ifdef _WIN32 err = err || wglewContextInit(wglewGetContext()); # elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) err = err || glxewContextInit(glxewGetContext()); # endif #else err = glewInit(); #endif if (GLEW_OK != err) { fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err)); DestroyContext(&ctx); return 1; } /* ---------------------------------------------------------------------- */ /* open file */ #if defined(_WIN32) if (!displaystdout) file = fopen("visualinfo.txt", "w"); if (file == NULL) file = stdout; #else file = stdout; #endif /* ---------------------------------------------------------------------- */ /* output header information */ /* OpenGL extensions */ fprintf(file, "OpenGL vendor string: %s\n", glGetString(GL_VENDOR)); fprintf(file, "OpenGL renderer string: %s\n", glGetString(GL_RENDERER)); fprintf(file, "OpenGL version string: %s\n", glGetString(GL_VERSION)); fprintf(file, "OpenGL extensions (GL_): \n"); PrintExtensions((char*)glGetString(GL_EXTENSIONS)); /* GLU extensions */ fprintf(file, "GLU version string: %s\n", gluGetString(GLU_VERSION)); fprintf(file, "GLU extensions (GLU_): \n"); PrintExtensions((char*)gluGetString(GLU_EXTENSIONS)); /* ---------------------------------------------------------------------- */ /* extensions string */ #if defined(_WIN32) /* WGL extensions */ if (WGLEW_ARB_extensions_string || WGLEW_EXT_extensions_string) { fprintf(file, "WGL extensions (WGL_): \n"); PrintExtensions(wglGetExtensionsStringARB ? (char*)wglGetExtensionsStringARB(ctx.dc) : (char*)wglGetExtensionsStringEXT()); } #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX) #else /* GLX extensions */ fprintf(file, "GLX extensions (GLX_): \n"); PrintExtensions(glXQueryExtensionsString(glXGetCurrentDisplay(), DefaultScreen(glXGetCurrentDisplay()))); #endif /* ---------------------------------------------------------------------- */ /* enumerate all the formats */ VisualInfo(&ctx); /* ---------------------------------------------------------------------- */ /* release resources */ DestroyContext(&ctx); if (file != stdout) fclose(file); return 0; }
void j_init_context(j_context_t i_context){ glewContextInit(i_context); }
/* This is the main entry point for Matlab or Octave. It gets called by Matlab or Octave, handles first-time initialization, error handling and subfunction dispatching. */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { // Start of dispatcher: int i; GLenum err; // FreeGlut must be initialized, otherwise it will emergency abort the whole application. // These variables are needed for it: int noargs = 1; char dummyarg[] = "ptbmoglcore"; char *dummyargp = &dummyarg[0]; // see whether there's a string command if(nrhs<1 || !mxIsChar(prhs[0])) mogl_usageerr(); // get string command mxGetString(prhs[0],cmd,CMDLEN); // Special case. If we're called with the special command "PREINIT", then // we return immediately. moglcore('PREINIT') is called by ptbmoglinit.m // on M$-Windows in order to preload the moglcore Mex-file into Matlab while // the current working directory is set to ..MOGL/core/ . This way, the dynamic // linker can find our own local version of glut32.dll and link it against moglcore. // Without this trick, we would need to install glut32.dll into the Windows system // folder which requires admin privileges and makes installation of Psychtoolbox // more complicated on M$-Windows... if (strcmp(cmd, "PREINIT")==0) { glBeginLevel=0; goto moglreturn; } if (strcmp(cmd, "DUMMYMODE")==0) { if (nrhs<2 || mxGetScalar(prhs[1])<0) { mexErrMsgTxt("MOGL-ERROR: No dummy mode level or invalid level (<0) given for subcommand DUMMYMODE!"); } dummymode = (int) mxGetScalar(prhs[1]); if (dummymode>0) printf("MOGL-INFO: Switched to dummy mode level %i.\n", dummymode); goto moglreturn; } // Special command to set MOGL debug level: // debuglevel = 0 --> Shut up in any case, leave error-handling to higher-level code. // debuglevel > 0 --> Check for OpenGL error conditions. // debuglevel > 0 --> Output glError()'s in clear-text and abort. Output GLSL errors and abort. // debuglevel > 1 --> Output GLSL diagnostic messages as well. // debuglevel > 2 --> Be very verbose! if (strcmp(cmd, "DEBUGLEVEL")==0) { if (nrhs<2 || mxGetScalar(prhs[1])<0) { mexErrMsgTxt("MOGL-ERROR: No debuglevel or invalid debuglevel (<0) given for subcommand DEBUGLEVEL!"); } debuglevel = (int) mxGetScalar(prhs[1]); goto moglreturn; } // Special cleanup subcommand needed for GNU/Octave: See explanation below in firstTime init. if (strcmp(cmd, "JettisonModuleHelper")==0) { goto moglreturn; } // Abort here if dummymode >= 10: Input arg. processing run, but no real // command parsing and processing; if (dummymode >= 10) { printf("MOGL-INFO: Dummy call to %s() - Ignored in dummy mode %i ...\n", cmd, dummymode); goto moglreturn; } #ifdef BUILD_GLM // GLM module is included and supported in moglcore: This is necessary if // one wants to use MOGL independent from Psychtoolbox. GLM is only supported // on MacOS-X, not on Linux or Windows... // We execute glm-commands without performing GLEW first-time initialization, // because to execute glewinit() we need a valid OpenGL context. This context is // either created by Psychtoolbox or by glm. Therefore glm-commands must be able // to execute before glewinit() happened. // look for command in glm command map if( (i=binsearch(glm_map,glm_map_count,cmd))>=0 ) { glm_map[i].cmdfn(nlhs,plhs,nrhs-1,prhs+1); goto moglreturn; } #endif // Is this the first invocation of moglcore? if (firsttime) { // Yes. Initialize GLEW, the GL Extension Wrangler Library. This will // auto-detect and dynamically link/bind all core OpenGL functionality // as well as all possible OpenGL extensions on OS-X, Linux and Windows. err = GLEW_OK; #ifdef PTB_USE_WAFFLE // Linux is special: If we use the Waffle backend for display system binding, then our display backend // may be something else than GLX (e.g., X11/EGL, Wayland/EGL, GBM/EGL, ANDROID/EGL etc.), in which case // glewInit() would not work and would crash hard. Detect if we're on classic Linux or Linux with X11/GLX. // If so, execute glewInit(), otherwise call glewContextInit() - a routine which skips GLX specific setup, // therefore only initializes the non-GLX parts. We need a hacked glew.c for this function to be available, // as original upstream GLEW makes that function private (static): if (!getenv("PSYCH_USE_DISPLAY_BACKEND") || strstr(getenv("PSYCH_USE_DISPLAY_BACKEND"), "glx")) { // Classic backend or GLX backend: The full show. err = glewInit(); } else { // Non-GLX backend, probably EGL: Reduced show. err = glewContextInit(); } #else // Other os'es, or Linux without Waffle backend: Always init GLEW: err = glewInit(); #endif if (GLEW_OK != err) { // Failed! Something is seriously wrong - We have to abort :( printf("MOGL: Failed to initialize! Probably you called an OpenGL command *before* opening an onscreen window?!?\n"); printf("GLEW reported the following error: %s\n", glewGetErrorString(err)); fflush(NULL); goto moglreturn; } // Success. Ready to go... if (debuglevel > 1) { printf("MOGL - OpenGL for Matlab & GNU/Octave initialized. MOGL is (c) 2006-2013 Richard F. Murray & Mario Kleiner, licensed to you under MIT license.\n"); #ifdef WINDOWS printf("On MS-Windows, we make use of the freeglut library, which is Copyright (c) 1999-2000 Pawel W. Olszta, licensed under compatible MIT/X11 license.\n"); printf("The precompiled Windows binary DLL's have been kindly provided by http://www.transmissionzero.co.uk/software/freeglut-devel/ -- Thanks!\n"); #endif printf("See file 'License.txt' in the Psychtoolbox root folder for the exact licensing conditions.\n"); } fflush(NULL); // Perform dynamic rebinding of ARB extensions to core functions, if necessary: mogl_rebindARBExtensionsToCore(); #ifdef FREEGLUT // FreeGlut must be initialized, otherwise it will emergency abort the whole application. // However, we skip init if we're on a setup without GLX display backend, as this would // abort us due to lack of GLX. On non-GLX we simply can't use FreeGlut at all. if (!getenv("PSYCH_USE_DISPLAY_BACKEND") || strstr(getenv("PSYCH_USE_DISPLAY_BACKEND"), "glx")) { // GLX display backend - Init and use FreeGlut: glutInit( &noargs, &dummyargp); } #endif // Running on a OpenGL-ES rendering api under Linux? if (getenv("PSYCH_USE_GFX_BACKEND") && strstr(getenv("PSYCH_USE_GFX_BACKEND"), "gles")) { // Yes. We emulate some immediate mode rendering commands, which aren't available // in OpenGL Embedded Subset at all, via "our" own emulation code. This code emulates // immediate mode on top of client vertex arrays and batch submission. if (debuglevel > 1) { printf("OpenGL-ES rendering API active: Emulating immediate mode rendering via David Petrie's ftglesGlue emulation code.\n"); } } // Register exit-handler: When flushing the mex-file, we free all allocated buffer memory: mexAtExit(&mexExitFunction); // Done with first time initialization: firsttime = 0; } // If glBeginLevel > 1 then most probably the script was aborted after execution of glBegin() but // before execution of glEnd(). In that case, we reset the level to zero. if (glBeginLevel > 1) glBeginLevel = 0; // Reset OpenGL error state so we can be sure that any of our error queries really // relate to errors caused by us: if (glBeginLevel == 0 && debuglevel > 0 && (strstr(cmd, "glGetError")==NULL)) glGetError(); // look for command in manual command map if( (i=binsearch(gl_manual_map,gl_manual_map_count,cmd))>=0 ) { gl_manual_map[i].cmdfn(nlhs,plhs,nrhs-1,(const mxArray**) prhs+1); if (debuglevel > 0) mogl_checkerrors(cmd, prhs); goto moglreturn; } // look for command in auto command map if( (i=binsearch(gl_auto_map,gl_auto_map_count,cmd))>=0 ) { gl_auto_map[i].cmdfn(nlhs,plhs,nrhs-1,(const mxArray**) prhs+1); if (debuglevel > 0) mogl_checkerrors(cmd, prhs); goto moglreturn; } // no match mogl_usageerr(); // moglreturn: Is the exit path of mogl. All execution ends at this point. moglreturn: return; }
int main (void) #endif { GLuint err; #if defined(_WIN32) || !defined(__APPLE__) || defined(GLEW_APPLE_GLX) char* display = NULL; int visual = -1; if (glewParseArgs(argc-1, argv+1, &display, &visual)) { #if defined(_WIN32) fprintf(stderr, "Usage: glewinfo [-pf <id>]\n"); #else fprintf(stderr, "Usage: glewinfo [-display <display>] [-visual <id>]\n"); #endif return 1; } #endif #if defined(_WIN32) if (GL_TRUE == glewCreateContext(&visual)) #elif defined(__APPLE__) && !defined(GLEW_APPLE_GLX) if (GL_TRUE == glewCreateContext()) #else if (GL_TRUE == glewCreateContext(display, &visual)) #endif { fprintf(stderr, "Error: glewCreateContext failed\n"); glewDestroyContext(); return 1; } glewExperimental = GL_TRUE; #ifdef GLEW_MX err = glewContextInit(glewGetContext()); #ifdef _WIN32 err = err || wglewContextInit(wglewGetContext()); #elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) err = err || glxewContextInit(glxewGetContext()); #endif #else err = glewInit(); #endif if (GLEW_OK != err) { fprintf(stderr, "Error [main]: glewInit failed: %s\n", glewGetErrorString(err)); glewDestroyContext(); return 1; } #if defined(_WIN32) f = fopen("glewinfo.txt", "w"); if (f == NULL) f = stdout; #else f = stdout; #endif fprintf(f, "---------------------------\n"); fprintf(f, " GLEW Extension Info\n"); fprintf(f, "---------------------------\n\n"); fprintf(f, "GLEW version %s\n", glewGetString(GLEW_VERSION)); #if defined(_WIN32) fprintf(f, "Reporting capabilities of pixelformat %d\n", visual); #elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) fprintf(f, "Reporting capabilities of display %s, visual 0x%x\n", display == NULL ? getenv("DISPLAY") : display, visual); #endif fprintf(f, "Running on a %s from %s\n", glGetString(GL_RENDERER), glGetString(GL_VENDOR)); fprintf(f, "OpenGL version %s is supported\n", glGetString(GL_VERSION)); glewInfo(); #if defined(_WIN32) wglewInfo(); #else glxewInfo(); #endif if (f != stdout) fclose(f); glewDestroyContext(); return 0; }