-
-
Save tesfabpel/cd186c7c34c91059a329481446771e50 to your computer and use it in GitHub Desktop.
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
#include <math.h> | |
#include <GL/glew.h> | |
#include <GL/glut.h> | |
#include <GL/gl.h> | |
#include <SDL2/SDL.h> | |
#include "utils.h" | |
int main(int argc, char *argv[]) | |
{ | |
printf("Hello, World!\n"); | |
//glutInit(&argc, argv); | |
//glewInit(); | |
if(SDL_Init(SDL_INIT_VIDEO) < 0) | |
goto exit; | |
SDL_Window *window; | |
SDL_Renderer *renderer; | |
window = SDL_CreateWindow("Hello, World", | |
SDL_WINDOWPOS_CENTERED, | |
SDL_WINDOWPOS_CENTERED, | |
640, | |
480, | |
SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); | |
// OpenGL 4.x Core profile | |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); | |
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4); | |
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); | |
renderer = SDL_GL_CreateContext(window); | |
//GLuint id; | |
//glGenBuffers(1, &id); | |
float hue = 0.0f; | |
float step = 1.0f / 10.0f; | |
Uint64 time_now = SDL_GetPerformanceCounter(); | |
Uint64 time_last; | |
float delta_time; | |
while(1) | |
{ | |
SDL_Event event; | |
SDL_PollEvent(&event); | |
if(event.type == SDL_QUIT) | |
{ | |
break; | |
} | |
// Calculate delta time | |
time_last = time_now; | |
time_now = SDL_GetPerformanceCounter(); | |
delta_time = (float) ((time_now - time_last) * 1000 / SDL_GetPerformanceFrequency()); | |
// Calculate bg color | |
hue += step * (delta_time / 1000.0f); | |
hue = fmodf(hue, 1.0f); | |
struct rgb_t rgb = hsv_to_rgb((struct hsv_t){hue, 1.0, 1.0}); | |
// Clear | |
glClearColor(rgb.r, rgb.g, rgb.b, 1.0); | |
glClear(GL_COLOR_BUFFER_BIT); | |
// ... | |
SDL_GL_SwapWindow(window); | |
} | |
SDL_DestroyRenderer(renderer); | |
SDL_DestroyWindow(window); | |
exit: | |
SDL_Quit(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment