Assignment01
Assignment01
Assignment01
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
void init(){
glClearColor(0.0,0.0,1.0,1.0);
glOrtho(-20,20,-20,20,-20,20);
}
02. Translation of Star Shape by taking user input of Tx & Ty Source Code
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include<bits/stdc++.h>
using namespace std;
float Tx = 0.0;
float Ty = 0.0;
void translation(void)
{
glBegin(GL_POLYGON);
glVertex2f(2,2);
glVertex2f(2,-2);
glVertex2f(-2,-2);
glVertex2f(-2,2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(5,0);
glVertex2f(2,2);
glVertex2f(2,-2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0,5);
glVertex2f(-2,2);
glVertex2f(2,2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(-5,0);
glVertex2f(-2,-2);
glVertex2f(-2,2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0,-5);
glVertex2f(2,-2);
glVertex2f(-2,-2);
glEnd();
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.22,0.99,0.11);
glLoadIdentity();
glTranslatef(Tx,Ty,0);
translation();
glFlush();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-15,15,-15,15,-15,15);
glMatrixMode(GL_MODELVIEW);
}
-----------------------------------------------------------------------------------
-----------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------
03. Rotations of Star Shape by taking user input of angle source code
#include <windows.h>
#include <iostream>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
//Initializes 3D rendering
void initRendering()
{
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL); //Enable color
glClearColor(0.7f, 0.9f, 1.0f, 1.0f); //Change the background to sky blue
}
float _angle;
float _cameraAngle = 0.0f;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glRotatef(-_cameraAngle, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, -5.0f);
glPushMatrix();
glTranslatef(0.0f, -1.0f, 0.0f);
glRotatef(_angle, 0.0f, 0.0f, -1.0f);
glBegin(GL_POLYGON);
glVertex2f(0.2,0.2);
glVertex2f(0.2,-0.2);
glVertex2f(-0.2,-0.2);
glVertex2f(-0.2,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.5,0.0);
glVertex2f(0.2,0.2);
glVertex2f(0.2,-0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.0,0.5);
glVertex2f(-0.2,0.2);
glVertex2f(0.2,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(-0.5,0.0);
glVertex2f(-0.2,-0.2);
glVertex2f(-0.2,0.2);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(0.0,-0.5);
glVertex2f(0.2,-0.2);
glVertex2f(-0.2,-0.2);
glEnd();
glPopMatrix();
glutSwapBuffers();
}
glutMainLoop();
return 0;
}
-----------------------------------------------------------------------------------
-----------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------
#ifdef __APPLE__
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include <stdlib.h>
#include<bits/stdc++.h>
using namespace std;
void reflections() {
glBegin(GL_POLYGON);
glVertex2f(3, 6); // Top right
glVertex2f(5, 6); // Top left
glVertex2f(5, 4); // Bottom left
glVertex2f(3, 4); // Bottom right
glEnd();
glBegin(GL_POLYGON);
glVertex2f(4, 7.5);
glVertex2f(5, 6);
glVertex2f(3, 6);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(5, 6);
glVertex2f(6.5, 5);
glVertex2f(5, 4);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(5, 4);
glVertex2f(4, 2.5);
glVertex2f(3, 4);
glEnd();
glBegin(GL_POLYGON);
glVertex2f(3, 4);
glVertex2f(1.5, 5);
glVertex2f(3, 6);
glEnd();
}
void display() {
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glLoadIdentity();
reflections();
glPushMatrix();
glScalef(1.0, -1.0, 1.0); // Reflect vertically
glColor3f(0.0, 1.0, 0.0); // Green color
reflections();
glPopMatrix();
glPushMatrix();
glScalef(-1.0, -1.0, 1.0); // Reflect both horizontally and vertically
glColor3f(0.0, 0.0, 1.0); // Blue color
reflections();
glPopMatrix();
glFlush();
}
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}