Last active
December 17, 2015 16:59
-
-
Save suzumura-ss/5643098 to your computer and use it in GitHub Desktop.
GLUTでteapotを表示
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 <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