Skip to content

Instantly share code, notes, and snippets.

@suzumura-ss
Last active December 17, 2015 16:59
Show Gist options
  • Save suzumura-ss/5643098 to your computer and use it in GitHub Desktop.
Save suzumura-ss/5643098 to your computer and use it in GitHub Desktop.
GLUTでteapotを表示
#include <GL/glut.h>
void display(void)
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glClearColor(0.0, 0.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColor3d(1.0, 0.0, 0.0);
GLfloat light0pos[] = { 1.0, 3.0, 1.0, 1.0 };
glLightfv(GL_LIGHT0, GL_POSITION, light0pos);
float diffuse[] = {1.0, 0.0, 0.0, 1.0};
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse);
static float rot = 0.0f;
glPushMatrix();
glRotatef(rot, 1, 0, 0);
glRotatef(rot * 1.1, 0, 1, 0);
glutSolidTeapot(0.5);
glPopMatrix();
rot += 0.1;
glutSwapBuffers();
}
void reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.5, 1.5, -1.5, 1.5, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void keyboard(uint8_t key, int x, int y)
{
switch (key) {
case 'q':
exit(0);
default:
break;
}
}
void idle()
{
glutPostRedisplay();
}
int main(int argc, char* argv[])
{
glutInitWindowPosition(200, 200);
glutInitWindowSize(800, 600);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DOUBLE|GLUT_DEPTH);
glutCreateWindow(argv[0]);
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutKeyboardFunc(keyboard);
glutIdleFunc(idle);
glutMainLoop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment