3d cube assgn added

This commit is contained in:
Tanmay 2023-12-07 10:26:55 +05:30
parent 8df4ca8691
commit 842822d2c8

View File

@ -0,0 +1,94 @@
#include<GL/glut.h>
void mydisplay()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity(); //resets modelview matrix
glTranslatef(0.0,0.0,-10.0);
//glScalef(2.0,2.0,0.0);
//glRotatef(20.0,1.0,0.0,0.0);
glRotatef(-45.0,0.0,1.0,0.0);
glBegin(GL_QUADS);
//front (red)
glColor3f(1.0,0.0,0.0);
glVertex3f(-1.0,1.0,1.0);
glVertex3f(-1.0,-1.0,1.0);
glVertex3f(1.0,-1.0,1.0);
glVertex3f(1.0,1.0,1.0);
//back (green)
glColor3f(0.0,1.0,0.0);
glVertex3f(1.0,1.0,-1.0);
glVertex3f(1.0,-1.0,-1.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f(-1.0,1.0,-1.0);
//right (blue)
glColor3f(0.0,0.0,1.0);
glVertex3f(1.0,1.0,1.0);
glVertex3f(1.0,-1.0,1.0);
glVertex3f(1.0,-1.0,-1.0);
glVertex3f(1.0,1.0,-1.0);
//left (yellow)
glColor3f(1.0,1.0,0.0);
glVertex3f(-1.0,1.0,-1.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f(-1.0,-1.0,1.0);
glVertex3f(-1.0,1.0,1.0);
//top (cyan)
glColor3f(0.0,1.0,1.0);
glVertex3f(-1.0,1.0,-1.0);
glVertex3f(-1.0,1.0,1.0);
glVertex3f(1.0,1.0,1.0);
glVertex3f(1.0,1.0,-1.0);
//bottom (magenta)
glColor3f(1.0,0.0,1.0);
glVertex3f(-1.0,-1.0,-1.0);
glVertex3f(-1.0,-1.0,1.0);
glVertex3f(1.0,-1.0,1.0);
glVertex3f(1.0,-1.0,-1.0);
glEnd();
glFlush();
}
void init()
{
glClearColor(0.0,0.0,0.0,1.0);
glEnable(GL_DEPTH_TEST);
}
void reshape(int w, int h)
{
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity(); //resets projection matrix
gluPerspective(60,1,2.0,50.0);
// glOrtho(-5,5,-5,5,-5,5);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc,char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH);
glutInitWindowPosition(100,100);
glutInitWindowSize(500,500);
glutCreateWindow("3D transformations");
glutDisplayFunc(mydisplay);
glutReshapeFunc(reshape);
init();
glutMainLoop();
}