SDL 2D OpenGL setup

Sage
Posts: 1,403
Joined: 2005.07
Post: #1
Whats the best most efficient setup for doing 2D game graphics with OpenGL,
Im drawing lots of sprites with transparency by drawing quads with png textures with alpha, compiled in glLists().

Any optimisation tips would be greatly appreaciated

My current pixel formatt is
Code:
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 0);

and my OpenGL setup is

Code:
glClearDepth(1.0);

glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glAlphaFunc(GL_GREATER, 0.1f);
glEnable(GL_ALPHA_TEST);

glEnable(GL_TEXTURE_2D);

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #2
Is creating your pixel format slow? I doubt it.
No point optimizing anything unless your app is running to slow. Then you should profile, and optimize only the problematic areas.
As far as getting tips on optimizations go, you'd be best to profile it in shark, and tell us what the slowest thing is, maybe with the line/s that are the slowest. But again, only if it's actually slow in the first place.
EDIT:
On reflection I realized I may have misinterpreted the question. There are certain ways you can go about doing things that may slow things down generally. For instance you could write a shader in such a way that it forces the software renderer. If someone could provide a list of dos and don'ts for these type of things it would be quite useful.

Perhaps I'll even start the ball rolling

DO use display lists for anything that is drawn more than once and doesn't change.
DONT use immediate mode. it's slow.
DONT draw more textures than fit in VRAM at once. Texture paging is slow.
DONT use glReadPixels unless absolutely necessary. slow.
DONT use textures larger than about 1024x1024 or 512x512 if you want to support the rage128. they will get corrupted on lower end machines.

David

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #3
Thanks a lot thats sounds like good advice + funny sig.

Well I was just wondering if the pixelformatt could be setup better for a 2D game as opposed to 3D. Would it be a good idea to disable depth testing or would that not really affect anything? Ill try out shark, ive not used any of those profiler tools yet, shark sounds pretty neat.

just a couple of questions
whats immediate mode and how do i avoid it?
Im only using about 10 textures that are each 128x128, that will not be too many will it?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #4
unknown Wrote:Im only using about 10 textures that are each 128x128, that will not be too many will it?

128*128*4*10/(bytes per MB) = 0.625 MB.
So, no.

A 512*512 RGBA texture is 1MB. *Most* people have at least a 32MB card.
Quote this message in a reply
Member
Posts: 320
Joined: 2003.06
Post: #5
unknown Wrote:whats immediate mode and how do i avoid it?
immediate mode is when you call glBegin and glEnd to do your drawing each frame. You avoid it by using display lists or some vertex-thingee like VAR or VBO. I generally code every new addition using immediate mode, and change it over to vertex arrays or display lists when performance becomes an issue.
If you're just starting out, immediate mode is fine to play with, just switch when you need a faster path.

The pixel format you're using looks fine. There's really no difference between a pixel format for 2D or 3D, you just will need to add extra bits and pieces if and when you need them.

For 2D you probably want to disable depth testing. Just draw everything in order, back to front. It won't make much difference with performance, but it's usually easier than trying to keep track of the z value everything is drawn at.

Chopper, iSight Screensavers, DuckDuckDuck: http://majicjungle.com
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #6
right, great thanks ill depth testing and I am using lists so thats good.
Does SDL_GL_DEPTH_SIZE matter?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #7
unknown Wrote:right, great thanks ill depth testing and I am using lists so thats good.
Does SDL_GL_DEPTH_SIZE matter?

However, if it's for a 2D game beware. Putting a single quad in a DL will actually be worse than using immediate mode. That said, most 2D games won't actually be drawing enough stuff to make immediate mode a problem. (Unless you have lots and lots of particles)
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #8
hmmmm, very confusing..
How would I using CHUD tools check which is quickest??

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 771
Joined: 2003.04
Post: #9
unknown Wrote:hmmmm, very confusing..
How would I using CHUD tools check which is quickest??

If you are just starting out, and don't have any large amount of code already, don't bother. Just make a couple of for loops, render a few thousand polygons using immediate mode, VAR, whatever you'd like to test. Check the framerate, and if there isn't a big difference (if you have VBL on, you probably won't see any difference with just a few thousand triangles), choose whatever is easier for you.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #10
VAR?
VBL?

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #11
unknown Wrote:VAR?
VBL?
GIYF. Rasp

If you search the forums, you should be able to find threads about both of those. If you are just beginning to use OpenGL, though, then it may be wise to hold off on worrying about VAR and a lot of optimization and just get the basics down.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #12
GIYF??????????

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #13
unknown Wrote:GIYF??????????
Google is your friend.
Quote this message in a reply
Sage
Posts: 1,403
Joined: 2005.07
Post: #14
LOL is certainly is!

Sir, e^iπ + 1 = 0, hence God exists; reply!
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Pixel Buffer Object setup issue dotbianry 2 3,468 Jan 6, 2013 11:03 AM
Last Post: dotbianry
  OpenGL ES2 matrix setup (humbly crawling back) Fenris 2 6,834 Aug 31, 2011 06:47 AM
Last Post: Fenris
  bug in OpenGL setup for NSOpenGL subclass (I think) backslash 2 3,845 Jul 18, 2007 01:10 PM
Last Post: backslash
  xCode/SDL Setup hammonjj 2 4,863 Mar 2, 2007 06:37 AM
Last Post: hammonjj
  Fullscreen/Window Setup/toggle skyhawk 10 5,033 Oct 13, 2006 04:05 PM
Last Post: skyhawk