#define GLFW_DLL
#include <windows.h>
#include <glfw3.h>
#include <gl/glu.h>
#include <iostream>
GLFWwindow* window = NULL;
static void Keyboard(GLFWwindow *window, int key, int scancode, int action, int mods)
{
if(key == 256)//ESC = 256
{
glfwTerminate();
exit(-1);
}
}
int main()
{
int width = 512, height = 512;
int frame = 0;
if(!glfwInit())
throw std::runtime_error("glfwInit failed");
window = glfwCreateWindow(width, height, "Rotating Triangles",NULL, NULL);
if(!window)
throw std::runtime_error("glfwOpenWindow failed.");
glfwMakeContextCurrent(window);
//defines the keyboard callback as the global function above
glfwSetKeyCallback(window, Keyboard);
while(!glfwWindowShouldClose(window))
{
frame++;
// cout << frame << endl;
glfwGetWindowSize(window, &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( 65.0f, (GLfloat)width/(GLfloat)height, 1.0f, 100.0f );
// 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, 0.25f, 1.0f, 0.75f);
glBegin( GL_TRIANGLES );
glColor3f(0.1f, 0.0f, 0.0f );
glVertex3f(0.0f, 3.0f, -4.0f);
glColor3f(0.0f, 1.0f, 0.0f );
glVertex3f(3.0f, -2.0f, -4.0f);
glColor3f(0.0f, 0.0f, 1.0f );
glVertex3f(-3.0f, -2.0f, -4.0f);
glEnd();
glBegin( GL_TRIANGLES );
glColor3f(0.0f, 0.1f, 0.0f );
glVertex3f(0.0f, 3.0f, -3.0f);
glColor3f(0.0f, 0.0f, 1.0f );
glVertex3f(3.0f, -2.0f, -2.0f);
glColor3f(1.0f, 0.0f, 0.0f );
glVertex3f(-3.0f, -2.0f, 2.0f);
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
glfwTerminate();
return 0;
}