well I am working on a simpler game called tic tac toe, my question is how do I get the mouse click to draw an X on the board. when I click the mouse nothing happens.
#include <freeglut.h>
#include <iostream>
using namespace std;
void drawBoard()
{
glPushMatrix();
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_LINE_STRIP);
glVertex3f(-18.75f, 6.25f, 0.0f);
glVertex3f(18.75f, 6.25f, 0.0f);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f(-18.75f, -6.25f, 0.0f);
glVertex3f(18.75f, -6.25f, 0.0f);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f(-6.25f, 18.75f, 0.0f);
glVertex3f(-6.25f, -18.75f, 0.0f);
glEnd();
glBegin(GL_LINE_STRIP);
glVertex3f(6.25f, 18.75f, 0.0f);
glVertex3f(6.25f, -18.75f, 0.0f);
glEnd();
glPopMatrix();
}
void drawText()
{
glColor3f(0.0f, 1.0f, 1.0f);
glRasterPos2f(10.0f, 10.0f);
glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, 'X');
}
void renderScene()
{
glClear(GL_COLOR_BUFFER_BIT);
drawBoard();
glutSwapBuffers();
}
void ChangeSize(GLsizei w, GLsizei h)
{
GLfloat aspectRatio;
if (h == 0)
h = 1;
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
aspectRatio = (GLfloat)w / (GLfloat)h;
if (w <= h)
glOrtho(-100.0, 100.0, -100.0 / aspectRatio, 100.0 / aspectRatio, 1.0, -1.0);
else
glOrtho(-100.0*aspectRatio, 100.0*aspectRatio, -100.0, 100.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouseClicks(int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
drawText();
}
}
int main(int argc, char**argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE);
glutInitWindowPosition(600, 400);
glutInitWindowSize(800, 600);
glutCreateWindow("Tic Tac Toe");
glutDisplayFunc(renderScene);
glutReshapeFunc(ChangeSize);
glutMouseFunc(mouseClicks);
glutMainLoop();
}