Question: In this assignment you will use OpenGL primitives to create a basic 2D scene. This scene should be visually interesting and allow for some interaction.
In this assignment you will use OpenGL primitives to create a basic 2D scene. This scene should be visually interesting and allow for some interaction. You should use at least the following OpenGL primitives that we have discussed so far in creating your scene: GL_POINTS (with varying sizes), GL_LINES, GL_LINE_STRIP, GL_TRIANGLES, GL_QUADS. Additionally, your scene should be composed of a number of the same shapes using local transformations to draw the shape in different places (use glPushMatrix()/glPopMatrix()). These primitives should be statically included in your scene. The clear color defined should be responsible for drawing at least some aspect of your scene (do not leave it as white). Your scene should contain at least 10 distinct regions. Be sure to color your scene and shapes. Dynamic scene: inspect the code provided to see how the keyboard and mouse click functions can be used to alter the scene. You should provide the functionality to add: a) points to the scene: with randomly assigned colors (the color for a point should stick with the point after added to the scene) b) lines to the scene: each new click should add a new end point to the line that is created c) a polygon to the scene: each click should add on to a polygon that is being generated The keyboard can be used to define which shape is being added to. The mouse click will then add the appropriate point to the shape point/line/polygon Bonus points will be awarded (maximum of 10 points) for: - the best scene - movement over time - shapes generated through functions You may start from the example OpenGL 2D application provided to you but you must draw the scene with the shapes you define in a sketch. Once complete, submit a Word document (.docx) that: 1) describes the functionality that was originally contained in the program 2) shows the sketch 3) contains the code, an output image of your scene before and after interacting with the scene 4) a brief description describing how you went about drawing the scene 5) if you included movement over time for bonus, include a short animation
#include#include #include using namespace std; #include // GLUT, include glu.h and gl.h float r1 = 1; float g1 = 0; float b1 = 0; float winW = 640; float winH = 480; vector< pair > boxes; bool drawboxes = true; /* Initialize OpenGL Graphics */ void initGL() { // Set "clearing" or background color //glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black and opaque glClearColor(1.0f, 1.0f, 1.0f, 1.0f); // Black and opaque } void drawBox(float x, float y, float size) { glColor3f(0,0,1); glBegin(GL_POLYGON); glVertex2f(x+size, y+size); glVertex2f(x-size, y+size); glVertex2f(x-size, y-size); glVertex2f(x+size, y-size); glEnd(); } const double PI = 3.14159; const double TWOPI = 6.28318; void drawStar(float x, float y, float s, int tips) { glColor3f(0,0,1); /* glBegin(GL_LINE_STRIP); for(int i=0; i
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
