Created
February 19, 2022 00:57
-
-
Save iTrooz/95766abee601a82659dec948195b364d to your computer and use it in GitHub Desktop.
SDL2 Hello World Square Hardware
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
/* | |
* Based from https://gist.github.com/cicanci/b54715298ab55dff2fbcd0ca3829d13b | |
* Basic SDL2 program to render a square using the hardware framework. | |
* Hope it helps you | |
*/ | |
#include <SDL2/SDL.h> | |
int main(){ | |
if (SDL_Init(SDL_INIT_EVERYTHING) != 0){ | |
SDL_Log("SDL_Init Error: %s\n", SDL_GetError()); | |
return -1; | |
} | |
SDL_Window* window; | |
SDL_Renderer* renderer; | |
if (SDL_CreateWindowAndRenderer(640, 480, 0, &window, &renderer) != 0){ | |
SDL_Log("SDL_CreateWindow Error: %s\n", SDL_GetError()); | |
return -1; | |
} | |
SDL_SetWindowTitle(window, "Square"); | |
bool exit = false; | |
SDL_Event event; | |
while (!exit) | |
{ | |
while (SDL_PollEvent(&event)) | |
{ | |
switch (event.type) | |
{ | |
case SDL_QUIT: | |
exit = true; | |
break; | |
} | |
} | |
SDL_RenderClear(renderer); | |
SDL_Rect rect({50,50,100, 100}); | |
SDL_SetRenderDrawColor(renderer, 0, 255, 0, 255 ); | |
SDL_RenderFillRect(renderer, &rect); | |
SDL_SetRenderDrawColor(renderer, 0, 0, 0, 255 ); | |
SDL_RenderPresent(renderer); | |
} | |
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