SDLWrapper::SDLWrapper() { if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDLDie("Unable to initialize SDL"); m_status = NO_INIT; } else { SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); m_window = SDL_CreateWindow(PROGRAM_NAME,SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN); if (!m_window) { SDLDie("Unable to create window"); m_status = NO_WINDOW; } else { CheckSDLError(__LINE__); m_context = SDL_GL_CreateContext(m_window); CheckSDLError(__LINE__); SDL_GL_SetSwapInterval(1); m_status = INIT; } } }
bool Engine_Init(char* windowTitle, int width, int height) { window_width = width; window_height = height; if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC | SDL_INIT_GAMECONTROLLER) < 0) // Initialize SDL2 Engine_Quit("Unable to initialize SDL"); // Or die on error SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24); // Create an application window with the following settings: window = SDL_CreateWindow( windowTitle, // window title SDL_WINDOWPOS_UNDEFINED, // initial x position SDL_WINDOWPOS_UNDEFINED, // initial y position width, // width, in pixels height, // height, in pixels SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE ); // Check that the window was successfully made if(window == NULL) Engine_Quit("Could not create window: %s"); CheckSDLError(__LINE__); mainContext = SDL_GL_CreateContext(window); CheckSDLError(__LINE__); glewExperimental = GL_TRUE; glewInit(); //Debug some things :) printf("Vendor: %s\n", glGetString(GL_VENDOR)); printf("Renderer: %s\n", glGetString(GL_RENDERER)); printf("Version: %s\n", glGetString(GL_VERSION)); printf("GLSL: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION)); printf("Extensions: %s\n", glGetString(GL_EXTENSIONS)); // This makes our buffer swap syncronized with the monitor's vertical refresh SDL_GL_SetSwapInterval(1); // Create our renderer Render_Init(width, height); QuadRenderer::Resized(width, height); //Core loop nextTime = SDL_GetTicks() + TICK_INTERVAL; return true; }
bool Init() { // Initialize SDL's Video subsystem if (SDL_Init(SDL_INIT_VIDEO) < 0) { std::cout << "Failed to init SDL\n"; return false; } // Create our window centered at 512x512 resolution mainWindow = SDL_CreateWindow(programName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL); // Check that everything worked out okay if (!mainWindow) { std::cout << "Unable to create window\n"; CheckSDLError(__LINE__); return false; } // Create our opengl context and attach it to our window mainContext = SDL_GL_CreateContext(mainWindow); SetOpenGLAttributes(); // This makes our buffer swap syncronized with the monitor's vertical refresh SDL_GL_SetSwapInterval(1); // Init GLEW //glewExperimental = GL_TRUE; //glewInit(); return true; }
bool Engine_SetFullscreen(bool fullscreen, bool realFullscreen /* = false */) { int result; if (fullscreen) { if (realFullscreen) { result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN); } else { result = SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); } } else { result = SDL_SetWindowFullscreen(window, 0); } CheckSDLError(__LINE__); return result == 0; }