Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include "include/SDL2/SDL.h"
- #include "include/GL/glew.h"
- #include <thread>
- #include <chrono>
- int main(int argc, char** argv) {
- if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
- std::cerr << "Error initializing SDL.\n";
- exit(1);
- }
- SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- //SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG);
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- glewExperimental = GL_TRUE;
- SDL_Window* window = SDL_CreateWindow("RenderSystem", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE);
- if(!window) {
- std::cerr << "Window creation failed.\n";
- SDL_Quit();
- exit(2);
- }
- SDL_GLContext context = SDL_GL_CreateContext(window);
- if(!context) {
- std::cerr << "OpenGL Context creation failed.\n";
- SDL_DestroyWindow(window);
- SDL_Quit();
- exit(3);
- }
- SDL_GL_MakeCurrent(window, context);
- std::fstream logFile;
- logFile.open("RenderSystem.log", std::ios::in | std::ios::out | std::ios::trunc);
- if(!logFile) {
- std::cerr << "Failed to open log file.\n";
- }
- int GLAttribVal;
- SDL_GL_GetAttribute(SDL_GL_ACCELERATED_VISUAL, &GLAttribVal);
- logFile << "SDL_GL_ACCELERATED_VISUAL: " << std::boolalpha << (bool)(GLAttribVal) << "\n";
- SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &GLAttribVal);
- logFile << "SDL_GL_CONTEXT_MAJOR_VERSION: " << GLAttribVal << "\n";
- SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &GLAttribVal);
- logFile << "SDL_GL_CONTEXT_MINOR_VERSION: " << GLAttribVal << "\n";;
- SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &GLAttribVal);
- logFile << "SDL_GL_RED_SIZE (red bits): " << GLAttribVal << "\n";
- SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &GLAttribVal);
- logFile << "SDL_GL_GREEN_SIZE (green bits): " << GLAttribVal << "\n";
- SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &GLAttribVal);
- logFile << "SDL_GL_BLUE_SIZE (blue bits): " << GLAttribVal << "\n";
- SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &GLAttribVal);
- logFile << "SDL_GL_ALPHA_SIZE (alpha bits): " << GLAttribVal << "\n";
- SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &GLAttribVal);
- logFile << "SDL_GL_DEPTH_SIZE: " << GLAttribVal << "\n";
- SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &GLAttribVal);
- logFile << "SDL_GL_DOUBLEBUFFER: " << std::boolalpha << (bool)(GLAttribVal) << "\n";
- int success = glewInit();
- if(success != GLEW_OK) {
- SDL_GL_DeleteContext(context);
- SDL_DestroyWindow(window);
- SDL_Quit();
- exit(4);
- }
- logFile << "\n\nOpenGL version: " << glGetString(GL_VERSION) << "\n";
- logFile << "OpenGL vendor: " << glGetString(GL_VENDOR) << "\n";
- logFile << "OpenGL renderer: " << glGetString(GL_RENDERER) << "\n\n\n";
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- SDL_Event evt;
- bool run = true;
- while(run) {
- SDL_PollEvent(&evt);
- switch(evt.type) {
- case SDL_KEYDOWN:
- if(evt.key.keysym.sym == SDLK_ESCAPE) {
- run = false;
- }
- break;
- case SDL_QUIT:
- run = false;
- break;
- }
- SDL_GL_SwapWindow(window);
- }
- SDL_GL_DeleteContext(context);
- SDL_DestroyWindow(window);
- SDL_Quit();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement