PDA

View Full Version : looking for glScalef examples



cg-hci_novice
09-03-2003, 09:10 AM
Multiple sources of diff types would be very appreciated. Am applying to 2D case.

Thanks a lot.

mikael_aronsson
09-03-2003, 11:05 AM
glScalef( 1, 2, 1); // for example...

There is not much more you can do with it...

Mikael

cg-hci_novice
09-03-2003, 12:09 PM
Thanks for the reply.

I guess I am looking more for some Web sites that would show the before and after. Do you know of any? Right now, I am getting a black screen when I try to add a line like you mentioned (except I have 0 in last arg). I comment out and my drawing returns. I am trying to expand it.

Thanks.

Deiussum
09-03-2003, 12:34 PM
You don't want 0 for the last parameter. Use 1 for no scaling in that dimension.

DOH!
09-03-2003, 01:55 PM
glScale just multiplies the following X,Y and Z coordinates by the amount specified in the glScale command.

Thats one of the simplest commands in OpenGL, why dont you just RTFM first?

cg-hci_novice
09-03-2003, 04:08 PM
I'll continue to post on here since I still can't expand even with the last arg as 1 http://www.opengl.org/discussion_boards/ubb/confused.gif and hope that DOH! goes away http://www.opengl.org/discussion_boards/ubb/wink.gif

Given that the following is within a display routine, what am I doing incorrectly?

glClear(GL_COLOR_BUFFER_BIT);

glBegin(GL_LINE_LOOP);
glColor3f(1.0, 1.0, 1.0);
glScalef(13.0, 13.0, 1.0);
for (i=0; i<count; i++)
{
glVertex2f(c_array[i].lat, c_array[i].lon);
}
glEnd();

glutSwapBuffers();

09-03-2003, 04:18 PM
Try putting this after glClearColor:

glPushMatrix(GL_MODELVIEW);
glLoadIdentity();

I hope this helps.

cg-hci_novice
09-03-2003, 04:31 PM
Unfortunately, that's not really an option. I am already provided with a main function containing:

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(LEFT_EDGE, RIGHT_EDGE,
BOTTOM_EDGE, TOP_EDGE);

prior to the call to the display routine and need to maintain this "format"

Thanks, though.

al_bob
09-03-2003, 04:53 PM
Read what DOH! posted. It doesn't get any simpler than that.

cg-hci_novice
09-03-2003, 04:57 PM
Well, maybe I don't understand what DOH! is saying - I just took at as an insult.

al_bob
09-03-2003, 06:40 PM
Perhaps you can start by saying what you don't understand with DOH!'s post?

Or parhaps you can start by saying what you don't understand from TFM (http://www.3dlabs.com/support/developer/GLmanpages/glscale.htm) ?

cg-hci_novice
09-03-2003, 07:01 PM
According to the site you've linked, I really should have got an GL_INVALID_OPERATION error for the code I posted above but I didn't. I wonder why.

Anyways, is it mandatory then for me to use the push and pop around the scaling to see the effect?

I need to maintain the code from the main function that I posted above in resolving this problem.

Thanks.

al_bob
09-03-2003, 07:14 PM
According to the site you've linked, I really should have got an GL_INVALID_OPERATION error for the code I posted above but I didn't. I wonder why.
Assuming you got your error reading code correct, it's most likely a driver bug.


Anyways, is it mandatory then for me to use the push and pop around the scaling to see the effect?
You could do that. You could also rescale by the inverse:



glScalef(13, 13, 1);
glBegin(...);
/* Render code goes here */
glEnd();
glScalef(1.0/13, 1.0/13, 1);


Either way will be fine. Using push/pop, or reloading hte matrix would ensure that you don't run into precision problems by continuously rescaling.

cg-hci_novice
09-03-2003, 07:23 PM
Thanks for the feedback.

Well, this has given me some options to think over a little more.

Thanks very much.

Deiussum
09-04-2003, 04:30 AM
The code in your outer loop is setting the projection matrix, you are scaling the modelview matrix, and you don't clear it out, so every frame, you are going to be scaling again. (OpenGL is a state machine, the state of the modelview matrix won't change unless you change it.)

So, frame 1, you scale by 13,13. Frame 2, you will now be scaling 13*13, 13*13. Frame 3, 13*13*13, 13*13*13, etc.. as you can see, you will quickly be scaling this up.

Edit: I guess your code never set the matrix mode to GL_MODELVIEW like it should have so you are scaling the GL_PROJECTION matrix, which in itself is usually a no no.

[This message has been edited by Deiussum (edited 09-04-2003).]

cg-hci_novice
09-04-2003, 11:21 AM
I just talked to someone about it and found out I am missing glTranslate.

Thanks for all the info.

mikael_aronsson
09-04-2003, 09:38 PM
Hi !

You cannot put a glScale between glbegin() glEnd(), you can only use glColor...glVertex... and a few other functions between glbegin/glEnd.

Mikael

cg-hci_novice
09-05-2003, 07:56 AM
Yeah, exactly why I should have the got the error (mentioned above).

Thanks for the info though.

I have no more questions.

Thanks everybody.

Deiussum
09-05-2003, 09:11 AM
The code you gave didn't show anywhere where you were checking for errors. To get errors, you need to actually check for them using glGetError(). The compiler won't help you with this, and no exceptions will be thrown.