Where to save sprites in memory in OpenGL?

forseti
Unregistered
 
Post: #1
Hi,

I have my resource image loading function that loads in a tile set image from the hard disk and do some calculations, then extract raw bitmap data.
My question is, what kind of OpenGL data structure should I use to save sprites, tiles, and other images? I was thinking of loading each tile set image (source image that each contains say an animation sequence for a character, or a bunch of tiles to blit on the ground on screen) into an OpenGL texture... but what if I save them into an off-screen OpenGL context instead? Or just as a raw bitmap data, nothing to do with OpenGL, and then pass the data to OpenGL drawing functions. Why is there a need to store resources in OpenGL textures? Since I won't be using OpenGL textures to put them on 3D surfaces, I wonder what the merit is in using OpenGL textures...

Oh, and I'm using OpenGL for 2D purposes, I use no 3D.

Thanks for your help. Smile
Quote this message in a reply
henryj
Unregistered
 
Post: #2
The 'traditional' way to do sprites is to load your images into some memory buffer and then blit them to the screen. You can do this this with OpenGL using glDrawPixels. It works the same way. You give it a pointer to some memory and the size of image and it writes it to screen.

The down side of this is that it might not be as fast as other methods but test it before you make that judgement.

The upside for using textured quads is that it will be the fast. You can apply textures to 2D shapes just as well as 3D. Texture rendering libraries usually do this. You can even apply textures to lines.

One thing to note is that you should combine lots of sprites into one texture. Join them all together and use the texture coordinates to 'pick' your sprite.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Textures will be the fastest way (they're stored in VRAM, where other things you could do won't be).

They're also the most flexible -- you get rotation, scaling, transparency, &c for free, not to mention 3D effects if you decide to get fancy Smile
Quote this message in a reply
henryj
Unregistered
 
Post: #4
Whoops. Should have said...

"TEXT rendering libraries usually do this"
Quote this message in a reply
sty
Unregistered
 
Post: #5
Hi guys,

Sorry for resurrecting this old(ish) thread.

I have just actually started learning OpenGL specifically as I fancied writing a game or some demos and thought about building a 2D sprite/background engine using OpenGL so that just as OneSadCookie says I can get the benefit of rotation, scaling etc. and in the future start to add 3D effects as well.

I'm programming in Cocoa on OSX and my computer is a TiBook 500MHz so it should have plenty of grunt. However even the simple stuff that I am looking at seems to be struggling for performance.

I'm actually working my way through the NeHe tutorials, but rotating a couple of simple shapes if dragging the system to it's knees.

So a couple of questions:

1) Anybody know whether OpenGL on OS X (10.1.5 I think) is hardware accelerated on my machine.

2) Do I need to install something, or code differently to use HW acceleration.

3) Are there any demos or examples of people using 3D HW for these 2D types of things. (I was especially interested by OneSadCookies comment about putting all sprites in one texture - that is on my wavelength)

BTW: the demos I am running are in 16bit colour, same as my screen display.

any help of pointers would be welcome.
Quote this message in a reply
ylaporte
Unregistered
 
Post: #6
Quote:Originally posted by sty
Hi guys,

Sorry for resurrecting this old(ish) thread.

I have just actually started learning OpenGL specifically as I fancied writing a game or some demos and thought about building a 2D sprite/background engine using OpenGL so that just as OneSadCookie says I can get the benefit of rotation, scaling etc. and in the future start to add 3D effects as well.

I'm programming in Cocoa on OSX and my computer is a TiBook 500MHz so it should have plenty of grunt. However even the simple stuff that I am looking at seems to be struggling for performance.

I'm actually working my way through the NeHe tutorials, but rotating a couple of simple shapes if dragging the system to it's knees.

So a couple of questions:

1) Anybody know whether OpenGL on OS X (10.1.5 I think) is hardware accelerated on my machine.

2) Do I need to install something, or code differently to use HW acceleration.

3) Are there any demos or examples of people using 3D HW for these 2D types of things. (I was especially interested by OneSadCookies comment about putting all sprites in one texture - that is on my wavelength)

BTW: the demos I am running are in 16bit colour, same as my screen display.

any help of pointers would be welcome.

OpenGL should be hardware accelerated on your mahine. You don't need to do anything special to use it (in normal conditions) but you can check your rendering context so it uses the hardware accelerated drivers. I don't remember how to do this and never really had to do it.

Ok, many gotchas that could be hurting you when doing this kind of stuff in OpenGL. If you loaded your texture once, I mean created teh texture and insert you data in, you don't need to do it for every frame, do it just once at initialisation. I know it seems logical but I have seen many examples of people reloading textures every frame.

Be sure to follow the pipeline's flow. It means to follow teh order in which things are done in OpenGL in the functions your calling.

I am not sure about this one, but I know it is a gotcha on many PC graphic cards: Do not run in 16 bits. 16 bits color sometimes revert to all software rendering so that you can compare the software driver results with the ones accelerated. So try using 32 bits.

If you use very large textures maybe they are too large for your card's memory, check you graphic card's specs to be sure.

And finally, use the profiler (Sampler.app)... It is a reflex you should develop for whenever your performance seems to be lagging.
Quote this message in a reply
Member
Posts: 328
Joined: 2002.04
Post: #7
(Soimewhat off topic... but doesn't Jaguar [Quartz Extreme] render the whole screen as a bunch of textures on flat images [using 3D HW for these 2D types of things]? Just curious, because that's what I've gathered, but I'm not sure if that was true.)
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL Point Sprites Talyn 10 13,503 Jan 18, 2009 05:55 PM
Last Post: Talyn
  OpenGL Texture Loading & Sprites corporatenewt 2 11,087 Jan 30, 2008 12:39 PM
Last Post: ynda20
  Drag to save unknown 3 2,784 Mar 11, 2006 07:45 AM
Last Post: unknown
  How would I save an NSView as a JPG? Joseph Duchesne 0 3,069 Sep 30, 2005 07:51 PM
Last Post: Joseph Duchesne
  Save GIF file... alert 6 4,510 Jan 11, 2005 08:48 AM
Last Post: ThemsAllTook