Again with OpenGL
Moderator: Coders of Rage
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
Still not rotating shape.
- dandymcgee
- ES Beta Backer
- Posts: 4709
- Joined: Tue Apr 29, 2008 3:24 pm
- Current Project: https://github.com/dbechrd/RicoTech
- Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
- Programming Language of Choice: C
- Location: San Francisco
- Contact:
Re: Again with OpenGL
You're obviously doing something wrong. Perhaps try starting with a working example and comparing your code to it?Benjamin100 wrote:Still not rotating shape.
http://nehe.gamedev.net/tutorial/rotation/14001/
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches!
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Again with OpenGL
ok, looking at your code, I see, generally, this:
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.
Code: Select all
[init stuff]
[push]
[draw]
[transform]
[flush to screen]
[pop]
[push]
[draw]
[flush]
[pop]
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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
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.
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.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
Ok, here is where I'm at now....
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.
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();
}
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
When you say rendering, what do you mean?
What functions render?
What functions render?
- Ginto8
- ES Beta Backer
- Posts: 1064
- Joined: Tue Jan 06, 2009 4:12 pm
- Programming Language of Choice: C/C++, Java
Re: Again with OpenGL
The stuff between glBegin/glEnd counts as rendering.Benjamin100 wrote:When you say rendering, what do you mean?
What functions render?
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.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
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.
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.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
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.
Thanks,
-Benjamin
EDIT: Keeps rotating now.