OpenGL Rotatef

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL Rotatef

Post 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.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: OpenGL Rotatef

Post 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.
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: OpenGL Rotatef

Post 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?
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: OpenGL Rotatef

Post 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).
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: OpenGL Rotatef

Post 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?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: OpenGL Rotatef

Post by short »

Are you using sdl_image?
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: OpenGL Rotatef

Post 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! :)
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: OpenGL Rotatef

Post 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.
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Innerscope
Chaos Rift Junior
Chaos Rift Junior
Posts: 200
Joined: Mon May 04, 2009 5:15 pm
Current Project: Gridbug
Favorite Gaming Platforms: NES, SNES
Programming Language of Choice: Obj-C, C++
Location: Emeryville, CA
Contact:

Re: OpenGL Rotatef

Post 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
Last edited by Innerscope on Sun Aug 02, 2009 2:25 pm, edited 1 time in total.
Current Project: Gridbug
Website (under construction) : http://www.timcool.me
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL Rotatef

Post 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);
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: OpenGL Rotatef

Post 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?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
User avatar
Falco Girgis
Elysian Shadows Team
Elysian Shadows Team
Posts: 10294
Joined: Thu May 20, 2004 2:04 pm
Current Project: Elysian Shadows
Favorite Gaming Platforms: Dreamcast, SNES, NES
Programming Language of Choice: C/++
Location: Studio Vorbis, AL
Contact:

Re: OpenGL Rotatef

Post 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.
User avatar
ibly31
Chaos Rift Junior
Chaos Rift Junior
Posts: 312
Joined: Thu Feb 19, 2009 8:47 pm
Current Project: Like... seven different ones
Favorite Gaming Platforms: Xbox 360, Gamecube
Programming Language of Choice: C++, ObjC
Location: New Jersey.

Re: OpenGL Rotatef

Post 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?
Image
Twitter
Website/Tumblr
My Projects

The best thing about UDP jokes is that I don’t care if you get them or not.
qpHalcy0n
Respected Programmer
Respected Programmer
Posts: 387
Joined: Fri Dec 19, 2008 3:33 pm
Location: Dallas
Contact:

Re: OpenGL Rotatef

Post 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.
Post Reply