OpenGL Texture Loading & Sprites

Nibbie
Posts: 2
Joined: 2007.12
Post: #1
I've been trying to get started with OpenGL programming for a while now. I've been using it in Xcode with Cocoa. I can setup the view, create and move colored boxes and do collision detection. The one thing that repeatedly stumps me, though is textures. What I would like to eventually be able to do is to create a 2D side-scrolling game and use OpenGL to draw my sprites and etc. I have a hard time with loading textures, and I don't know how to approach sprites with OpenGL, though. If someone has an example that would show how to load textures (containing alpha channels that should be applied) and use them as sprites that would be very helpful.

I'd appreciate any help and direction.

- Corporate Newt
Quote this message in a reply
⌘-R in Chief
Posts: 1,254
Joined: 2002.05
Post: #2
See this thread, particularly OneSadCookie's post:
http://www.idevgames.com/forum/showthrea...re+loading

For sprites, all you have to do is simply stick a texture on a simple quad. Bam.

Is there a more specific question you had?
Quote this message in a reply
Apprentice
Posts: 16
Joined: 2008.01
Post: #3
Well its more than just slapping a texture onto a Quad...

Sprites are usually animated so you will need several frames of animation. This is easy to achieve - you just load the texture with all the frames, bind it to the Quad, then change the texture coordinates at a particular time period (about every tenth of a second - it will vary depending on the effect you want to achieve).

Then there is the dreaded alpha bending to allow the alpha channel to actually work - this should be covered in tutorials - so that the sprite is not just displayed as a quad.

If you are working in 3D in any way (even for 2D games) you may want to sort your sprites for depth so that the sprites overlap properly, the so-called painter's algorithm, which just means drawing the furthest items first!

And then finally, sprites generally do different things: go left, go right, fire, blow up etc - so the list of textures for any particular character needs to be tied together by some loose data structure such as an array.

Incidently, I use FutureBASIC (which I find a lot easier to use than C ).
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  OpenGL ES Texture Masking airfire 6 14,621 Mar 17, 2014 07:07 PM
Last Post: baioses
  OpenGL ES Texture Compression ajrs84 9 4,012 May 7, 2013 03:36 PM
Last Post: ajrs84
  OpenGL ES Texture Masking dalasjoe sin 0 3,826 Apr 13, 2012 12:17 AM
Last Post: dalasjoe sin
  Texture in OpenGL ES 2 looks pixelated vunterslaush 18 22,960 Aug 30, 2011 09:44 PM
Last Post: Frogblast
  Lighting and changing texture colors in OpenGL agreendev 2 7,637 Aug 13, 2010 03:47 PM
Last Post: agreendev