particles

Particle systems
git clone git://git.electrosoup.com/particles
Log | Files | Refs | README | LICENSE

main.c (1431B)


      1 #include "glad/glad.h"
      2 
      3 #include <SDL2/SDL.h>
      4 #include <SDL2/SDL_opengl.h>
      5 #include <stdio.h>
      6 
      7 const int WIDTH = 512, HEIGHT = 512;
      8 
      9 int main(int argc, char** argv)
     10 {
     11     if (SDL_Init(SDL_INIT_VIDEO) < 0)
     12     {
     13         fprintf(stderr, "SDL INIT ERROR: %s\n", SDL_GetError());
     14         exit(EXIT_FAILURE);
     15     }
     16 
     17     SDL_Window* window = SDL_CreateWindow("Particles", 100, 100, WIDTH,
     18             HEIGHT, SDL_WINDOW_OPENGL);
     19     if (window == NULL)
     20     {
     21         fprintf(stderr, "SDL WINDOW ERROR: %s\n", SDL_GetError());
     22         exit(EXIT_FAILURE);
     23     }
     24 
     25     SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK,
     26             SDL_GL_CONTEXT_PROFILE_CORE);
     27     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
     28     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
     29 
     30     SDL_GLContext context = SDL_GL_CreateContext(window);
     31     if (context == NULL)
     32     {
     33         fprintf(stderr, "SDL GL CONTEXT ERROR: %s\n", SDL_GetError());
     34         exit(EXIT_FAILURE);
     35     }
     36 
     37     gladLoadGLLoader(SDL_GL_GetProcAddress);
     38     
     39     glViewport(0, 0, WIDTH, HEIGHT);
     40     glClearColor(0.1f, 0.4f, 0.8f, 1.0f);
     41 
     42     SDL_Event window_event;
     43     while (1)
     44     {
     45         if (SDL_PollEvent(&window_event))
     46         {
     47             if (window_event.type == SDL_QUIT)
     48             {
     49                 break;
     50             }
     51         }
     52 
     53         glClear(GL_COLOR_BUFFER_BIT);
     54 
     55         SDL_GL_SwapWindow(window);
     56     }
     57 
     58     SDL_DestroyWindow(window);
     59     SDL_Quit();
     60 }