Coordinates - should be easy

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.

Here is the code sample you want (i hope that’s the right code for you)

GLvoid ReSizeScene(GLsizei w, GLsizei h)
{
GLfloat Entf = 100.0f; //Range Var
if(h == 0)
{
h = 1;
}

glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

//Clipping volume (left, right, bottom, top, near, far)
if(w <= h)
{
	glOrtho(-Entf, Entf, -Entf*h/w, Entf*h/w, -Entf, Entf);
}
else
{
	glOrtho(-Entf*w/h, Entf*w/h, -Entf, Entf, -Entf, Entf);
}

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

Here is the code sample you want (i hope that’s the right code for you)

GLvoid ReSizeScene(GLsizei w, GLsizei h)
{
GLfloat Entf = 100.0f; //Range Var
if(h == 0)
{
h = 1;
}

glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();

//Clipping volume (left, right, bottom, top, near, far)
if(w <= h)
{
	glOrtho(-Entf, Entf, -Entf*h/w, Entf*h/w, -Entf, Entf);
}
else
{
	glOrtho(-Entf*w/h, Entf*w/h, -Entf, Entf, -Entf, Entf);
}

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

}

Uupps, soorry

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.

Heres a simple GLUT example: http://personal.lig.bellsouth.net/lig/s/_/s_dolan/Resize.zip

This subject cant be covered in a few paragraphs. There are too many variables.
The OpenGL SuperBible will show you how to do this & alot more. Get a book!

Byte Zero:
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.

Any ideas?

Thanks for your help!!

Hi I’am sorry I am using only Glut, MFC is to stupid, so if you want the Glut code for this mail me;

bytezero@usa.com

c u

I moved your function to the bottom and called it within my plotting function and it worked!!

I don’t know how - but frankly I don’t care.

Thanks very much!!