Using VC++ 6.0 I am plotting an array of points in a window. The array refers to an image that is let’s say 640480 pixels. Currently my image stretches when the window is resized - how do I force it to stay at 640480 whatever the window size?
I am quite new to this so please explain in very plain English, with sample code if possible.
Use an orthogonal projection matrix. Call glOrtho( leftx, rightx, topy, bottomy, front back ). Well the parameters may be a bit different but the idea is still the same.
Let leftx and topy be 0.0f, rightx and bottom y be the extensions of the windows’s client area. take small values for front and big values for back if you want.
Then, the pixels should be accesible just with their coordinates, and since you call glOrtho everytime the window’s size change (since then it’s client area also changes) with the updated extensions. Process some message like WM_SIZED or something and do the update there.
Anyway… if you want to display an image you might be better off with a textured quad, where the texture contains the image.
You need to handle the WM_SIZE message sent to your window, when you drag a corner or maximize the window. This message contains the new size of your window in pixels. You use these values to remap your projection matrix. How you handle this message depends on what your are using to code OpenGL: GLUT, Win32 API, or MFC.
Where does that code go?
I tried to put it in my:
void CChildView::OnGLDraw(CDC *pDC)
function but I don’t think that is right.
I’m using a simple MFC wizard program and building it up to do some simple graphics as part of an image transfer experiment. The problem is that a lot of the code is pregenerated and quite complicated.
The code (GL_POINTS) I use to plot the image is in CChildview and the code that calls to create the window is CMainFrm.