Question: By using Microsoft Visual Studio 2 0 2 2 community : Aim: to implement a simple 2 D drawing program using GLUT and OpenGL Work

By using Microsoft Visual Studio 2022 community :
Aim: to implement a simple 2D drawing program using GLUT and OpenGL
Work in a team of max 6 students.
Using the SimplePaintProgram.cpp as your base, implement a simple 2D 'paint' program using OpenGL and GLUT, with the following OpenGL primitives:
- GL_POINTS
- GL_LINES
- GL_LINE_LOOP
- GL_TRIANGLES
- GL_QUADS
- Points - single mouse click (boring... yawn!!)
- Lines - two mouse clicks to specify endpoints
- Triangles (both wireframe and filled)- three mouse clicks to specify vertices
- Squares (both wireframe and filled)- two mouse clicks to specify two diagonal corners
- Circles (wireframe)- two mouse clicks to specify centre and radius
- Also provide options to clear the drawing area and to exit the program (use GLUT bitmap characters to display these options)
Right clicking the mouse should bring up a menu. Use GLUT menus and submenus to implement the following:
- A colour submenu - for the user to select a drawing colour (provide at least 8 different colours to choose from)
- A point size submenu - for the user to select a point size for drawing points (provide at least 6 point sizes to choose from)
- A line width submenu - for the user to select a line width for the wireframe shapes (provide at least 6 point sizes to choose from)
- An option to clear screen
- An option to exit the program
- The drawing canvas must be kept separate from the user interface (i.e. shapes must not be drawn in the user interface).
This is the demo code that u will modified :
f* Filename: SimplePaintProgram.cpp
Date: 6 January 2010
Description: This is a simple paint program that can draw lines and points. Upon pressing the 'c' or 'r' key on the keyboard, the drawing area will clear. The program will close when the 'e' key is pressed.
```
Modification Log: -
*/
```
#include
#include
#include
#define LINE 1
#define POINT 2
#define CLEAR 3
//initialize global variables
int point_size=1;
int line_size=1;
int X1=1, X2=-1, Y1=-1, Y2=-1;
bool P1= false, P2=false, P3=false, Cleared=false, Cleared2=false, Line=false, Point=false;
char "shape="No Shape Selected"; ```
//this function draws the program's panels
void drawPanel()
{
//panel backgound
gIBegin(GL_QUADS);
gIColor3f(1,0,1);
glVertex2i(0,0);
glVertex2i(0,60);
gIVertex2i(600,60);
glVertex2i(600,0);
glEnd();
//panel lines
glBegin(GL_LINES);
gIColor3f(0,0,0);
glVertex2i(0,60);
gIVertex2i(600,60);
glVertex2i(0,30);
glVertex2i(600,30);
glVertex2i(120,60);
glVertex2i(120,0);
glEnd();
//this draws image of a point on its button
glBegin(GL_POINTS);
glColor3f(0,0,0);
glVertex2i(61,45);
glVertex2i(61,46);
glVertex2i(60,45);
glVertex2i(60,46);
glEnd();
//this draws image of a line on its button
glBegin(GL_LINES);
glColor3f(0,0,0);
glVertex2i(30,15);
glVertex2i(90,15);
glEnd();
//this displays the shape status on the panel
glColor3f(0,0,0);
int tlength = strlen(shape);
glRasterPos3f(178,37,0);
for (int counter=0; counter =tlength; counter++){
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, shape[counter]);
}
}
//this function draws points on the drawing area when the point button is selected
void drawPoint()
{
if(P1==true)
``````
{
glPointSize(point_size); //set point size
glBegin(GL_POINTS);
glColor3f(0,0,0);
glVertex2i(X1,Y1);
glEnd();
P1=false;
}
}
//this draws lines on the drawing area when the line button is selected
/la line is drawn by clicking twice on the drawing area
void drawLine()
{
if(P1==true && P2==true)
{
glLineWidth(line_size);
glBegin(GL_LINES);
glColor3f(0,0,0);
gIVertex2i(X1,Y1);
gIVertex2i(X2,Y2);
glEnd();
P1=false;
P2=false;
}
}
//this is where all the calls to the functions are made
void draw()
{
//the GL_COLOR_BUFFER_BIT is cleared only once to keep the content of the drawing page
if(Cleared == false)
{
gIClear(GL_COLOR_BUFFER_BIT);
Cleared = true;
}
//the drawPanel() function is called everytime the draw function is called
drawPanel();
//checks if the object is selected using the boolean, and calls the appropriate function
if (Line==true)
drawLine();
if (Point==true)
drawPoint();
glFlush();
}
//this function is responsible for the action that happens when we select from the menu panel
void processMenuEvents(int option)
{
``````
if(Cleared2== false)
{
gIClear(GL_COLOR_BUFFER_BIT);
Cleared2= true;
}
switch (option)
{
case LINE:
Line= true;
Point= false;
P1=false;P2=false;P3=false;
shape="Drawing a Line";
break;
case POINT :
Line= false;
Point= true;
P1=false;P2=false;P3=false;
shape="Drawing a Point";
break;
case CLEAR :
glClear(GL_COLOR_BUFFER_BIT);
P1= false,P2=false, P3= false;
break;
}
glutPostRedisplay();
}
//this function is responsible for mouse interaction
void mouse (int btn, int state, int x, int y)
{
//these are listeners for left mouse click events in the drawing area
if (btn == GLUT_LEFT_BUTTON && state == GLUT_DOWN && 600-y >60)
{
if (Line==true)
{```
}
}
}
Ifthese are llateners for buttons in the panel
If [ x >0 &&x x 120 && 600-y>0 && 600-y 30)
processMenu
By using Microsoft Visual Studio 2 0 2 2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!