Skip to content

Instantly share code, notes, and snippets.

@fouric
Created October 3, 2019 18:45
Show Gist options
  • Save fouric/8fe87f0b94761105a1fe82ee2f261747 to your computer and use it in GitHub Desktop.
Save fouric/8fe87f0b94761105a1fe82ee2f261747 to your computer and use it in GitHub Desktop.
/* compile with `gcc ramdisk/opengl.c -lSDL2 -lGL` */
#include <SDL2/SDL.h>
#include <GL/gl.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
SDL_Init(SDL_INIT_VIDEO);
SDL_Window* win = SDL_CreateWindow("test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 512, 512, SDL_WINDOW_OPENGL);
SDL_GLContext ctx = SDL_GL_CreateContext(win);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetSwapInterval(1);
int value = 0;
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &value);
printf("major version: %i\n", value);
SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &value);
printf("minor version: %i\n", value);
glClearColor(0.7, 0.0, 0.7, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
SDL_GL_SwapWindow(win);
SDL_Delay(1000);
SDL_GL_DeleteContext(ctx);
SDL_DestroyWindow(win);
SDL_Quit();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment