Here I am trying to draw a cube with three faces.One face is red, one green and one blue.
Then I rotate the cube in a way that I should see half of the red face and half of the green face, of 45 degrees around the y axis.I should see a half red and half green cube, but I only see the red face, that’s the code:
#import <OpenGL/OpenGL.h>
#import <GLUT/GLUT.h>
int width=500, height=500, depth=500;
void init()
{
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glEnable(GL_DEPTH_TEST);
glViewport(0, 0, width, height);
glOrtho(0, width, height, 0, 0, depth);
}
void display()
{
glClearColor(0.9, 0.9, 0.9, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBegin(GL_QUADS);
gluLookAt(250, 250, 0, -250, 250, 250, 0, 1, 0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(45, 0, 1, 0);
// First face
glColor4f(1, 0, 0, 0);
glVertex3i(100, 100,0);
glVertex3i(300, 100,0);
glVertex3i(300, 300,0);
glVertex3i(100, 300,0);
// Second face
glColor4f(0, 1, 0, 0);
glVertex3i(300,100,0);
glVertex3i(300,300,0);
glVertex3i(300,100,300);
glVertex3i(300,100,300);
// Third face
glColor4f(0, 0, 1, 0);
glVertex3i(100, 100,300);
glVertex3i(300, 100,300);
glVertex3i(300, 300,300);
glVertex3i(100, 300,300);
glEnd();
glFlush();
}
int main(int argc, char * argv[])
{
glutInit(&argc, argv);
glutInitWindowPosition(100, 100);
glutInitWindowSize(width, height);
glutCreateWindow("Test");
glutDisplayFunc(display);
init();
glutMainLoop();
return 0;
}
PS: Code outdated because my university is outdated