genpfault

https://stackoverflow.com/a/50457770

May 22nd, 2018
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.63 KB | None | 0 0
  1. #include <GL/glew.h>
  2. #include <GLFW/glfw3.h>
  3. #include <iostream>
  4.  
  5. void refresh( GLFWwindow* window )
  6. {
  7.     static double prv = glfwGetTime();
  8.     const double cur = glfwGetTime();
  9.     const double dt = ( cur - prv );
  10.     prv = cur;
  11.  
  12.     int w, h;
  13.     glfwGetFramebufferSize( window, &w, &h );
  14.     glViewport( 0, 0, w, h );
  15.  
  16.     glClearColor( 0, 0, 0, 1 );
  17.     glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  18.  
  19.     glMatrixMode( GL_PROJECTION );
  20.     glLoadIdentity();
  21.  
  22.     glMatrixMode( GL_MODELVIEW );
  23.     glLoadIdentity();
  24.  
  25.     const float degPerSec = 45.0f;
  26.     static float angle = 0.0f;
  27.     angle += degPerSec * dt;
  28.  
  29.     glRotatef( angle, 0, 0, 1 );
  30.  
  31.     glScalef( 0.5, 0.5, 0.5 );
  32.     glBegin( GL_TRIANGLES );
  33.     glColor3ub( 255, 0, 0 );
  34.     glVertex2f(  0,  1 );
  35.     glColor3ub( 0, 255, 0 );
  36.     glVertex2f( -1, -1 );
  37.     glColor3ub( 0, 0, 255 );
  38.     glVertex2f(  1, -1 );
  39.     glEnd();
  40.  
  41.     glfwSwapBuffers( window );
  42. }
  43.  
  44. void resize( GLFWwindow* window, int width, int height )
  45. {
  46.     refresh( window );
  47. }
  48.  
  49. int main( int argc, char** argv )
  50. {
  51.     glfwInit();
  52.     std::cout << "GLFW version: " << glfwGetVersionString() << std::endl;
  53.     GLFWwindow* window = glfwCreateWindow( 640, 480, "Drag Test", NULL, NULL );
  54.     glfwSetTime( 0.0 );
  55.     glfwMakeContextCurrent( window );
  56.     glewInit();
  57.     glGetError();
  58.  
  59.     glfwSetWindowSizeCallback( window, resize );
  60.     glfwSetWindowRefreshCallback( window, refresh );
  61.     while( !glfwWindowShouldClose( window ) )
  62.     {
  63.         glfwPollEvents();
  64.         refresh( window );
  65.     }
  66.  
  67.     glfwDestroyWindow( window );
  68.     glfwTerminate();
  69.     return 0;
  70. }
Add Comment
Please, Sign In to add comment