Created
December 16, 2019 20:43
-
-
Save Farious/fabf5d25224baccdb910b9ac6270c3ee to your computer and use it in GitHub Desktop.
Simple SDL2 init and usage.
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
// | |
// main.cpp | |
// | |
// Created by Fabio Reis on 16/12/2019. | |
// | |
#include <SDL2/SDL.h> | |
int main(int, char**) { | |
if (SDL_Init(SDL_INIT_VIDEO) != 0) { | |
SDL_Log("Unable to initialize SDL: %s", SDL_GetError()); | |
return 1; | |
} | |
SDL_Window *window = SDL_CreateWindow("Hello World", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 800, 600, SDL_WINDOW_SHOWN); | |
SDL_Renderer *renderer = SDL_CreateRenderer(window, -1, 0); | |
bool quit = false; | |
while(!quit) { | |
SDL_Event event; | |
while (SDL_PollEvent(&event)) { | |
if(event.type == SDL_QUIT) { | |
quit = true; | |
} | |
} | |
uint32_t ticks = SDL_GetTicks(); | |
float rate = 1000.f; | |
float shift = sinf(ticks / rate); | |
float phase = cosf(ticks * 2 / rate); | |
float angle = cosf(ticks * 3 / rate); | |
SDL_SetRenderDrawColor(renderer, fabsf(shift * 255.f), fabsf(phase * 255.f), fabsf(angle * 255.f), 255); | |
SDL_RenderClear(renderer); | |
SDL_RenderPresent(renderer); | |
SDL_Delay(16); | |
} | |
SDL_Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment