Best Way to do Sprites?

Member
Posts: 29
Joined: 2004.11
Post: #1
Hey Everyone,

I have just started using OpenGL and GLUT and (with the help of NeHe and OneSadCookie's Tutorials) a widow with a red cube that you can move around with arrow keys (took me 4 Hours to make...). As a next step I wanted to know how I could turn that 2D cube into a sprite with a transparent back (i.e. plane or spaceship sprite).

I would appreciate a simple method since I do not have a ton of knowledge about OpenGL.

Thanks,

AGhost
Quote this message in a reply
Moderator
Posts: 508
Joined: 2002.09
Post: #2
Learn how to load an image in OpenGL and turn it into a texture. Then use that texture to texturemap you Quad using glTexCoord2f() functions.

If you are using Cocoa, you can load a png file using NSImage, turn it into an NSBitmapImageRep and use the data to generate a texture using glGenTexture and glTexImage2D (or something).

"When you dream, there are no rules..."
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
<insert my standard plea to *not* use NSBitmapImageRep for that task here>
Quote this message in a reply
Moderator
Posts: 592
Joined: 2002.12
Post: #4
OneSadCookie Wrote:<insert my standard plea to *not* use NSBitmapImageRep for that task here>

What are the reasons for not using NSBitmapImageRep?
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
If you create the NSBitmapImageRep yourself, telling it what pixel format to use, there's no problem.

If you don't, you have no guarantee what pixel format it will use. It can use all sorts of things, including planar formats, wacky rowbytes, etc -- mostly completely useless for sending to OpenGL.

Mostly, it'll give you a useful format, but if you rely on that being the case, you are likely to break in a future OS update. Tiger changed the set of pixel formats that NSBitmapImageRep actually produces in practice, and many applications that made invalid assumptions about what they'd be given broke as a result.

That means that in order to be safe, you need to be able to convert *all* the wacky pixel formats that NSBitmapImageRep could use, into sane ones. Good luck with that...

Or you could use an API like QuickTime's GraphicsImport or ImageIO which draw the image into a buffer with a user-specified pixel format, and avoid the issue entirely.
Quote this message in a reply
Member
Posts: 41
Joined: 2006.01
Post: #6
Use a high-contrast background. Grab the images off the display, drag them into photoshop and remove the background. You may have to re-mix the edges a little, but that can be done en-mass.
Quote this message in a reply
Post Reply