Public feed #887415

Meins

public text v1 · immutable
Raw Edit
·published 2008-02-01 09:11 UTC
rendered paste body
#include <GL/glut.h>



void mySpecial(int specKey, int mouseX, int mouseY);

/* definitions for cuboid */
GLuint cuboid=1,axes=2;

float top[4][3]		= { 0, 20,0,  200, 20,0,   200,20,100,    0,20,100 };	/* vertex arrays for each rectangle */
float bottom[4][3]	= { 0, 0, 0, 200, 0, 0,  200,0, 100,   0,0, 100 };
float front[4][3]	= { 0, 0, 0,    200,0, 0,   200,20,0,    0, 20,0 };
float back[4][3]	= { 0,0,100,    200,0, 100,    200, 20, 100,     0, 20,100 };
float left[4][3]	= { 0, 0, 0,  0, 20,0,     0, 20,100,       0, 0, 100 };
float right[4][3]	= { 200,0, 0,  200,20,0, 200,20,100, 200,0, 100 };
int step=0;


/* Initializations */
static void myinit(void)
{   
    glClearColor (1.0, 1.0, 1.0, 1.0);	/* background color */



    glNewList(cuboid, GL_COMPILE);	

		glBegin(GL_QUADS);				/* front area of cuboid */
			glColor3f(1.0,0.0,0.0);
			glVertex3fv(front[0]);
			glVertex3fv(front[1]);
			glVertex3fv(front[2]);
			glVertex3fv(front[3]);

		glEnd();
		
		glBegin(GL_QUADS);				// back area of cuboid 
			glColor3f(0.0,0.0,0.0);
			glVertex3fv(back[0]);
			glVertex3fv(back[1]);
			glVertex3fv(back[2]);
			glVertex3fv(back[3]);

		glEnd();

		glBegin(GL_QUADS);				// left area of cuboid 
			glColor3f(0.0,0.0,0.0);
			glVertex3fv(left[0]);
			glVertex3fv(left[1]);
			glVertex3fv(left[2]);
			glVertex3fv(left[3]);

		glEnd();

		glBegin(GL_QUADS);				//right area of cuboid 
			glColor3f(0.0,0.0,0.0);
			glVertex3fv(right[0]);
			glVertex3fv(right[1]);
			glVertex3fv(right[2]);
			glVertex3fv(right[3]);

		glEnd();

		glBegin(GL_QUADS);				// top area of cuboid
			glColor3f(0.0,0.0,1.0);
			glVertex3fv(top[0]);
			glVertex3fv(top[1]);
			glVertex3fv(top[2]);
			glVertex3fv(top[3]);

		glEnd();

		glBegin(GL_QUADS);				//bottom area of cuboid
			glColor3f(0.0,1.0,0.0);
			glVertex3fv(bottom[0]);
			glVertex3fv(bottom[1]);
			glVertex3fv(bottom[2]);
			glVertex3fv(bottom[3]);

		glEnd();

			glBegin(GL_POINTS);
			glPointSize(10.0);
		glColor3f(1,0,0);
		glVertex3f(-5,-5,-5);
	glEnd();
	glEndList();
}


/* Creating the Scene */
static void RenderScene(void)
{	glMatrixMode(GL_MODELVIEW);
    glClear(GL_COLOR_BUFFER_BIT);					/* clears the color buffer */
	
	glLoadIdentity();
	glTranslatef(0,80,0);
	glCallList(cuboid);

	glLoadIdentity();
//	glTranslatef(0,60,0);		//tischbein verschieben, das ganze 4 mal
	glScalef(0.05,4, 0.1);		//korrekt formen
	glCallList(cuboid);


	glLoadIdentity();
	glTranslatef(190,0,0);		//tischbein verschieben, das ganze 4 mal
	glScalef(0.05,4, 0.1);		//korrekt formen
	glCallList(cuboid);

	glLoadIdentity();
	glTranslatef(190,0,90);		//tischbein verschieben, das ganze 4 mal
	glScalef(0.05,4, 0.1);		//korrekt formen
	glCallList(cuboid);

	glLoadIdentity();
	glTranslatef(0,0,90);		//tischbein verschieben, das ganze 4 mal
	glScalef(0.05,4, 0.1);		//korrekt formen
	glCallList(cuboid);

    glFlush ();											/* flushes OpenGL command queues and buffers */
}

/* Callback function to handle window dimensions and size changes */
static void myReshape(int w, int h)
{
	if(w>h) w=h;							/* cube doesn't change its design on resize */
	else h=w;

    glViewport(0, 0, w, h);	
    
	glMatrixMode(GL_PROJECTION);			/* sets the current projection matrix (applies following
											   matrix operations to the projection matrix stack)*/
    glLoadIdentity();						/* replace current matrix through identity matrix */

	gluPerspective(90.0, 1.0, 0.1, 500.0);				/* set perspective */
	gluLookAt(50, 150.0, -200.0, 100, 90, 50, 0.0, 1.0, 0.0);	/* set the viewpoint */


}


/* GLUT functions to set up the window */
void main(int argc, char** argv)
{
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_ALPHA | GLUT_DEPTH);
    glutInitWindowPosition (0, 0);
	glutInitWindowSize(500, 500);
   	glutInit(&argc, argv);
	glutCreateWindow ("Transformationsverfahren Aufgabe a");
    
    myinit();							/* Initialization */
    glutReshapeFunc (myReshape);		/* Function to call when window changes size */
    glutDisplayFunc(RenderScene);		/* Creating the Szene */		/* Key function */

    glutMainLoop();	
}