Skip to content

Instantly share code, notes, and snippets.

@doccaico
Last active March 19, 2023 23:19
Show Gist options
  • Select an option

  • Save doccaico/8ed44a7344cc0d00b1eb18c8c1f09a5d to your computer and use it in GitHub Desktop.

Select an option

Save doccaico/8ed44a7344cc0d00b1eb18c8c1f09a5d to your computer and use it in GitHub Desktop.
Triangle (SDL2) on MSYS2
// Build (MSYS2)
// gcc -Wall -pedantic main.c `sdl2-config --cflags --libs`
#include <SDL.h>
#include <stdbool.h>
int main(int argc, char** argv) {
SDL_Init(SDL_INIT_EVERYTHING);
SDL_Window* window = SDL_CreateWindow(
"SDL", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 800, 600, SDL_WINDOW_SHOWN);
SDL_Renderer* renderer = SDL_CreateRenderer(
window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
SDL_Vertex vertex_1 = {{400, 150}, {255, 0, 0, 255}, {0, 0}};
SDL_Vertex vertex_2 = {{200, 450}, {0, 0, 255, 255}, {0, 0}};
SDL_Vertex vertex_3 = {{600, 450}, {0, 255, 0, 255}, {0, 0}};
SDL_Vertex vertices[] = {
vertex_1,
vertex_2,
vertex_3
};
bool running = true;
while(running)
{
SDL_Event ev;
while(SDL_PollEvent(&ev))
{
if((SDL_QUIT == ev.type) ||
(SDL_KEYDOWN == ev.type && SDL_SCANCODE_ESCAPE == ev.key.keysym.scancode))
{
running = false;
break;
}
}
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderClear(renderer);
SDL_RenderGeometry(renderer, NULL, vertices, 3, NULL, 0);
SDL_RenderPresent(renderer);
}
SDL_DestroyRenderer(renderer);
SDL_DestroyWindow(window);
SDL_Quit();
return 0;
}
@doccaico

Copy link
Copy Markdown
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment