Created
May 2, 2012 17:37
-
-
Save batizhevsky/2578556 to your computer and use it in GitHub Desktop.
Шаблон для приложения opengl+glut+osx
This file contains hidden or 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 <stdlib.h> | |
#include <GLUT/glut.h> | |
#include <OpenGL/gl.h> | |
#include <OpenGL/glu.h> | |
#define kWindowWidth 640 | |
#define kWindowHeight 480 | |
unsigned int delay= 10; | |
GLvoid InitGL(GLvoid) | |
{ | |
glShadeModel(GL_SMOOTH); | |
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); | |
glClearDepth(1.0f); | |
glEnable(GL_DEPTH_TEST); | |
glDepthFunc(GL_LEQUAL); | |
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); | |
} | |
GLvoid DrawGLScene(GLvoid) | |
{ | |
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |
glLoadIdentity(); | |
//code | |
glutSwapBuffers(); | |
} | |
GLvoid ReSizeGLScene( GLsizei width, GLsizei height) | |
{ | |
if (height == 0) | |
{ | |
height = 1; | |
} | |
glViewport(0, 0, width, height); | |
glMatrixMode(GL_PROJECTION); | |
glLoadIdentity(); | |
gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f); | |
glMatrixMode( GL_MODELVIEW ); | |
glLoadIdentity(); | |
} | |
GLvoid keyPressed(unsigned char key, int x, int y) | |
{ | |
switch (key) { | |
case 27: //ESC to exit | |
exit(0); | |
break; | |
default: | |
break; | |
} | |
} | |
void timer(int value){ | |
//update the display | |
glutPostRedisplay(); | |
//the timer function replaces idle AND is placed here | |
glutTimerFunc(delay, timer, 0); | |
} | |
int main(int argc, char** argv) | |
{ | |
glutInit(&argc, argv); | |
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH); | |
glutInitWindowSize(kWindowWidth, kWindowHeight); | |
glutInitWindowPosition (100, 200); | |
glutCreateWindow (argv[0]); | |
InitGL(); | |
glutDisplayFunc(&DrawGLScene); | |
glutReshapeFunc(&ReSizeGLScene); | |
//glutIdleFunc(&DrawGLScene); //Плохо | |
glutTimerFunc(delay, timer, 0); | |
glutKeyboardFunc(&keyPressed); | |
glutMainLoop(); | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment