Original Post
Hi, i´m extremely noob in OpenGL API and i got a big problem in coordinates.Well, i wanna make a program that highlight a square if the user clicks on it and set the default color if he clicks out.The problem in my code is : if the user click on the top of square it doesn´t highlight!!! Here is the code, please tell what´s wrong. [Edited by - Himura-San on November 15, 2004 3:24:26 PM]
#include <GL\glut.h>
void Draw()
{
//Aplica as alterações ao modelo
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_POLYGON);
{
//glColor3f(1.0f,1.0f,1.0f);
glVertex2i(100,150);
glVertex2i(100,100);
glVertex2i(150,100);
glVertex2i(150,150);
}
glEnd();
glFlush();
}
void Mouse(int button , int state, int x , int y)
{
if (button == GLUT_LEFT_BUTTON)
if (state == GLUT_DOWN)
if ( (x >= 100) && (x <= 150) && (y >= 100) && (y <= 150) ) glColor3f(1.0f,0.0f,0.0f);
else glColor3f(1.0f,1.0f,1.0f);
//if (state == GLUT_UP) glColor3f(1.0f,1.0f,1.0f);
glutPostRedisplay();
}
void Reshape(GLint w, GLint h)
{
glViewport(0,0,(GLsizei)w,(GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,(GLdouble)w,0.0,(GLdouble)h);
}
int main()
{
//Cria a Janela
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(320,240);
glutInitWindowPosition(10,10);
glutCreateWindow("My Program :p");
//Seta a cor de fundo como preta
glClearColor(0.0,0.0,0.0,0.0);
glutDisplayFunc(Draw);
glutReshapeFunc(Reshape);
glutMouseFunc(Mouse);
glutMainLoop();
}