Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

3.

Write a program that draw the following shape and apply the following 2d

Transformations to the Object using the formulas

a. Translation if the tx=150 And ty=100

Code

#include <GL\glut.h>

#include <iostream>

#include <windows.h>

using namespace std;

void myInit(void)

glClearColor(1.0, 1.0, 1.0, 1.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0.0, 400.0, 0.0, 400.0);

void myDisplay(void)

glClear(GL_COLOR_BUFFER_BIT);

glPointSize(2.0);

glColor3f(1.0f, 0.0f, 0.0f);

glPushMatrix();

glTranslatef(150, 100, 0);

glTranslatef(-150, -100, 0);

glBegin(GL_POLYGON);

glVertex2i(40, 40);

glVertex2i(320, 40);

glVertex2i(40, 200);

glVertex2i(320, 200);

glVertex2i(40, 200);
glVertex2i(40, 40);

glVertex2i(320, 200);

glVertex2i(320, 40);

glEnd();

glColor3f(0.0f, 1.0f, 1.0f);

glBegin(GL_POLYGON);

glVertex2i(10, 200);

glVertex2i(340, 200);

glVertex2i(200, 390);

glVertex2i(10, 200);

glVertex2i(200, 390);

glEnd();

glFlush();

int main(int argc, char** argv)

glutInit(&argc, argv);

glutInitDisplayMode(

GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(900, 740);

glutInitWindowPosition(0, 0);

glutCreateWindow("Basic hut like" " structure");

glutDisplayFunc(myDisplay);

myInit();

glutMainLoop();

return 0;

}
b. Scaling down by sx=0.5 and sy=1.5

#include <GL\glut.h>

#include <iostream>

#include <windows.h>

using namespace std;

void myInit(void)

glClearColor(1.0, 1.0, 1.0, 1.0);

glMatrixMode(GL_PROJECTION);

glLoadIdentity();

gluOrtho2D(0.0, 400.0, 0.0, 400.0);

void myDisplay(void)

glClear(GL_COLOR_BUFFER_BIT);

glPointSize(2.0);

glColor3f(1.0f, 0.0f, 0.0f);

glPushMatrix();

glScalef(0.5f, 1.5f,0.0f);

glBegin(GL_POLYGON);

glVertex2i(40, 40);

glVertex2i(320, 40);

glVertex2i(40, 200);

glVertex2i(320, 200);

glVertex2i(40, 200);

glVertex2i(40, 40);

glVertex2i(320, 200);

glVertex2i(320, 40);

glEnd();
glColor3f(0.0f, 1.0f, 1.0f);

glBegin(GL_POLYGON);

glVertex2i(10, 200);

glVertex2i(340, 200);

glVertex2i(200, 390);

glVertex2i(10, 200);

glVertex2i(200, 390);

glEnd();

glFlush();

int main(int argc, char** argv)

glutInit(&argc, argv);

glutInitDisplayMode(

GLUT_SINGLE | GLUT_RGB);

glutInitWindowSize(900, 740);

glutInitWindowPosition(0, 0);

glutCreateWindow("Basic hut like" " structure");

glutDisplayFunc(myDisplay);

myInit();

glutMainLoop();

return 0;

You might also like