Created
June 6, 2013 00:41
-
-
Save gszauer/5718491 to your computer and use it in GitHub Desktop.
This file contains 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
#include <cmath> | |
#include <vector> | |
#include <map> | |
#include <iostream> | |
#include <OpenGL/gl.h> | |
#include <GLUT/glut.h> | |
#define WINFOW_TITLE "Window Template" | |
#define WINDOW_WIDTH 400 | |
#define WINDOW_HEIGHT 250 | |
#define UPDATE_TIME 17 /* ((1 / 60) * 1000) rounded up */ | |
void Initialize(); | |
void Shutdown(); | |
void display(); | |
void updateTimer(int windowId); | |
void reshape(int width, int height); | |
void glPerspective(float fov, float aspectRatio, float znear, float zfar); | |
int main(int argc, char** argv) { | |
glutInit(&argc, argv); | |
glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH); | |
glutInitWindowPosition(0,0); | |
glutInitWindowSize(WINDOW_WIDTH , WINDOW_HEIGHT); | |
glutCreateWindow(WINFOW_TITLE); | |
reshape(WINDOW_WIDTH, WINDOW_HEIGHT); | |
glutDisplayFunc(display); | |
glutReshapeFunc(reshape); | |
glutTimerFunc(UPDATE_TIME, updateTimer, glutGetWindow()); | |
Initialize(); | |
atexit(Shutdown); | |
glutMainLoop(); | |
return 0; | |
} | |
void Shutdown() { | |
} | |
void Initialize() { | |
} | |
void display() { | |
glClearColor(0.5f, 0.6f, 0.7f, 0.0f); | |
glClear(GL_COLOR_BUFFER_BIT); | |
glutSwapBuffers(); | |
} | |
void updateTimer(int windowId) { | |
glutTimerFunc(UPDATE_TIME, updateTimer, windowId); | |
} | |
void reshape(int width, int height) { | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
glViewport(0, 0, width, height); | |
glPerspective(60.0f, width / height, 0.01f, 1000.0f); | |
//glOrtho(0.0f, 1.0f, 1.0f, 0.0f, -100.0f, 100.0f); | |
glMatrixMode(GL_MODELVIEW); | |
} | |
void glPerspective(float fov, float aspectRatio, float znear, float zfar) { | |
float ymax = znear * tanf(fov * M_PI / 360.0f); | |
float xmax = ymax * aspectRatio; | |
glFrustum(-xmax, xmax, -ymax, ymax, znear, zfar); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment