#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
GLfloat Cx = 0, Cy = 0, Cz = 3;
static int Angle = 0;
const GLfloat vertices[] =
{ 2,0,-1, 2,1,-1, -2,1,-1, -2,0,-1, /* hintere Wand */
2,0, 1, 2,1, 1, -2,1, 1, -2,0, 1, /* vordere Wand */
2,2,0, -2,2,0,
2.2 ,2 ,0 , -2.2 ,2 ,0 , /* Dachfirst */
2.2 ,0.9 , -1.1 , -2.2 ,0.9 , -1.1 , /* Dachkanten */
2.2 ,0.9 ,1.1 , -2.2 ,0.9 ,1.1 ,
1 ,0 ,0.5 , 1.25 ,0 ,0.5 , 1.25 ,0 ,0.25 , 1 ,0 ,0.25 , /* Schornstein */
1 ,2.5 ,0.5 , 1.25 ,2.5 ,0.5 , 1.25 ,2.5 ,0.25 , 1 ,2.5 ,0.25 };
const GLint triangles[] =
{ 0, 3, 2,
2, 1, 0,
4, 0, 1,
1, 5, 4,
7, 4, 5,
5, 6, 7,
3, 7, 6,
6, 2, 3,
0, 4, 7,
7, 3, 0,
5, 1, 8,
2, 6, 9,
10, 11, 15,
15, 14, 10,
10, 12, 13,
13, 11, 10,
17, 16, 19,
19, 18, 17,
17, 21, 20,
20, 16, 17,
17, 18, 22,
22, 21, 17,
18, 19, 23,
23, 22, 18,
19, 16, 20,
20, 23, 19,
23, 20, 21,
21, 22, 23};
const float colors[] = {
1.0f, 0.0f, 0.0f, 1.0f, // Set The Color To Red with full luminance
0.0f, 1.0f, 0.0f, 1.0f, // Set The Color To Green with full luminance
0.0f, 0.0f, 1.0f, 1.0f // Set The Color To Blue with full luminance
};
void display(void)
{
glEnable(GL_DEPTH_TEST);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glFrustum(-1, 1, -1, 1, 1, 10);
gluLookAt(1, 2, 4, 0, 0, 0, 0, 1, 0);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glRotatef((GLfloat)Angle, 0.0, 1.0, 0.0);
glVertexPointer(3, GL_FLOAT, 0, vertices);
glColorPointer(4, GL_FLOAT, 0, colors);
glDrawElements(GL_TRIANGLES, 27*3, GL_UNSIGNED_INT, triangles);
glDisableClientState(GL_VERTEX_ARRAY);
glFlush();
}
void special(int key, int, int) {
switch (key) {
case GLUT_KEY_LEFT: (Angle += 5) %= 360; break;
case GLUT_KEY_RIGHT: (Angle -= 5) %= 360; break;
default: return;
}
glutPostRedisplay();
}
void keyboard(unsigned char c, int x, int y) {
static int fillMode = GL_FILL;
fillMode = (fillMode == GL_FILL) ? GL_LINE : GL_FILL;
glPolygonMode(GL_FRONT_AND_BACK, fillMode);
glutPostRedisplay();
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowSize(800, 600);
glutCreateWindow("Vertexarray");
glutKeyboardFunc(keyboard);
glutSpecialFunc(special);
glutDisplayFunc(display);
glutMainLoop();
return 0;
} |