Button Testing with a mouse

I’m a WIN API OpenGL user. I learned my OpenGL from nehe.gamedev.net. Okay, I’ve got a rather strange problem. I don’t know why my program is doing this. I’m making a game and I’m making an opening screen with a bitmap, and to goto the high score bitmap I’m testing for a mouse click with an area of pixels that contains the pic of the button the quad that I drew. Unfortunately this is not working. If anyone has any idea why this is so messed up, please help me.

Here’s the coding from my DrawGLScene:

glLoadIdentity(); // Reset The View

// Get The Current Mouse Position ( Add )
if ( (mpos.x>100) && (mpos.x<200) && (mpos.x>100) && (mpos.y<360) && (mpos.y>260) )
high_score = TRUE;
high_score = FALSE;

if ( (mpos.x<=337) && (mpos.x>=258) && (mpos.y<=449) && (mpos.y>=405) )

int page = 0;

// Checking for High Scores Button on Title
// Page
if (lmp_hit && (page!=1) && hsp_hit)
page = 1;
// Checking for OK Button on High Scores Page
else if (lmp_hit && (page!=0) && OKp_hit)
page = 0;

glBindTexture(GL_TEXTURE_2D, texture[page]);
// Opening.bmp
glTranslatef(0.0f, 0.0f, -35.0f);

// Draw A Quad

Here’s the coding for my button testing:

if (high_score && !hsp)
hsp = TRUE;
hsp_hit = !hsp_hit;

if (!high_score)
hsp = FALSE;

if (OK && !OKp)
OKp_hit = !OKp_hit;

if (!OK)

Any help would be greatly appreciated. I hope you can understand all that.


When you use GetCursorPos, this is relative to the upper-left hand corner of the screen, not the current window. So you will need to get a client-space device context for you window and use that to convert these screen coordinates into window coordinates. There is, if I recall, a device context function to convert these coordinates into window coordinates.

does anyone know what this conversion function is and how I could use it???

[This message has been edited by jeremyp (edited 04-18-2001).]

There are two functions that might be of interest for you:

ScreenToClient and ClientToScreen

which convert Screen and Client(Window)-Coordinates.

Hope that helps