/* * This example code creates an SDL window and renderer, and then clears the * window to a different color every frame, so you'll effectively get a window * that's smoothly fading between colors. * * This code is public domain. Feel free to use it for any purpose! */ #include #include #include #include #include #include #define SDL_MAIN_USE_CALLBACKS 1 /* use the callbacks instead of main() */ #include #include #include "include/glad/gl.h" /* We will use this renderer to draw into this window every frame. */ static SDL_Window *window = NULL; static SDL_Renderer *renderer = NULL; static SDL_GLContext context = NULL; /* This function runs once at startup. */ SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) { SDL_SetAppMetadata("Heartbeat", "1.0", "io.typetrait.heartbeat"); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 6); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); if (!SDL_Init(SDL_INIT_VIDEO)) { SDL_Log("Couldn't initialize SDL: %s", SDL_GetError()); return SDL_APP_FAILURE; } if (!SDL_CreateWindowAndRenderer("Heartbeat", 640, 480, SDL_WINDOW_RESIZABLE, &window, &renderer)) { SDL_Log("Couldn't create window/renderer: %s", SDL_GetError()); return SDL_APP_FAILURE; } int version = gladLoadGL((GLADloadfunc)SDL_GL_GetProcAddress); if (version == 0) { printf("Failed to initialize OpenGL context\n"); return SDL_APP_FAILURE; } context = SDL_GL_CreateContext(window); SDL_SetRenderLogicalPresentation(renderer, 640, 480, SDL_LOGICAL_PRESENTATION_LETTERBOX); return SDL_APP_CONTINUE; } /* This function runs when a new event (mouse input, keypresses, etc) occurs. */ SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) { if (event->type == SDL_EVENT_QUIT) { return SDL_APP_SUCCESS; } return SDL_APP_CONTINUE; } /* This function runs once per frame, and is the heart of the program. */ SDL_AppResult SDL_AppIterate(void *appstate) { SDL_RenderLine(renderer, 0.0f, 0.0f, 15.0f, 15.0f); glClearColor(1.0f, 0.8f, 0.2f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); SDL_GL_SwapWindow(window); return SDL_APP_CONTINUE; } /* This function runs once at shutdown. */ void SDL_AppQuit(void *appstate, SDL_AppResult result) { /* SDL will clean up the window/renderer for us. */ SDL_GL_DestroyContext(context); // SDL_DestroyWindow(window); // SDL_Quit(); }