Created
          March 26, 2016 22:49 
        
      - 
      
 - 
        
Save powerc9000/e6cc071544c32a6650ae to your computer and use it in GitHub Desktop.  
  
    
      This file contains hidden or 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
    
  
  
    
  | // The OpenGL libraries, make sure to include the GLUT and OpenGL frameworks | |
| #include <OpenGL/gl.h> | |
| #include <OpenGL/glu.h> | |
| #include <SDL2/SDL.h> | |
| #include <math.h> | |
| // This is just an example using basic glut functionality. | |
| // If you want specific Apple functionality, look up AGL | |
| float PI = 3.1415; | |
| int main(int argc, char **argv) | |
| { | |
| SDL_Window *window = SDL_CreateWindow( | |
| "SDL2/OpenGL Demo", 0, 0, 720, 720, | |
| SDL_WINDOW_OPENGL|SDL_WINDOW_RESIZABLE); | |
| // Create an OpenGL context associated with the window. | |
| SDL_GLContext glcontext = SDL_GL_CreateContext(window); | |
| // now you can make GL calls. | |
| int quit = 0; | |
| int color = 0; | |
| float spin = -0.5f; | |
| float beginRadians = 0.0f; | |
| int growShrink = 1; | |
| float growRate = .25f; | |
| float length = .5f; | |
| float x = 0; | |
| float y = 0; | |
| float y_speed = .7; | |
| float x_speed = .3f; | |
| SDL_Event event; | |
| float startingTick = SDL_GetTicks(); | |
| while(!quit){ | |
| while(SDL_PollEvent(&event)) | |
| { | |
| /* If a quit event has been sent */ | |
| if (event.type == SDL_QUIT) | |
| { | |
| /* Quit the application */ | |
| quit = 1; | |
| } | |
| } | |
| glClearColor(0,0,color,0); | |
| glClear(GL_COLOR_BUFFER_BIT); | |
| float rad = 1.25664f; | |
| float start = 1.5708f + beginRadians; | |
| for(int point = 0; point < 5; point++){ | |
| float next = start + (2*rad); | |
| glBegin(GL_LINES); | |
| glVertex3f(cos(start)*length+x, sin(start)*length+y, 0.0f); | |
| glVertex3f(cos(next)*length+x, sin(next)*length+y, 0.0f); | |
| glEnd(); | |
| start += rad; | |
| } | |
| float now = SDL_GetTicks(); | |
| float delta = (now - startingTick)/1000; | |
| beginRadians += spin * (delta); | |
| beginRadians = fmod(beginRadians, 2.0f * PI); | |
| length += (growShrink * growRate) * delta; | |
| x += x_speed * delta; | |
| y += y_speed * delta; | |
| if(y >= 1 || y <= -1){ | |
| y_speed *= -1; | |
| } | |
| if(x>= 1|| x <= -1){ | |
| x_speed *= -1; | |
| } | |
| if(length >= 1.0f){ | |
| growShrink = -1; | |
| } | |
| if(length <= .25f){ | |
| growShrink = 1; | |
| } | |
| SDL_GL_SwapWindow(window); | |
| // if(color == 1){ | |
| // color = 0; | |
| // } | |
| // else{ | |
| // color = 1; | |
| // } | |
| startingTick = now; | |
| } | |
| // Once finished with OpenGL functions, the SDL_GLContext can be deleted. | |
| SDL_GL_DeleteContext(glcontext); | |
| return 0; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment