Last active
December 16, 2019 20:44
-
-
Save Farious/687d816ece30d499d7a0af89280cbf33 to your computer and use it in GitHub Desktop.
Simple SDL2 init and usage. Shows message: _flock failed to lock maps file: errno = 35_ upon initialisation but runs normally.
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