I wrote a pretty big graphics program a while back that uses CDC for drawing.

I wanted to do some 3D stuff among dozens of other things so, i installed OPENGL in replace of my CDCs

I have more everything ironed out and its working great for the most part.

My mouse points and any other point (example - ::OnMouseMove(nFlags, point)) are not 100% matching up with what OPENGL draws.

For example, if you want to draw a line the further you go out from point 0,0 the bigger the difference in the mouse point and where it draws when you click.

So if you draw a long from 0,0 to say 200,200 then it seems to draw properly. However, the more i zoom out the more the difference is visible.

Im assuming its in my projection… i really don’t know. Im not sure what code to give you.

Note, my ASPECT is 1 because i need to be able to change the size of the window and i don’t want the image to lose that same aspect.


	// Make the rendering context current

	// Reset The Current Viewport And Perspective Transformation
	glViewport(0, 0, cx, cy);

	m_height= cy;
	m_width = cx;

	// Calculate The Aspect Ratio Of The Window

Are you drawing a 2D or 3D line? Is your world coordinate system for the line object the same as the window coordinate system?

Im doing 3D which is why i choose OpenGl but, my problem is with the 2D world. Im not concerned with 3D because i use 3D only to display the image and at that point, the matching coordinates do not matter. The lines that are having problems are the 2D lines. The further from the 0,0 point the further off they are. I think its because one is using metric coordinates and the other another in another coordinate. Im really not sure if my coordinates are the same as the window coordinates which is probably where the problem lies and im not sure what to do from there.

You have made at least two mistakes:

  1. Aspect depends on the window size and should not be 1.
  2. Use Ortho projection to achieve what you need, not Perspective.

Sorry. I provided you the wrong code. All that code above i went ahead removed from the program because i wasn’t calling it anymore.

I set ASPECT to 1 because i did not want the window size to be a factor in drawing but, that’s irrelevant now.

This is what i am calling



// Reset the model matrix

// This Will Clear The Background Color To Screen
	GetRValue(pDoc->m_cScreenColor) / 255.0f, 
	GetGValue(pDoc->m_cScreenColor) / 255.0f, 
	GetBValue(pDoc->m_cScreenColor) / 255.0f,

// Clear the screen and the depth buffer

glOrtho(m_WorkingRect.left, m_WorkingRect.right, m_WorkingRect.bottom,,-10, 4000);

// Translate to a suitable position
glScalef(1.0f * m_fZoomScale,1.0f * m_fZoomScale,1.0f * m_fZoomScale);


glTranslatef(m_pWindowOrg.x,m_pWindowOrg.y,0);//Check Z

I think the problem is either with WORKINGRECT or the zoom because when i zoom in and out, the problem gets progressively worse but at 100% works perfectly fine. I think its just a conversion issue one way or another.


1 - i didnt realize that glOthro does the scaling for me. I originally had the glscale there because i was using projection (i think) like the old code i posted.

2 - What i really think solved the problem was just either a loose glPOPmatrix or glPUSHmatrix. I think adding or removing one of those ended up fixing the problem…