Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <GL/glut.h>
typedef float Point2f [2];
GLfloat v [6][3] = {{-1.0, 0.0, -1.0}, {1.0, 0.0, -1.0},
{-1.0, 0.0, 1.0}, {1.0, 0.0, 1.0},
{0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}};
GLfloat colors [6][3] = {{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0},
{0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
{1.0, 0.0, 1.0}, {0.0, 1.0, 1.0}};
void side (GLfloat * a, GLfloat * b, GLfloat * c, GLfloat * d) {
glVertex3fv (a);
glVertex3fv (b);
glVertex3fv (c);
// glVertex3fv (d);
}
void octo (GLfloat * a, GLfloat * b, GLfloat * c, GLfloat * d,
GLfloat * e, GLfloat * f, GLfloat * g, GLfloat * h) {
glColor3fv (colors [0]);
side (a, b, d, c);
glColor3fv (colors [1]);
side (c, d, f, e);
glColor3fv (colors [2]);
side (e, f, h, g);
glColor3fv (colors [3]);
side (g, h, b, a);
glColor3fv (colors [4]);
side (a, c, e, g);
glColor3fv (colors [5]);
side (b, d, f, h);
}
void display ( ) { // need one such function per callback method
char * name = "octahedron";
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ( );
glBegin (GL_TRIANGLE_STRIP);
octo (v [0], v [1], v [2], v [3], v [4], v[5], v[6], v[7]);
glEnd ( );
glPopMatrix ( );
glFlush ( );
}
void myReshape (int w, int h) {
GLfloat aspect;
glViewport (0, 0, w, h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ( );
aspect = (GLfloat) h / (GLfloat) w;
glOrtho (-5.0, 5.0, -5.0, 5.0, -5.0, 5.0);
gluPerspective (10.0, aspect, 10.0, -10.0);
gluLookAt (5.0, 5.0, 10.0, 0.5, 1.0, 1.0, 0.0, 1.0, 0.0);
glMatrixMode (GL_MODELVIEW);
glutPostRedisplay ( );
}
int main (int argc, char ** argv) {
/* 3D initialization stuff */
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize (500, 500);
glutInitWindowPosition (100,100);
glutCreateWindow ("Octahedron");
glutReshapeFunc (myReshape);
glutDisplayFunc (display); /* display callback invoked when window opened */
glEnable (GL_DEPTH_TEST);
glClearColor (1.0, 1.0, 1.0, 1.0); /* white background */
glutMainLoop ( );
return 0;
}
Thanks again.