PDA

View Full Version : changing the arguments to gluOrtho2D during execution



zihuatanejo
09-14-2004, 10:08 AM
Is this actually possible?

I've created a program that generates the Herter-Heighway Dragon fractal. However, the fractal changes position for each iteration and I need to change the display coordinates of the window dynamically, so to speak, as it changes.

I'm using gluOrtho2D() to set the coordinates initially but calling it again with the updates coordinates doesn't work - in fact the screen goes completely blank.

Any ideas? I've considered using the gluLookAt() function but since its a 2D program it seems somewhat unnecessary.

I'm sure there's a simple solution, I just don't know what it is! ;)

Cheers :)

ZbuffeR
09-14-2004, 10:16 AM
Maybe glOrtho is better, not sure about this.

It should work correctly, double check the doc, maybe put a glLoadIdentity before it ?

If you still have problems, post your gl tviwport and transforma code.

well, sorry, too much wine this evening :p

zihuatanejo
09-14-2004, 03:23 PM
Tried glOrtho, no change - think gluOrtho2D is the same anyway, it just puts in the near and far values as -1 and 1.

Tried glFrustum as well, but no difference. Its a real puzzler :s

I'm prob just missing something simple out.

Not using glViewport (except in the reshape function, which i haven't implemented yet), because i'm using local coordinates rather than image coordinates, so to speak.

http://www.math.umass.edu/~mconnors/fractal/generate/dragon.html

That link shows how the fractal grows through each iteration. Its hard to see it but after the first few iterations the fractal moves steadily in the (x, -y) direction. Just so gives you a clearer idea of what i'm on about!

I can email the code to anyone who's interested and i'll copy some in here later if I'm still stuck.

Basically I have four variables, xMin, xMax, yMin, yMax, that I use with gluOrtho2D() at the start of the program.

For each iteration, I calculate the centre of the dragon, which is simple enough (its the last vertex of the previous iteration) and adjust the values of xMin, xMax, yMin, and yMax i.e.

xMin += centreX;
xMax += centreX;
yMin += centreY;
yMax += centreY;

However if i then call gluOrtho2D again with the updated variables, the screen goes black for some reason. I just assumed u could only call gluOrtho2D once and needed to use another function if u needed to change it during execution.

Maybe i'm just too tired, or too stupid ;)

dorbie
09-14-2004, 05:02 PM
You should read the post more carefully, I'm pretty sure zbuffer got it right when he mentioned calling glLoadIdentity. The ortho routines multiply their projection with whatever is already on the projection stack.

zihuatanejo
09-15-2004, 02:55 AM
Thankyou both for your help.

I was being a dumbass in multiple areas ;) Yes, needed to use glLoadIdentity. Just put:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(xMin, xMax, yMin, yMax);

glMatrixMode(GL_MODELVIEW);
...
...

at the start of my display function..

Of course, ironically when I ran the program the fractal wandered off to the left instead of staying in the middle of the damn window, but you can't have everything all at once can you ;)

Thanks again :)