Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <iostream>
- void refresh( GLFWwindow* window )
- {
- static double prv = glfwGetTime();
- const double cur = glfwGetTime();
- const double dt = ( cur - prv );
- prv = cur;
- int w, h;
- glfwGetFramebufferSize( window, &w, &h );
- glViewport( 0, 0, w, h );
- glClearColor( 0, 0, 0, 1 );
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- const float degPerSec = 45.0f;
- static float angle = 0.0f;
- angle += degPerSec * dt;
- glRotatef( angle, 0, 0, 1 );
- glScalef( 0.5, 0.5, 0.5 );
- glBegin( GL_TRIANGLES );
- glColor3ub( 255, 0, 0 );
- glVertex2f( 0, 1 );
- glColor3ub( 0, 255, 0 );
- glVertex2f( -1, -1 );
- glColor3ub( 0, 0, 255 );
- glVertex2f( 1, -1 );
- glEnd();
- glfwSwapBuffers( window );
- }
- void resize( GLFWwindow* window, int width, int height )
- {
- refresh( window );
- }
- int main( int argc, char** argv )
- {
- glfwInit();
- std::cout << "GLFW version: " << glfwGetVersionString() << std::endl;
- GLFWwindow* window = glfwCreateWindow( 640, 480, "Drag Test", NULL, NULL );
- glfwSetTime( 0.0 );
- glfwMakeContextCurrent( window );
- glewInit();
- glGetError();
- glfwSetWindowSizeCallback( window, resize );
- glfwSetWindowRefreshCallback( window, refresh );
- while( !glfwWindowShouldClose( window ) )
- {
- glfwPollEvents();
- refresh( window );
- }
- glfwDestroyWindow( window );
- glfwTerminate();
- return 0;
- }
Add Comment
Please, Sign In to add comment