Page 2 of 2

Re: OpenGL Rotatef

Posted: Sat Aug 01, 2009 10:36 pm
by qpHalcy0n
I'm glad that fixed it. You'll pick up the terminology as you go.

The user pointer doesn't operate terribly much different from the immediate mode processing, instead it attempts to make better use of vertex cache coherency and reduce DMA overhead to the card by batching multiple vertices at a time. They're still very very slow. Matrices are not "pushed onto vertices" or anything like that. When you make a draw call, whether it's via an immediate mode begin/end pair, or via a hardware buffered draw arrays call, all the vertices are simply passed through the top-most (current) modelview and projection matrices at all times...no matter what..and all this is part of the vertex processing pipeline.

So glVertexPointer in his case is just another method of sending the information through the pipes. They get transformed just the same.

Re: OpenGL Rotatef

Posted: Sat Aug 01, 2009 11:36 pm
by ibly31
I dont know enough about OpenGL to know what most of the functions do... Im just following tutorials at thus point. Soon, hopefully, Ill understand.

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 12:16 am
by short
I have a question about glRotatef.

I have been just trying trying to get a 2d box to spin around. I finally got this piece of code to work.

Code: Select all

void drawBox()
{
	glPushMatrix();
	glLoadIdentity(); // clears the matrix

	glRotatef(45.0f,0f,0f,1.0f);

	glBegin(GL_QUADS);
		glColor3f(1.0, 0.0, 0.0);
			glVertex3f(200, 200,0);

		glColor3f(0.0, 1.0, 0.0);
			glVertex3f(300, 200,0);

		glColor3f(0.0, 0.0, 1.0);
			glVertex3f(300, 300,0);

		glColor3f(1.0, 0.0, 1.0);
			glVertex3f(200, 300,0);
	glEnd();
	glPopMatrix();
	
}
Since I have a 1.0 in my z coordinate, I am imagining my rectangle on the end of a pole, and I am simply turning the pole.

I have the Redbook here with me, and it's not helping me much either.

Anyone care to elaborate on exactly how this is working? I'm still learning opengl, I'm super new to it still.

Thanks

edit: What does the 1.0f in the z parameter do?

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 10:07 am
by Falco Girgis
Yeah, that's exactly how you should imagine it. I'm guessing your rectangle is in 2D?

The two perpendicular edges of your rectangle are your x and y axes. Then the pole is perpendicular to the two, being the z coordinate. Since you're rotating about the z coordinate, it is analogous to the pole rotating through it.

The 1.0f in the z parameter is how much of the rotation transform you want to affect each axis. 0.0-1.0f. 0.0 is nothing (because you aren't rotating through x or y), and z is 1.0 (because the entire rotation is through the z).

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 10:45 am
by ibly31
Another question: I have pretty much everything working so far that I need, but when I tried to import a .png file with alpha/transparency, it just showed up as a my image with a black background... how do I fix this?

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 10:54 am
by short
Are you using sdl_image?

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 11:57 am
by ibly31
I'm doing iPhone development, with OpenGL ES. No SDL involved. Though I wish it was, SDL was my best friend back with my old Windows computer! :)

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 12:02 pm
by ibly31
I'm not sure if GyroVorbis fixed your mistake or not, but with what I have done so far in OpenGL ES, I always use a -1.0 for my Z value in all my vertices, because going negative makes it go away from the camera in a forward motion. When you set up your orthogonal/frustum view you might have set the near parameter to 0.001, which is greater than 0, thus making the rectangle not display. Just guessing, I could(most likely) be wrong.

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 12:54 pm
by Innerscope
ibly31 wrote:Another question: I have pretty much everything working so far that I need, but when I tried to import a .png file with alpha/transparency, it just showed up as a my image with a black background... how do I fix this?
[Edit] Oops, thought you said blank. Read what qpHalcy0n wrote

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 1:14 pm
by qpHalcy0n
If the image is showing but not blending, then most likely you have not enabled alpha blending. If you want to smoothly blend with the rest of the scene you'll need to turn z-testing off (if you're doing depth tests) and render back to front blending the source alpha to the inverted source's alpha value.
The following enables alpha blending:

Code: Select all

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

DrawStuff();

glDisable(GL_BLEND);

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 7:48 pm
by ibly31
Ah, yes. Thanks. I have that in my setupView: function, and I only call it once, it seems to work. Is it better practice to glEnable and glDisable EVERY time the scene is drawn?

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 8:53 pm
by Falco Girgis
ibly31 wrote:Ah, yes. Thanks. I have that in my setupView: function, and I only call it once, it seems to work. Is it better practice to glEnable and glDisable EVERY time the scene is drawn?
The chances are that eventually you will have things blended and not blended in the scene, in which case you don't have a choice. So there's nothing wrong with doing it.

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 9:06 pm
by ibly31
Oh, okay. Can you give me an example of when you'd need to do blended and non-blended work in a game/ simulation?

Re: OpenGL Rotatef

Posted: Sun Aug 02, 2009 10:38 pm
by qpHalcy0n
Well, any time you have alpha blended faces you'll need to do a proper sort. Generally you'd do a pass w/ the opaque geometry front to back w/ blending disabled. By rendering front to back you can make use of early z-rejection and on some video cards double speed or quadruple speed depth writes (normally when color writes are disabled). Then you would disable depth testing, enable alpha blending, sort the transparent faces back to front, and then render them. Always reset the original render state when you're done. Just be cautious to not redundantly (normally redundant calls are buffered out) and excessively enable blending. Alpha blending is one of the more expensive post pixel processing routines.