Page 3 of 3
Re: Again with OpenGL
Posted: Thu Jan 12, 2012 5:37 pm
by Benjamin100
Still not rotating shape.
Re: Again with OpenGL
Posted: Thu Jan 12, 2012 6:25 pm
by dandymcgee
Benjamin100 wrote:Still not rotating shape.
You're obviously doing something wrong. Perhaps try starting with a working example and comparing your code to it?
http://nehe.gamedev.net/tutorial/rotation/14001/
Re: Again with OpenGL
Posted: Thu Jan 12, 2012 6:35 pm
by Ginto8
ok, looking at your code, I see, generally, this:
Code: Select all
[init stuff]
[push]
[draw]
[transform]
[flush to screen]
[pop]
[push]
[draw]
[flush]
[pop]
The first issue is that flushing and buffer-swapping should both happen after ALL of your rendering is done, not halfway through. There might be a few weird situations where you'd want to flush/swap before the end, but this is not one of them.
The second issue is the order in which you have your draw vs your transformation. Look at the general formula I gave you, specifically the parts in the [push]/[pop] groupings; you'll see a difference that completely explains why it isn't rotating.
Re: Again with OpenGL
Posted: Thu Jan 12, 2012 6:41 pm
by Benjamin100
But I've done it before with the transformation BEFORE the drawing. It STILL doesn't rotate.
Now I've flushed AFTER the Push, transform, draw, Pops and it STILL doesn't work.
I started out that way, the order changed because I was trying out different ways.
That just puts me back where I started. 2 shapes, neither moving.
Re: Again with OpenGL
Posted: Thu Jan 12, 2012 6:43 pm
by Benjamin100
Ok, here is where I'm at now....
Code: Select all
void rect_display(void)
{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glRotatef(0.1, 0.0, 0.0, 1.0);
glBegin(GL_POLYGON);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(0.3, 0.8, 0.0);
glVertex3f(0.3, 0.2, 0.0);
glVertex3f(0.8, 0.2, 0.0);
glVertex3f(0.8, 0.8, 0.0);
glEnd();
glPopMatrix();
glPushMatrix();
glBegin(GL_TRIANGLES);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(0.5, 0.9, 0.0);
glVertex3f(0.1, 0.1, 0.0);
glVertex3f(0.9, 0.1, 0.0);
glEnd();
glPopMatrix();
glFlush();
glutSwapBuffers();
glutPostRedisplay();
}
If you can't tell from this, I'll probably just show the main function, and initializing function. But I can't suppose that has to do with it, because I can make one shape appear and move... though maybe not this same way.
Re: Again with OpenGL
Posted: Thu Jan 12, 2012 6:44 pm
by Benjamin100
When you say rendering, what do you mean?
What functions render?
Re: Again with OpenGL
Posted: Fri Jan 13, 2012 9:15 am
by Ginto8
Benjamin100 wrote:When you say rendering, what do you mean?
What functions render?
The stuff between glBegin/glEnd counts as rendering.
But what you're seeing might not indicate that it isn't rotating, but rather that it rotates so little that it doesn't matter. glRotate(r,x,y,z) rotates r DEGREES around the (x,y,z) vector. So if you have it rotating 0.1 degrees, that difference would be barely perceptible, or may be so small that it doesn't translate to even the smallest difference in the pixels. Make it glRotate(30,0,0,1) and see if you still have the issue, because, aside from the tiny rotation amount, it looks like there shouldn't be an issue at all.
Re: Again with OpenGL
Posted: Fri Jan 13, 2012 3:41 pm
by Benjamin100
Yeah, OK. Now it moves over on the side. But it doesn't animate.
Usually if it is outside of the push/pop it will rotate in a loop.
Why doesn't it continue to rotate now?
EDIT: Silly me, I need a variable that changes the degree each time around, don't I?
I think I've done that before, must have just forgotten.
Sorry for all of the trouble.
Thank you for the help.
Re: Again with OpenGL
Posted: Fri Jan 13, 2012 3:53 pm
by Benjamin100
You see, I had it on 0.1 because I expected it to do 0.1 further and further in a loop. So when it looked like it wasn't moving, I figured the rotation wasn't working at all, (because it WOULD keep moving outside of the push/pop, I think because it was rotating that CURRENT matrix 0.1, which kept it moving.) When I put it INSIDE the push/pop, I expected it to also keep moving another 0.1 again and again, not realizing that to do that I might need to keep increasing the degree, unlike outside of the push/pop.
Thanks,
-Benjamin
EDIT: Keeps rotating now.