I'm making a 2D drawing canvas in OpenGL that allows you to draw shapes on the drawing canvas by simply selecting which shape you want to draw.
I have created the entire interface for the 2D drawing canvas and also added in a mouse function that reads a screen size of 1000x800
that works perfectly fine also, however with some squares that I have drawn out, I want to be able to change the colour of them depending on which is click (Highlighting them basically).
Here's my drawSquare
function that draws the 4 points to make a square:
void drawSquare(GLfloat length, GLfloat x, GLfloat y, GLfloat outline)
{
// x1,y1 is the top left-hand corner coordinate
// and so on...
GLfloat x1, y1, x2, y2, x3, y3, x4, y4;
x1 = x - length / 2;
y1 = y + length / 2;
x2 = x + length / 2;
y2 = y + length / 2;
x3 = x + length / 2;
y3 = y - length / 2;
x4 = x - length / 2;
y4 = y - length / 2;
// ACTUAL SQUARE OBJECT
glColor3f(0.0, 1.0, 1.0); // Colour: Cyan
glBegin(GL_POLYGON);
glVertex2f(x1, y1); // vertex for BLUE SQUARES
glVertex2f(x2, y2);
glVertex2f(x3, y3);
glVertex2f(x4, y4);
glEnd();
if (outline == true)
{
// SQUARE OUTLINE
glColor3f(0.0, 0.0, 0.0); // Colour: Black
glBegin(GL_LINE_LOOP);
glLineWidth(2);
glVertex2f(x1, y1); // vertex for OUTLINE
glVertex2f(x2, y2);
glVertex2f(x3, y3);
glVertex2f(x4, y4);
glEnd();
}
glFlush();
}
And to draw it, I simply call the function in my display()
function using drawSquare(100, 50, 350,true);
.
But if I want to be able to highlight each square when clicked, how would I do this?