1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
#include <GL/glfw.h>
#include <math.h>
int main()
{
int width, height;
float frame = 0;
float angle = 0;
float distance = 20;
bool running = true;
glfwInit();
if( !glfwOpenWindow( 512, 512, 0, 0, 0, 0, 0, 0, GLFW_WINDOW ) )
{
glfwTerminate();
return 0;
}
glfwSetWindowTitle("GLFW Application");
while(running)
{
frame++;
angle = frame/100;
glfwGetWindowSize( &width, &height );
height = height > 0 ? height : 1;
glViewport( 0, 0, width, height );
glClearColor( 0.0f, 0.0f, 0.0f, 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 95.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f );
glTranslatef(sin(angle)*distance, 1.0f, cos(angle)*distance );
// Draw some rotating garbage
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
gluLookAt(0.0f, -10.0f, 0.0f,
0.0f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f );
//glTranslatef( 1.0f, 1.0f, 0.0f );
//glRotatef(frame*2, 2.00f, 0.00f, 0.75f);
glBegin( GL_TRIANGLES );
glColor3f(0.1f, 0.0f, 0.0f );
glVertex3f(0.1f, 0.0f, -4.0f);
glColor3f(1.0f, 1.0f, 0.0f );
glVertex3f(0.1f, 0.0f, 4.0f);
glColor3f(0.0f, 0.0f, 1.0f );
glVertex3f(-2.0f, 0.0f, 0.0f);
glEnd();
glBegin( GL_TRIANGLES );
glColor3f(1.0f, 0.1f, 0.0f );
glVertex3f(-0.1f, 0.0f, -4.0f);
glColor3f(0.0f, 0.0f, 1.0f );
glVertex3f(-0.1f, 0.0f, 4.0f);
glColor3f(1.0f, 0.0f, 0.0f );
glVertex3f(-2.0f, 0.0f, 0.0f);
glEnd();
glfwSwapBuffers();
// exit if ESC was pressed or window was closed
running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam( GLFW_OPENED);
}
glfwTerminate();
return 0;
}
|