Jump to content
  • Advertisement
Sign in to follow this  
fooman_69

Which way is faster?

This topic is 4887 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hiya, Which is faster? I think the 2nd one would be, but my FPS doesn't show much difference.
//Draw players
	glLoadIdentity();
	glBegin(GL_QUADS);
		//player 1
		glTexCoord2f(ent1->GetImage().left, ent1->GetImage().bottom);	glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE));							// Bottom Left Of The Texture and Quad
		glTexCoord2f(ent1->GetImage().right, ent1->GetImage().bottom);	glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE));				// Bottom Right Of The Texture and Quad
		glTexCoord2f(ent1->GetImage().right, ent1->GetImage().top);		glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE));	// Top Right Of The Texture and Quad
		glTexCoord2f(ent1->GetImage().left, ent1->GetImage().top);		glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE));				// Top left of the texture and quad

		//player 2
		glTexCoord2f(ent2->GetImage().left, ent2->GetImage().bottom);	glVertex2f((float)(p2_x * TILE_SIZE), (float)(p2_y * TILE_SIZE));							// Bottom Left Of The Texture and Quad
		glTexCoord2f(ent2->GetImage().right, ent2->GetImage().bottom);	glVertex2f((float)(p2_x * TILE_SIZE + TILE_SIZE), (float)(p2_y * TILE_SIZE));				// Bottom Right Of The Texture and Quad
		glTexCoord2f(ent2->GetImage().right, ent2->GetImage().top);		glVertex2f((float)(p2_x * TILE_SIZE + TILE_SIZE), (float)(p2_y * TILE_SIZE - TILE_SIZE));	// Top Right Of The Texture and Quad
		glTexCoord2f(ent2->GetImage().left, ent2->GetImage().top);		glVertex2f((float)(p2_x * TILE_SIZE), (float)(p2_y * TILE_SIZE - TILE_SIZE));				// Top left of the texture and quad
	glEnd();
OR
	//Draw players
	Sprite ent1Spr = ent1->GetImage();
	Sprite ent2Spr = ent2->GetImage();

	glLoadIdentity();
	glBegin(GL_QUADS);
		//player 1
		glTexCoord2f(ent1Spr.left, ent1Spr.bottom);		glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE));							// Bottom Left Of The Texture and Quad
		glTexCoord2f(ent1Spr.right, ent1Spr.bottom);	glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE));				// Bottom Right Of The Texture and Quad
		glTexCoord2f(ent1Spr.right, ent1Spr.top);		glVertex2f((float)(p1_x * TILE_SIZE + TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE));	// Top Right Of The Texture and Quad
		glTexCoord2f(ent1Spr.left, ent1Spr.top);		glVertex2f((float)(p1_x * TILE_SIZE), (float)(p1_y * TILE_SIZE - TILE_SIZE));				// Top left of the texture and quad

		//player 2
		glTexCoord2f(ent2Spr.left, ent2Spr.bottom);		glVertex2f((float)(p2_x * TILE_SIZE), (float)(p2_y * TILE_SIZE));							// Bottom Left Of The Texture and Quad
		glTexCoord2f(ent2Spr.right, ent2Spr.bottom);	glVertex2f((float)(p2_x * TILE_SIZE + TILE_SIZE), (float)(p2_y * TILE_SIZE));				// Bottom Right Of The Texture and Quad
		glTexCoord2f(ent2Spr.right, ent2Spr.top);		glVertex2f((float)(p2_x * TILE_SIZE + TILE_SIZE), (float)(p2_y * TILE_SIZE - TILE_SIZE));	// Top Right Of The Texture and Quad
		glTexCoord2f(ent2Spr.left, ent2Spr.top);		glVertex2f((float)(p2_x * TILE_SIZE), (float)(p2_y * TILE_SIZE - TILE_SIZE));				// Top left of the texture and quad
	glEnd();

Share this post


Link to post
Share on other sites
Advertisement
Maybe you dont see a difference because your compiler already made that optimization.

Share this post


Link to post
Share on other sites
And even if the compiler didn't already make it, that is such a minor optimization, it won't really affect performance at all.

Share this post


Link to post
Share on other sites
Not to mention that optimization is completely useless in the face of the fact that you're using glBegin/End/Vertex/etc.

Share this post


Link to post
Share on other sites
It's pointless to optimize Immediate OpenGL. Step into Vertex Arrays. (Do a search on Vertex Arrays on that page and read up on it).

Actually, I take that back, it's not pointless to optimize any OpenGL, but optimizing OpenGL is more about sorting data to minimize state changes rather than finding superfast commands.

Whenever you glEnable, glDisable, glBind, glBegin and glEnd, you take a performance hit. Getting the OpenGL state machine in that sweet spot where you put the most out on the screen while call those commands the least is your optimizing dream.

Share this post


Link to post
Share on other sites
Correct me if I am wrong, but all you did is create temporary variables to replace all those references you were using?

That seems like less of a performance issue and more of a readability issue.

Share this post


Link to post
Share on other sites
Thnaks for the replies.
I only asked because it was beat into my throughout college that optimization is key. I figured 10 calls to a class method was more costly than creating two temp variables once.

I will do my best to optimize the gl calls however.
If I am drawing quads throughout the Render method, I should only ever need one glBegin/glEnd call right?

Share this post


Link to post
Share on other sites
It was beat into you that optimization is the key?

I recommend a long period of recuperation, possibly involving self flagelation, to beat it back out again...

"Premature optimization is the root of all evil."

"More computing sins are committed in the name of efficiency (without necessarily achieving it) than for any other single reason - including blind stupidity."

"There are three rules of optimization:
1) Don't optimize.
2) Don't optimize yet.
3) Don't optimize unless a profiler specifically tells you to do so."

"80% of your code is run 20% of the time" (and optimizing that 80% is therefore pointless).

And many more quotes... and threads... both in gamedev and elsewhere... I was thinking all this even as I read your subject...



Share this post


Link to post
Share on other sites
Perfectly understood, and I wish you were there in class as they taught us to code in this fashion. We could have used another person questioning their optimization lessons.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:

"There are three rules of optimization:
1) Don't optimize.
2) Don't optimize yet.
3) Don't optimize unless a profiler specifically tells you to do so."


The two rules of optimization:
1) Don't optimize
2) ( * For Experts Only * ) Don't optimize yet

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!