void dreamTriInit(int width, int height) { // Configure Regal to log to file in /sdcard (disabled by default in this sample) // Note that for your own projects WRITE_EXTERNAL_STORAGE permission needs to be added to your AndroidManifest.xml setenv("REGAL_LOG_ALL", "0", 1); setenv("REGAL_LOG_ERROR", "1", 1); setenv("REGAL_LOG_FILE", "/sdcard/dreamri.log", 1); // This is not necessary when the EGL context is created natively, but is here as a reminder // to do register the EGL context with Regal when it is created by a Java thread. RegalMakeCurrent(eglGetCurrentContext()); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // avoid unlikely divide by zero if (height==0) { height=1; } float aspect = float(width)/float(height); glViewport(0, 0, width, height); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); if( aspect > 1 ) { glFrustum( -0.1 * aspect, 0.1 * aspect, -0.1, 0.1, 0.1, 100.0 ); } else { glFrustum( -0.1, 0.1, -0.1 / aspect, 0.1 / aspect, 0.1, 100.0 ); } glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); }
JNIEXPORT void JNICALL Java_com_regal_dreamtri_DreamtriLib_init(JNIEnv *env, jobject obj, jint width, jint height) { // Configure Regal to log to file in /sdcard (disabled by default in this sample) // Note that for your own projects WRITE_EXTERNAL_STORAGE permission needs to be added to your AndroidManifest.xml setenv("REGAL_LOG_ALL", "0", 1); setenv("REGAL_LOG_ERROR", "1", 1); setenv("REGAL_LOG_FILE", "/sdcard/dreamri.log", 1); // Because teh EGL context was created by a Java thread, we need to register it with Regal. RegalMakeCurrent(eglGetCurrentContext()); g_x = 0.0f; // Avoid unlikely divide by 0 if (height==0) height=1; float aspect = float(width)/float(height); glClearColor(0.0f, 0.0f, 0.0f, 0.5f); glViewport(0, 0, width, height); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); if( aspect > 1 ) { glFrustum( -0.1 * aspect, 0.1 * aspect, -0.1, 0.1, 0.1, 100.0 ); } else { glFrustum( -0.1, 0.1, -0.1 / aspect, 0.1 / aspect, 0.1, 100.0 ); } glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); }
JNIEXPORT void JNICALL Java_com_regal_dreamtorus_DreamtorusLib_init(JNIEnv *env, jobject obj, jint width, jint height) { // On Android there is a new context each time the application // is activated - we ought to clean up the Regal resources for // the old context, but there is no API for that yet. RegalMakeCurrent(eglGetCurrentContext()); dreamTorusInit(); dreamTorusReshape(width, height); }
int main(int argc, const char *argv[]) { glutInitDisplayString("rgba>=8 depth double"); glutInitWindowSize(500, 500); glutInit( &argc, (char **) argv); glutCreateWindow("dreamtorus"); // Regal workaround for OSX GLUT #ifdef __APPLE__ RegalMakeCurrent(CGLGetCurrentContext()); #endif RegalSetErrorCallback(myError); // Exercise REGAL_extension_query extension if (glIsSupportedREGAL("GL_REGAL_extension_query")) { printf("GL_REGAL_extension_query is supported.\n"); if (glIsSupportedREGAL("GL_EXT_debug_marker")) printf("GL_EXT_debug_marker is supported.\n"); else printf("GL_EXT_debug_marker is not supported.\n"); if (glIsSupportedREGAL("GL_EXT_framebuffer_object")) printf("GL_EXT_framebuffer_object is supported.\n"); else printf("GL_EXT_framebuffer_object is not supported.\n"); if (glIsSupportedREGAL("GL_EXT_direct_state_access")) printf("GL_EXT_direct_state_access is supported.\n"); else printf("GL_EXT_direct_state_access is not supported.\n"); if (glIsSupportedREGAL("GL_NV_path_rendering")) printf("GL_NV_path_rendering is supported.\n"); else printf("GL_NV_path_rendering is not supported.\n"); } glutTimerFunc(16, myTick, 0); glutDisplayFunc(myDisplay); glutReshapeFunc(reshape); glutKeyboardFunc(myKeyboard); glutMainLoop(); return 0; }
int main ( int argc, char** argv ) // Create Main Function For Bringing It All Together { glutInit ( &argc, argv ); // Erm Just Write It =) glutInitDisplayMode ( GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA ); // Display Mode glutInitWindowPosition (0,0); glutInitWindowSize ( 500, 500 ); // If glutFullScreen wasn't called this is the window size glutCreateWindow ( "NeHe Lesson 6- Ported by Rustad" ); // Window Title (argv[0] for current directory as title) #ifdef EMSCRIPTEN RegalMakeCurrent((RegalSystemContext)1); #endif init (); //glutFullScreen ( ); // Put Into Full Screen glutDisplayFunc ( display ); // Matching Earlier Functions To Their Counterparts glutReshapeFunc ( reshape ); glutKeyboardFunc ( keyboard ); glutSpecialFunc ( arrow_keys ); glutIdleFunc ( display ); glutMainLoop ( ); // Initialize The Main Loop }
GLboolean glewCreateContext (struct createParams *params) { CGLPixelFormatAttribute contextAttrs[20]; int i; CGLPixelFormatObj pf; GLint npix; CGLError error; i = 0; contextAttrs[i++] = kCGLPFAAccelerated; /* No software rendering */ #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_7 if (params->profile & GL_CONTEXT_CORE_PROFILE_BIT) { if (params->major==3 && params->minor>=2) { contextAttrs[i++] = kCGLPFAOpenGLProfile; /* OSX 10.7 Lion onwards */ contextAttrs[i++] = (CGLPixelFormatAttribute) kCGLOGLPVersion_3_2_Core; /* 3.2 Core Context */ } } #endif contextAttrs[i++] = 0; error = CGLChoosePixelFormat(contextAttrs, &pf, &npix); if (error) return GL_TRUE; error = CGLCreateContext(pf, NULL, &ctx); if (error) return GL_TRUE; CGLReleasePixelFormat(pf); octx = CGLGetCurrentContext(); error = CGLSetCurrentContext(ctx); if (error) return GL_TRUE; /* Needed for Regal on the Mac */ #if defined(GLEW_REGAL) && defined(__APPLE__) RegalMakeCurrent(ctx); #endif return GL_FALSE; }
int main(int argc, const char *argv[]) { glutInitDisplayString("rgba>=8 depth double"); glutInitWindowSize(500, 500); glutInit( &argc, (char **) argv); glutCreateWindow("dreamtorus"); glLogMessageCallbackREGAL(myOutput); // Regal workaround for OSX GLUT #ifdef __APPLE__ RegalMakeCurrent(CGLGetCurrentContext()); #endif // Regal workaround for Emscripten GLUT emulation #ifdef EMSCRIPTEN RegalMakeCurrent((RegalSystemContext)1); #endif RegalSetErrorCallback(myError); // Exercise REGAL_extension_query extension if (glIsSupportedREGAL("GL_REGAL_extension_query")) { printf("GL_REGAL_extension_query is supported.\n"); if (glIsSupportedREGAL("GL_EXT_debug_marker")) printf("GL_EXT_debug_marker is supported.\n"); else printf("GL_EXT_debug_marker is not supported.\n"); if (glIsSupportedREGAL("GL_EXT_framebuffer_object")) printf("GL_EXT_framebuffer_object is supported.\n"); else printf("GL_EXT_framebuffer_object is not supported.\n"); if (glIsSupportedREGAL("GL_EXT_direct_state_access")) printf("GL_EXT_direct_state_access is supported.\n"); else printf("GL_EXT_direct_state_access is not supported.\n"); if (glIsSupportedREGAL("GL_NV_path_rendering")) printf("GL_NV_path_rendering is supported.\n"); else printf("GL_NV_path_rendering is not supported.\n"); } printf("\n"); printf("E - Toggle GL error checking.\n"); printf("D - Toggle debug checking.\n"); printf("L - Toggle driver logging.\n"); printf("M - Toggle emulation.\n"); printf("R - Toggle driver calls.\n"); printf("\n"); glutTimerFunc(16, myTick, 0); glutDisplayFunc(myDisplay); glutReshapeFunc(dreamTorusReshape); glutKeyboardFunc(myKeyboard); glutMainLoop(); return 0; }
int main(int argc, char **argv) { GLenum status; GLboolean hasDSA; int samples = 0; int i; glutInitWindowSize(canvas_width, canvas_height); glutInit(&argc, argv); for (i=1; i<argc; i++) { if (argv[i][0] == '-') { int value = atoi(argv[i]+1); if (value >= 1) { samples = value; continue; } } fprintf(stderr, "usage: %s [-#]\n where # is the number of samples/pixel\n", programName); exit(1); } if (samples > 0) { char buffer[200]; if (samples == 1) samples = 0; printf("requesting %d samples\n", samples); sprintf(buffer, "rgb stencil~4 double samples~%d", samples); glutInitDisplayString(buffer); } else { /* Request a double-buffered window with at least 4 stencil bits and 8 samples per pixel. */ #if 0 glutInitDisplayString("rgb stencil~4 double samples~8"); #else glutInitDisplayString("rgb stencil~4 double"); #endif } glutCreateWindow("Classic PostScript tiger NV_path_rendering example"); // Regal workaround for OSX GLUT #ifdef __APPLE__ extern void *CGLGetCurrentContext(void); RegalMakeCurrent(CGLGetCurrentContext()); #endif status = glewInit(); if (status != GLEW_OK) { fatalError("OpenGL Extension Wrangler (GLEW) failed to initialize"); } printf("vendor: %s\n", glGetString(GL_VENDOR)); printf("version: %s\n", glGetString(GL_VERSION)); printf("renderer: %s\n", glGetString(GL_RENDERER)); printf("samples per pixel = %d\n", glutGet(GLUT_WINDOW_NUM_SAMPLES)); printf("Executable: %d bit\n", (int)(8*sizeof(int *))); printf("\n"); printf("Use left mouse button to scale/zoom (vertical, up/down) and rotate (right=clockwise, left=ccw)\n"); printf("Rotate and zooming is centered where you first left mouse click\n"); printf("Hold down Ctrl at left mouse click to JUST SCALE\n"); printf("Hold down Shift at left mouse click to JUST ROTATE\n"); printf("\n"); printf("Use middle mouse button to slide (translate)\n"); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMouseFunc(mouse); glutMotionFunc(motion); initModelAndViewMatrices(); glutCreateMenu(menu); glutAddMenuEntry("[f] Toggle filling", 'f'); glutAddMenuEntry("[s] Toggle stroking", 's'); glutAddMenuEntry("[r] Reset view", 'r'); glutAddMenuEntry("[Esc] Quit", 27); glutAttachMenu(GLUT_RIGHT_BUTTON); if (!glewIsSupported("GL_REGAL_extension_query")) printf("GL_REGAL_extension_query is not supported.\n"); if (!glewIsSupported("GL_EXT_debug_marker")) printf("GL_EXT_debug_marker is not supported.\n"); hasDSA = glewIsSupported("GL_EXT_direct_state_access"); if (!hasDSA) { fatalError("OpenGL implementation doesn't support GL_EXT_direct_state_access (you should be using NVIDIA GPUs...)"); } if (!glewIsSupported("GL_NV_path_rendering")) { fatalError("required NV_path_rendering OpenGL extension is not present"); } initGraphics(); path_count = getTigerPathCount(); glutMainLoop(); return 0; }
/* * Opens a window. Requires a SFG_Window object created and attached * to the freeglut structure. OpenGL context is created here. */ void fgPlatformOpenWindow( SFG_Window* window, const char* title, GLboolean positionUse, int x, int y, GLboolean sizeUse, int w, int h, GLboolean gameMode, GLboolean isSubWindow ) { XVisualInfo * visualInfo = NULL; XSetWindowAttributes winAttr; XTextProperty textProperty; XSizeHints sizeHints; XWMHints wmHints; XEvent eventReturnBuffer; /* return buffer required for a call */ unsigned long mask; unsigned int current_DisplayMode = fgState.DisplayMode ; XConfigureEvent fakeEvent = {0}; /* Save the display mode if we are creating a menu window */ if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB ; #ifdef EGL_VERSION_1_0 #define WINDOW_CONFIG window->Window.pContext.egl.Config #else #define WINDOW_CONFIG window->Window.pContext.FBConfig #endif fghChooseConfig(&WINDOW_CONFIG); if( window->IsMenu && ( ! fgStructure.MenuContext ) ) fgState.DisplayMode = current_DisplayMode ; if( ! WINDOW_CONFIG ) { /* * The "fghChooseConfig" returned a null meaning that the visual * context is not available. * Try a couple of variations to see if they will work. */ #ifndef EGL_VERSION_1_0 if( !( fgState.DisplayMode & GLUT_DOUBLE ) ) { fgState.DisplayMode |= GLUT_DOUBLE ; fghChooseConfig(&WINDOW_CONFIG); fgState.DisplayMode &= ~GLUT_DOUBLE; } #endif if( fgState.DisplayMode & GLUT_MULTISAMPLE ) { fgState.DisplayMode &= ~GLUT_MULTISAMPLE ; fghChooseConfig(&WINDOW_CONFIG); fgState.DisplayMode |= GLUT_MULTISAMPLE; } } FREEGLUT_INTERNAL_ERROR_EXIT( WINDOW_CONFIG != NULL, "FBConfig with necessary capabilities not found", "fgOpenWindow" ); /* Get the X visual. */ #ifdef EGL_VERSION_1_0 EGLint vid = 0; XVisualInfo visualTemplate; int num_visuals; if (!eglGetConfigAttrib(fgDisplay.pDisplay.egl.Display, window->Window.pContext.egl.Config, EGL_NATIVE_VISUAL_ID, &vid)) fgError("eglGetConfigAttrib(EGL_NATIVE_VISUAL_ID) failed"); visualTemplate.visualid = vid; visualInfo = XGetVisualInfo(fgDisplay.pDisplay.Display, VisualIDMask, &visualTemplate, &num_visuals); #else visualInfo = glXGetVisualFromFBConfig( fgDisplay.pDisplay.Display, window->Window.pContext.FBConfig ); #endif FREEGLUT_INTERNAL_ERROR_EXIT( visualInfo != NULL, "visualInfo could not be retrieved from FBConfig", "fgOpenWindow" ); /* * XXX HINT: the masks should be updated when adding/removing callbacks. * XXX This might speed up message processing. Is that true? * XXX * XXX A: Not appreciably, but it WILL make it easier to debug. * XXX Try tracing old GLUT and try tracing freeglut. Old GLUT * XXX turns off events that it doesn't need and is a whole lot * XXX more pleasant to trace. (Think mouse-motion! Tons of * XXX ``bonus'' GUI events stream in.) */ winAttr.event_mask = StructureNotifyMask | SubstructureNotifyMask | ExposureMask | ButtonPressMask | ButtonReleaseMask | KeyPressMask | KeyReleaseMask | VisibilityChangeMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask | ButtonMotionMask; winAttr.background_pixmap = None; winAttr.background_pixel = 0; winAttr.border_pixel = 0; winAttr.colormap = XCreateColormap( fgDisplay.pDisplay.Display, fgDisplay.pDisplay.RootWindow, visualInfo->visual, AllocNone ); mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask; if( window->IsMenu || ( gameMode == GL_TRUE ) ) { winAttr.override_redirect = True; mask |= CWOverrideRedirect; } if( ! positionUse ) x = y = -1; /* default window position */ if( ! sizeUse ) w = h = 300; /* default window size */ window->Window.Handle = XCreateWindow( fgDisplay.pDisplay.Display, window->Parent == NULL ? fgDisplay.pDisplay.RootWindow : window->Parent->Window.Handle, x, y, w, h, 0, visualInfo->depth, InputOutput, visualInfo->visual, mask, &winAttr ); /* Fake configure event to force viewport setup * even with no window manager. */ fakeEvent.type = ConfigureNotify; fakeEvent.display = fgDisplay.pDisplay.Display; fakeEvent.window = window->Window.Handle; fakeEvent.x = x; fakeEvent.y = y; fakeEvent.width = w; fakeEvent.height = h; XPutBackEvent(fgDisplay.pDisplay.Display, (XEvent*)&fakeEvent); /* * The GLX context creation, possibly trying the direct context rendering * or else use the current context if the user has so specified */ if( window->IsMenu ) { /* * If there isn't already an OpenGL rendering context for menu * windows, make one */ if( !fgStructure.MenuContext ) { fgStructure.MenuContext = (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) ); fgStructure.MenuContext->MContext = fghCreateNewContext( window ); } /* window->Window.Context = fgStructure.MenuContext->MContext; */ window->Window.Context = fghCreateNewContext( window ); } else if( fgState.UseCurrentContext ) { #ifdef EGL_VERSION_1_0 window->Window.Context = eglGetCurrentContext( ); #else window->Window.Context = glXGetCurrentContext( ); #endif if( ! window->Window.Context ) window->Window.Context = fghCreateNewContext( window ); } else window->Window.Context = fghCreateNewContext( window ); #if !defined( __FreeBSD__ ) && !defined( __NetBSD__ ) && !defined(EGL_VERSION_1_0) if( !glXIsDirect( fgDisplay.pDisplay.Display, window->Window.Context ) ) { if( fgState.DirectContext == GLUT_FORCE_DIRECT_CONTEXT ) fgError( "Unable to force direct context rendering for window '%s'", title ); } #endif sizeHints.flags = 0; if ( positionUse ) sizeHints.flags |= USPosition; if ( sizeUse ) sizeHints.flags |= USSize; /* * Fill in the size hints values now (the x, y, width and height * settings are obsolete, are there any more WMs that support them?) * Unless the X servers actually stop supporting these, we should * continue to fill them in. It is *not* our place to tell the user * that they should replace a window manager that they like, and which * works, just because *we* think that it's not "modern" enough. */ sizeHints.x = x; sizeHints.y = y; sizeHints.width = w; sizeHints.height = h; wmHints.flags = StateHint; wmHints.initial_state = fgState.ForceIconic ? IconicState : NormalState; /* Prepare the window and iconified window names... */ XStringListToTextProperty( (char **) &title, 1, &textProperty ); XSetWMProperties( fgDisplay.pDisplay.Display, window->Window.Handle, &textProperty, &textProperty, 0, 0, &sizeHints, &wmHints, NULL ); XFree( textProperty.value ); XSetWMProtocols( fgDisplay.pDisplay.Display, window->Window.Handle, &fgDisplay.pDisplay.DeleteWindow, 1 ); #ifdef EGL_VERSION_1_0 fghPlatformOpenWindowEGL(window); #else glXMakeContextCurrent( fgDisplay.pDisplay.Display, window->Window.Handle, window->Window.Handle, window->Window.Context ); #endif #ifdef FREEGLUT_REGAL RegalMakeCurrent(window->Window.Context); #endif /* register extension events _before_ window is mapped */ #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H fgRegisterDevices( fgDisplay.pDisplay.Display, &(window->Window.Handle) ); #endif if (!window->IsMenu) /* Don't show window after creation if its a menu */ { XMapWindow( fgDisplay.pDisplay.Display, window->Window.Handle ); window->State.Visible = GL_TRUE; } XFree(visualInfo); /* wait till window visible */ if( !isSubWindow && !window->IsMenu) XPeekIfEvent( fgDisplay.pDisplay.Display, &eventReturnBuffer, &fghWindowIsVisible, (XPointer)(window->Window.Handle) ); #undef WINDOW_CONFIG }