Skip to content

Instantly share code, notes, and snippets.

@skyfe79
Created June 24, 2012 05:28
Show Gist options
  • Save skyfe79/2981794 to your computer and use it in GitHub Desktop.
Save skyfe79/2981794 to your computer and use it in GitHub Desktop.
GLUT02
#include <OpenGL/OpenGL.h>
#include <GLUT/GLUT.h>
void renderScene(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0f, 0.0f, 0.0f);
glRectf(-25.0f, 25.0f, 25.0f, -25.0f);
glFlush();
}
void changeSize(GLsizei w, GLsizei h)
{
GLfloat aspectRatio;
if(h==0)
h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspectRatio = (GLfloat)w / (GLfloat)h;
if(w <= h)
glOrtho(-100, 100, -100/aspectRatio, 100/aspectRatio, 1.0, -1.0);
else
glOrtho(-100 * aspectRatio, 100*aspectRatio, -100.0, 100.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void setupRenderingContext(void)
{
glClearColor(0.0, 0.0, 0.0, 1.0f);
}
int main(int argc, const char * argv[])
{
glutInit(&argc, const_cast<char **>(argv));
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutCreateWindow("Hello GLUT");
glutReshapeFunc(changeSize);
glutDisplayFunc(renderScene);
setupRenderingContext();
glutMainLoop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment