void SDLWindow::toggleVsync() { setVerticalSync(!mVsync); }
bool SDLWindow::createContext() { //Init SDL if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) { fprintf(stderr, "SDL Error: %s", SDL_GetError()); return false; } // Check to see if we are forcing the legacy profile. bool forceLegacy = false; for (auto cmd : GameState::gState->mCmdArgs) { if (strcasecmp(cmd.c_str(), "-legacygl") == 0) { forceLegacy = true; break; } } SDL_GLContext context; // First try the core profile, unless we specified the legacy profile // as a command line argument. bool success = false; GLContext profileChosen = GLContext::INVALID; if (!forceLegacy) { IO::printf("Attempting to create a core OpenGL context."); success = createGLContextAndWindow(GLContext::CORE, window, context); if (success) profileChosen = GLContext::CORE; } if (forceLegacy || !success) { if (!success) IO::printf("Failed to create a core OpenGL context. Attempting to create a legacy context.\n"); if (forceLegacy) IO::printf("Forcing the legacy OpenGL context. Attempting to create a legacy context.\n"); success = createGLContextAndWindow(GLContext::LEGACY, window, context); if (success) profileChosen = GLContext::LEGACY; } // If we still didn't have success, bail. if (!success) { IO::printf("Failed to create an OpenGL context. Make sure that you have at least OpenGL 2.1.\n"); return false; } SDL_GL_MakeCurrent(window, context); #ifdef _WIN32 epoxy_handle_external_wglMakeCurrent(); #endif // Initialize the GL library if (profileChosen == GLContext::CORE) GL::createGL<GL33>(); else GL::createGL<GL21>(); // for the love of god please not software rendering. #if defined(_WIN32) || defined(__APPLE__) { std::string renderer = reinterpret_cast<const char*>(glGetString(GL_RENDERER)); #ifdef _WIN32 if (renderer.find("Microsoft") != std::string::npos) { #else if (renderer.find("APPLE") != std::string::npos) { #endif IO::printf("Unable to create a hardware accelerated OpenGL driver. Please make sure that you have OpenGL drivers downloaded and they are up to date.\n"); return false; } } #endif // Let the GL library store this context. glBindContextEXT(context); IO::printf("System Memory: %dMB\n", PlatformEx::getPhysicalSystemRam()); IO::printf("OpenGL Core Profile Info\n"); IO::printf(" Version: %s\n", glGetString(GL_VERSION)); IO::printf(" Vendor: %s\n", glGetString(GL_VENDOR)); IO::printf(" Renderer: %s\n", glGetString(GL_RENDERER)); IO::printf(" Shading: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); IO::printf(" VRAM: %uMB\n", glGetVideoRamEXT()); //Use Vsync setVerticalSync(true); //Lock cursor lockCursor(true); // we bind a blank VAO, as it's required for core profile glGenVertexArrays(1, &mVAO); glBindVertexArray(mVAO); return true; } void SDLWindow::destroyContext() { // clean up VAO if (mVAO) glDeleteVertexArrays(1, &mVAO); SDL_GL_DeleteContext(context); glBindContextEXT(nullptr); SDL_Quit(); } void SDLWindow::swapBuffers() { SDL_GL_SwapWindow(window); }
void ofAppGLFWWindow::setupOpenGL(int w, int h, int screenMode){ requestedWidth = w; requestedHeight = h; if(!glfwInit( )){ ofLog(OF_LOG_ERROR,"cannot init GLFW"); return; } printf("WINDOW MODE IS %i", screenMode); windowMode = screenMode; glfwOpenWindowHint( GLFW_FSAA_SAMPLES, samples ); // targets default // GLFW_REFRESH_RATE 0 // GLFW_ACCUM_RED_BITS; 0 // GLFW_ACCUM_GREEN_BITS; 0 // GLFW_ACCUM_BLUE_BITS; 0 // GLFW_ACCUM_ALPHA_BITS; 0 // GLFW_AUX_BUFFERS; 0 // GLFW_STEREO; 0 // GLFW_WINDOW_NO_RESIZE; 0 // GLFW_FSAA_SAMPLES; 0 int result; if (windowMode == OF_WINDOW){ result = glfwOpenWindow( w, h, // Width and height of window 8, 8, 8, // Number of red, green, and blue bits for color buffer 8, // Number of bits for alpha buffer 32, // Number of bits for depth buffer (Z-buffer) 0, // Number of bits for stencil buffer GLFW_WINDOW // We want a desktop window (could be GLFW_FULLSCREEN) ); }else if(windowMode == OF_FULLSCREEN){ result = glfwOpenWindow( getScreenSize().x, getScreenSize().y, // Width and height of window 8, 8, 8, // Number of red, green, and blue bits for color buffer 8, // Number of bits for alpha buffer 32, // Number of bits for depth buffer (Z-buffer) 0, // Number of bits for stencil buffer GLFW_FULLSCREEN // We want a desktop window (could be GLFW_FULLSCREEN) ); showCursor(); }else if(windowMode == OF_GAME_MODE){ result = glfwOpenWindow( w, h, // Width and height of window 8, 8, 8, // Number of red, green, and blue bits for color buffer 8, // Number of bits for alpha buffer 32, // Number of bits for depth buffer (Z-buffer) 0, // Number of bits for stencil buffer GLFW_FULLSCREEN // We want a desktop window (could be GLFW_FULLSCREEN) ); showCursor(); } else { printf("**** invalid windowMode\n"); } if ( result != GL_TRUE ) { printf("**** failed to open glfw window\n"); } else printf("*--- opened glfw window\n"); setVerticalSync(false); // Set window title glfwSetWindowTitle( " " ); glfwEnable( GLFW_KEY_REPEAT ); // ofBackground(200,200,200); // default bg color // ofSetColor(0xFFFFFF); // default draw color // used to be black, but // black + texture = black // so maybe grey bg // and "white" fg color // as default works the best... requestedHeight = requestedHeight < 1 ? 1 : requestedHeight; glfwGetWindowSize( &requestedWidth, &requestedHeight ); nonFullScreenW = ofGetWidth(); nonFullScreenH = ofGetHeight(); glfwGetWindowSize( &windowW, &windowH ); setWindowPosition(50, 50); }