0% found this document useful (0 votes)
3 views4 pages

Basic 2D transformation code

The document outlines a program for performing basic 2D transformations such as translation, rotation, and scaling using OpenGL. It includes a display function to draw a polygon and an options menu to select the desired transformation. The program initializes the OpenGL context and sets up the main loop for rendering the transformations on a window.

Uploaded by

alexmak11217
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views4 pages

Basic 2D transformation code

The document outlines a program for performing basic 2D transformations such as translation, rotation, and scaling using OpenGL. It includes a display function to draw a polygon and an options menu to select the desired transformation. The program initializes the OpenGL context and sets up the main loop for rendering the transformations on a window.

Uploaded by

alexmak11217
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Write a program to perform basic 2D transformation

(translation, rotation and scaling) about origin and about


a fixed point without using direct OpenGL functions for
the transformations.

include <GL/glut.h>

void display()

/* draw unit square polygon */

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_flOLYGO );

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

glVertex2f(150, 150);

glVertex2f(300, 150);

glVertex2f(225, 225);

glEnd();

/* flush GL buffers */

glFlush();

/* clear window */

void OptionsMenu(GLint selectedOpt)

switch (selectedOpt)

case 1:

/* draw unit square polygon */

glBegin(GL_flOLYGO );

glVertex2f(150, 150);

glVertex2f(300, 150);

glVertex2f(225,

225); glEnd();

/* flush GL buffers */
glFlush();

break;

case 2:

glRotatef(15, 0, 0, 1);

glColor3f(1.0f, 0.0f,

0.0f); break;

case 3:

glScalef(1.5, 1.5, 0);

glColor3f(0.0f, 1.0f,

0.0f); break;

case 4:

glTranslatef(100, 100, 0);

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

default: break;

void init()

glClearColor(0.0, 0.0, 0.0, 0.0);

// glflointSize(1.0);

glMatrixMode(GL_flROJECTIO );

glLoadIdentity();

gluOrtho2D(0.0, 800.0, 0.0, 800.0);}

void main(int argc, char** argv)

glutInit(fiargc, argv);

glutInitDisplayMode(GLUT_SI GLE |

GLUT_RGB); glutInitWindowSize(800,

800);

glutInitWindowflosition(0,

0);

glutCreateWindow("simple");

glutDisplayFunc(display);

glutCreateMenu(OptionsMenu

);

glutAddMenuEntry("flolygon

", 1);

glutAddMenuEntry("Rotate ", 2);


glutAddMenuEntry("Scale", 3);
glutAddMenuEntry("Transla

te ", 4);

glutAttachMenu(GLUT_RIG T_B

UTTO ); init();

glutMainLoop();}

You might also like