Best Way to do Sprites?
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
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
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).
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..."
<insert my standard plea to *not* use NSBitmapImageRep for that task here>
OneSadCookie Wrote:<insert my standard plea to *not* use NSBitmapImageRep for that task here>
What are the reasons for not using NSBitmapImageRep?
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.
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.
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.

