Last active
June 6, 2024 06:10
-
-
Save oknauta/6aacc2b7bb757e4237ebfcfc7da17a63 to your computer and use it in GitHub Desktop.
Creating a blank window in C with SDL library.
This file contains 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
/*************************************************************************** | |
* File: sdl2_window_blank.c | |
* Date: 2024-05-31 | 2024-06-06 | |
***************************************************************************/ | |
#include <SDL2/SDL.h> | |
#include <stdbool.h> | |
#define WINDOW_SIZE_X 800 // Window width. | |
#define WINDOW_SIZE_Y 600 // Window height. | |
int main(int argc, char const *argv[]) | |
{ | |
if(SDL_Init(SDL_INIT_EVERYTHING) != 0) | |
{ | |
SDL_Log("error %s", SDL_GetError()); | |
SDL_Quit(); | |
return 1; | |
} | |
SDL_Window *window; SDL_Renderer *renderer; // Definitions to a window. | |
// Creating the window and renderer. | |
if(SDL_CreateWindowAndRenderer(WINDOW_SIZE_X, WINDOW_SIZE_Y, SDL_WINDOW_RESIZABLE, &window, &renderer) != 0) | |
{ | |
SDL_Log("error %s", SDL_GetError()); | |
SDL_Quit(); | |
return 1; | |
} | |
SDL_Event event; // Loop event. | |
bool running = true; // Checks if the program is running. | |
while(running) | |
{ | |
while(SDL_PollEvent(&event)) | |
{ | |
if(event.type == SDL_QUIT) // If the user press the exit button, do something. | |
{ | |
running = false; | |
} | |
} | |
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); // Window background color. | |
SDL_RenderClear(renderer); // Clears the buffer. | |
SDL_RenderPresent(renderer); // Updates the render. | |
} | |
SDL_DestroyRenderer(renderer); | |
SDL_DestroyWindow(window); | |
SDL_Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment