Render polygon at mouse position

I’m having a bit of trouble getting my head around the coordinate system in opengl. I’m trying to render an object at the mouse position.

in my objects class I have a posX and posY variables
and here is my draw routine incase I’m doing something wrong here:

glPushMatrix();
	glColor3f(1.0,1.0,1.0);
	glTranslatef(posX,posY,0.0f);

	glBegin(GL_POLYGON);

	glVertex3f(0.0,0.0,0.0);
	glVertex3f(0.025,0.0,0.0);
	glVertex3f(0.025,0.1,0.0);
	glVertex3f(0.0,0.1,0.0);
	
	glEnd();
	glPopMatrix(); 

So in my main class I have a passivemotion callback function and I simply do myObject->posY = y; Now I know thats wrong but I’m not sure how I should convert it into screenCoords;

Note that Im rendering the scene with an orthographic projection.

So the problem is you want to render this polygon at the mouse position but it renders at somewhere different?
If it is the case first thing you should check is if your input is right. For example for windows :


POINT cur_pos;
GetCursorPos(&cur_pos);
ScreenToClient(hWnd, &cur_pos));

x = cur_pos.x;
y = frame.h - cur_pos.y;