Computergraphik_Hopp/Code/template_culling.c

81 lines
2 KiB
C
Raw Permalink Normal View History

2018-10-24 15:03:05 +02:00
#include <GL/glut.h>
#include <string.h>
int width = 800;
int height = 600;
2018-10-31 14:45:06 +01:00
void init(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE);
glutInitWindowSize(width, height);
glutInitWindowPosition(100, 100);
glViewport(0, 0, width, height);
glutCreateWindow("Culling");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0);
gluLookAt(0.25, 0.5, 0.1, 0, 0, 0, 0, 1, 0);
////////////////////////////////////////////////////////////////////
2018-10-24 15:03:05 +02:00
glEnable(GL_CULL_FACE);
glCullFace(GL_FRONT);
2018-10-31 14:45:06 +01:00
////////////////////////////////////////////////////////////////////
2018-10-24 15:03:05 +02:00
}
void display(void)
{
2018-10-31 14:45:06 +01:00
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
// FRONT
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
// BACK
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glColor3f(0.0f, 1.0f, 0.0f);
// LEFT
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
// RIGHT
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glColor3f(0.0f, 0.0f, 1.0f);
// BOTTOM
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
2018-10-24 15:03:05 +02:00
glEnd();
2018-10-31 14:45:06 +01:00
glFlush();
2018-10-24 15:03:05 +02:00
}
int main(int argc, char** argv)
{
2018-10-31 14:45:06 +01:00
init(argc, argv);
glutDisplayFunc(display);
glutMainLoop();
return 0;
2018-10-24 15:03:05 +02:00
}