SCT221-C004-0096-2019 Programming Assignment #2 2D Graphics in OpenGL
SCT221-C004-0096-2019 Programming Assignment #2 2D Graphics in OpenGL
Programming Assignment #2
2D Graphics in OpenGL
3. Write an OpenGL program that allows interactive creation of polygons via mouse input. That
is, I click to create new vertices until I like the polygon, then make some indication (double
click, right click, press a key, click a button; your choice) that I’m done, and the polygon is
created.
#include <stdlib.h>
#include <stdarg.h>
#include <GLUT/GLUT.h>
#include <OpenGL/OpenGL.h>
double width=600;
double height=600;
bool down=false;;
// window size
#define maxWD 640
#define maxHT 480
// rotation speed
#define thetaSpeed 0.05
// check overflow
if (theta >= (2.0 * 3.14159))
theta = theta - (2.0 * 3.14159);
// actual calculations..
xf = cx + (int)((float)(px - cx) * cos(theta))
- ((float)(py - cy) * sin(theta));
yf = cy + (int)((float)(px - cx) * sin(theta))
+ ((float)(py - cy) * cos(theta));
// update
px = px + tx;
py = py + ty;
// update
fx = px * sx;
fy = py * sy;
glFlush();
// creating a delay
// so that the point can be noticed
delay(500);
glClear(GL_COLOR_BUFFER_BIT);
// update
fx = px;
fy = py;