Again with OpenGL
Moderator: Coders of Rage
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
which object is the "glRotatef" function rotating?
How do I specify one object as opposed to another?
Do I just use the "push" and "pop" to change between objects I'm controlling?
EDIT: Evidently not.
How do I specify one object as opposed to another?
Do I just use the "push" and "pop" to change between objects I'm controlling?
EDIT: Evidently not.
- 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
glRotate multiplies the currently selected matrix by a rotation matrix. When called as glRotatef(a,b,c,d), you can conceptually think of this as rotating the current origin a degrees around the vector (b,c,d).
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
Thanks!
So, the push and pop helps matrix selection?
So, the push and pop helps matrix selection?
- 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
push and pop operate on the matrix stack, which can be considered a "backlog" of previous matrices. For more information on how stacks like this work: Wikipedia is your friend.
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
Code: Select all
glPushMatrix();
glRotatef(0.1, 0.0, 1.0, 0.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();
- 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
Yes, but since the vector (0.0,1.0,0.0) points up, not out toward the viewer, it would rotate around a "pole" going from the top of the screen top to the bottom, which I'm guessing isn't what you're looking to do. Also, using GL_POLYGON instead of GL_QUAD is isn't necessarily a good idea, because OpenGL is faster with quads (and even faster with triangles) than with polygons (when it knows they're quads/triangles, and doesn't have to treat them like polygons).
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
Well when I put the rotate within the push and pop it won't rotate.
EDIT: This is using the "glutMainLoop();".
EDIT: This is using the "glutMainLoop();".
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
I think I understand the different ways it rotates, I just want to rotate one shape while another stays still
- 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
Here's the general formula for working with transformations and the matrix stack:
Most parts of that can be removed, but the indented scenes require the [push][pop] surrounding them to prevent them from affecting other scenes.
Code: Select all
[general transformations]
[render scene based on general transforms]
[push]
[scene 1 transformations]
[scene 1 rendering]
[pop]
[push]
[scene 2 transformations]
[scene 2 rendering]
[pop]
[render second scene based on general transforms]
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
Thank you.
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
Well, it seems the rotation doesn't do anything when inside of the push and pop.
- 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
Why don't you post the code? Since you say it "doesn't do anything", I'm assuming that you popped the matrix again before actually using the rotation for rendering, but I can't be sure without code.
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
Wait a minute, a couple things...
So, first I think I get that the RENDERING, not JUST the transformations, need to be within the "push()" and "pop()".
Now, is this not supposed to be in the display function? Is this a separate function?
I mean, the push and pop regions are not the same ones as the ones with the vertex data?
So, first I think I get that the RENDERING, not JUST the transformations, need to be within the "push()" and "pop()".
Now, is this not supposed to be in the display function? Is this a separate function?
I mean, the push and pop regions are not the same ones as the ones with the vertex data?
-
- ES Beta Backer
- Posts: 250
- Joined: Tue Jul 19, 2011 9:37 pm
Re: Again with OpenGL
I've done some editing on it, but now it just makes the rectangle(EDIT: Triangle) flash.
So there is the display function. It originally just displayed the rectangle, hence the name.
Please tell me EVERYTHING that is wrong with it. And if there should even be a display function.
Code: Select all
void rect_display(void)
{
glClearColor(0, 0, 0, 0);
glClear(GL_COLOR_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
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();
glRotatef(0.1, 0.0, 0.0, 1.0);
glFlush();
glutSwapBuffers();
glutPostRedisplay();
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();
glFlush();
glPopMatrix();
}
Please tell me EVERYTHING that is wrong with it. And if there should even be a display function.
-
- Respected Programmer
- Posts: 387
- Joined: Fri Dec 19, 2008 3:33 pm
- Location: Dallas
- Contact:
Re: Again with OpenGL
Rotate before submitting draw calls. This will ensure that the specified transform is applied to all subsequent render calls. This is the purpose for push/pop, so that you can SAVE the current transform state, and RESTORE it when you're done rendering that "thing" such that not ALL subsequent objects rendered have that same transform applied to them. This would be an undesired side effect.
So Push (Save the current transform)
apply new transform
render
Pop (Restore old transform)
Remember this paradigm. Change render state? Clean it up when you're done.
So Push (Save the current transform)
apply new transform
render
Pop (Restore old transform)
Remember this paradigm. Change render state? Clean it up when you're done.