Problems with transformation

I am having trouble displaying data, and must be misunderstanding something about transforms. I’ve had no problems setting up 3d views, but now that I’m trying to use glOrtho for a simple 2d projection I’m encountering surprising difficulty.

I want to graph values between xmin,xmax,ymin,ymax
If I use glOrtho(0,1,0,1)
and plot values within those ranges, it works.

If I want to translate to arbitrary scale, I try:
glTranslatef(-xMin,-yMin,-1);
glScaled(1/deltaX, 1/deltaY, 1);

and get nothing. Thinking I had slipped a gasket, I tried reversing the two even though I was pretty sure it was right, but that’s wrong too. I also tried eliminating the translate and scale, and changing the observer to:
gluOrtho2D(xMin, xMax, yMin, yMax);

So first, any help on this specific problem would be greatly appreciated. Second, in order to debug problems in the future, I’d like a routine if anyone has it handy that takes a point x,y,z and performs the translation done by the current opengl transform. Is there any way to extract the current state of the matrix, multiply on my x,y,z value, so I can print the results?

thanks,
Dov

double xMin = -74;
double yMin = 38;
double xMax = -70;
double yMax = 42;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, 1, 0, 1);
//gluOrtho2D(xMin, xMax, yMin, yMax);
glMatrixMode(GL_MODELVIEW);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
glLoadIdentity();
glPushMatrix();
glTranslated(0.93,0.05,0);
glScaled(0.05, 0.9, 1);
scale->generateLegend(white, medFont, 19.0, 7, 24.0);
glPopMatrix();

#if 0
glColor3ubv(white);
glBegin(GL_QUADS);
glVertex2f(0, 0);
glVertex2f(1, 0);
glVertex2f(1, 1);
glVertex2f(0, 1);
glEnd();
#endif
cout << xMin << “,” << yMin << " " <<
xMax << “,” << yMax << "
";
double deltaX = xMax - xMin;
double deltaY = yMax - yMin;
double centerX = (xMax + xMin)/2;
double centerY = (yMax + yMin)/2;
glTranslatef(-xMin,-yMin,-1);
//glTranslatef(-centerX,-centerY,-1);
glScaled(1/deltaX, 1/deltaY, 1);
glColor3ubv(green);
glBegin(GL_QUADS);
glVertex2f(xMin, yMin);
glVertex2f(xMax, yMin);
glVertex2f(xMax, yMax);
glVertex2f(xMin, yMax);
glEnd();
}
};

Regarding your last question

You may find glGet with arg GL_MODELVIEW_MATRIX and GL_MODELVIEW_STACK_DEPTH (and possibly other args to get the projection matrix, etc. ) useful.

I find it easier to track down problems on the application side of things (ie, the code using opengl, hence pushing all these matrices into the stack) rather than the opengl side.

mad

Thanks!

In the interim, I did get the glGetFloatv call, and can perform operations on data.

Now for the reverse question, I do not see any call to allow me to play with the values and then do a glSetFloatv. Is there any way to load a matrix from my values?

I do not see any call to allow me to play with the values and then do a glSetFloatv.

Try glLoadMatrixd or glLoadMatrixf.