Created
February 20, 2014 20:46
-
-
Save shakesoda/9122868 to your computer and use it in GitHub Desktop.
sdl example for missingno
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <GLXW/glxw.h> | |
| #include <SDL2/SDL.h> | |
| class DisplaySystem { | |
| public: | |
| DisplaySystem() { | |
| window = SDL_CreateWindow( | |
| "thingy", | |
| SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, | |
| 1280, 720, | |
| SDL_WINDOW_OPENGL //| SDL_WINDOW_FULLSCREEN_DESKTOP | |
| ); | |
| renderer = SDL_CreateRenderer(window, -1, | |
| SDL_RENDERER_ACCELERATED | | |
| SDL_RENDERER_PRESENTVSYNC | |
| ); | |
| SDL_GL_SetSwapInterval(1); | |
| if (!window || !renderer || glxwInit()) { | |
| init_succeeded = false; | |
| return; | |
| } | |
| glEnable(GL_DEPTH_TEST); | |
| glEnable(GL_BLEND); | |
| glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |
| //glDebugMessageCallbackARB(&gl_debug_callback, NULL); | |
| init_succeeded = true; | |
| } | |
| void shutdown() { | |
| SDL_DestroyRenderer(renderer); | |
| SDL_DestroyWindow(window); | |
| } | |
| void flip() { | |
| SDL_RenderPresent(renderer); | |
| glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
| } | |
| const bool did_init() { return init_succeeded; } | |
| protected: | |
| bool init_succeeded; | |
| SDL_Renderer *renderer; | |
| SDL_Window *window; | |
| GLuint vao, vbo, vs, fs, shader; | |
| }; | |
| int main(int argc, char **argv) { | |
| SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); | |
| DisplaySystem display; | |
| if (!display.did_init()) { | |
| printf("%s :(\n", SDL_GetError()); | |
| return 1; | |
| } | |
| double then = SDL_GetTicks(); | |
| double last_reset = then; | |
| while (1) { | |
| SDL_Event e; | |
| if (SDL_PollEvent(&e)) { | |
| if (e.type == SDL_QUIT) | |
| break; | |
| if (e.type == SDL_KEYDOWN) { | |
| if (e.key.keysym.sym == SDLK_ESCAPE) | |
| break; | |
| } | |
| } | |
| double now = SDL_GetTicks(); | |
| double delta = (now - then) / 1000.0; | |
| then = now; | |
| // update/draw things | |
| display.flip(); | |
| } | |
| display.shutdown(); | |
| SDL_Quit(); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment