rendered paste body#include <stdio.h>
#include <stdio.h>
#include <math.h>
#include <windows.h>
#include <GL/gl.h>
#include <GL/glut.h>
//#ifdef WIN32
// #define GLUTCALLBACK /**/
//#endif
/*================================================*/
GLfloat eckpunkte[8][3]= {
{0,0,1},
{1,0,1},
{1,0,0},
{0,0,0},
{0,1,1},
{1,1,1},
{1,1,0},
{0,1,0},
}; //eckpunkte in einem 2 dimensionalen Feld
GLfloat mat_diffuse[] ={1,0,0};
GLfloat mat_specular[]={0,1,1,1};
GLfloat mat_shininess[]={50};
GLfloat mat_back_diffuse[]={0,1,1};
GLfloat light_position[]={3,4,20,0};
GLfloat light_diffuse[]={1,0,1,1};
GLfloat light_specular[]={1,1,1,1};
GLfloat light_ambient[]={0,0,0.5,1};
GLuint WUERFEL=1;
GLuint KUGEL=3;
static void GLUTCALLBACK myinit(void)
{
GLUquadricObj *kugel;
kugel=gluNewQuadric();
/* Initializations */
glLightfv(GL_LIGHT1,GL_POSITION,light_position);
glLightfv(GL_LIGHT1,GL_DIFFUSE,light_diffuse);
glLightfv(GL_LIGHT1,GL_SPECULAR,light_specular);
glLightfv(GL_LIGHT1,GL_AMBIENT,light_ambient);
glClearColor (0.0, 0.0, 0.0, 0.0);
glNewList(KUGEL,GL_COMPILE);
glBegin(GL_LINE);
gluQuadricDrawStyle(kugel,GLU_FILL);
glMaterialfv(GL_FRONT,GL_DIFFUSE,mat_diffuse);
glMaterialfv(GL_FRONT,GL_SPECULAR,mat_specular);
glMaterialfv(GL_FRONT,GL_SHININESS,mat_shininess);
glMaterialfv(GL_BACK,GL_DIFFUSE,mat_back_diffuse);
gluSphere(kugel,0.8,16,16);
gluDeleteQuadric(kugel);
glEnd();
glEndList();
glNewList(WUERFEL,GL_COMPILE);
glBegin(GL_QUADS);
glColor3f(1,0,0);
glVertex3fv(eckpunkte[2]);
glColor3f(0,0,0);
glVertex3fv(eckpunkte[3]);
glColor3f(0,0,1);
glVertex3fv(eckpunkte[0]);
glColor3f(1,0,1);
glVertex3fv(eckpunkte[1]);
glEnd();
glBegin(GL_QUADS);
glColor3f(1,1,1);
glVertex3fv(eckpunkte[5]);
glColor3f(0,1,1);
glVertex3fv(eckpunkte[4]);
glColor3f(0,0,1);
glVertex3fv(eckpunkte[0]);
glColor3f(1,0,1);
glVertex3fv(eckpunkte[1]);
glEnd();
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3fv(eckpunkte[6]);
glColor3f(0,1,0);
glVertex3fv(eckpunkte[7]);
glColor3f(0,1,1);
glVertex3fv(eckpunkte[4]);
glColor3f(1,1,1);
glVertex3fv(eckpunkte[5]);
glEnd();
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3fv(eckpunkte[6]);
glColor3f(1,1,1);
glVertex3fv(eckpunkte[5]);
glColor3f(1,0,1);
glVertex3fv(eckpunkte[1]);
glColor3f(1,0,0);
glVertex3fv(eckpunkte[2]);
glEnd();
glBegin(GL_QUADS);
glColor3f(1,1,0);
glVertex3fv(eckpunkte[6]);
glColor3f(0,1,0);
glVertex3fv(eckpunkte[7]);
glColor3f(0,0,0);
glVertex3fv(eckpunkte[3]);
glColor3f(1,0,0);
glVertex3fv(eckpunkte[2]);
glEnd();
glBegin(GL_QUADS);
glColor3f(0,1,0);
glVertex3fv(eckpunkte[7]);
glColor3f(0,1,1);
glVertex3fv(eckpunkte[4]);
glColor3f(0,0,1);
glVertex3fv(eckpunkte[0]);
glColor3f(0,0,0);
glVertex3fv(eckpunkte[3]);
glEnd();
glEndList();
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
}
static void GLUTCALLBACK RenderScene(void){
/* Creating the Scene */
glClear(GL_COLOR_BUFFER_BIT);
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glTranslatef(-1.0,-0.5,2.0);
glCallList(KUGEL);
glPopMatrix();
glCallList(WUERFEL);
//glutSwapBuffers();
glFlush (); /* Flushes OpenGL command queues and buffers */
}
static void GLUTCALLBACK myReshape(int w, int h)
{
/* Callback function to handle window dimensions and size changes */
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION); /* specifies the current matrix */
glLoadIdentity(); /* Sets the currant matrix to identity */
gluPerspective(45,1,0.1,20);
gluLookAt(0, 2, 10, 0.5,0.5, -0.5, 0, 1, 0);
}
/* Main Loop */
void main(int argc, char** argv)
{
/* GLUT functions to set up the window */
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB );
glutInitWindowPosition (0, 0);
glutInitWindowSize(500, 500);
glutInit(&argc, argv);
glutCreateWindow ("Color Cube....");
myinit(); /* Initialization */
glutReshapeFunc(myReshape); /* Function to call when window changes size */
glutDisplayFunc(RenderScene); /* Creating the Szene */
glutMainLoop();
}