OpenGL Sprite Structure

Post: #1
I am working on a 2d isometric OpenGL(with which I'm fairly inexperienced in) engine using Carbon C, which renders tiles and sprites as textured quads. My trouble is, I can't seem to find any practical way to implement a sprite structure. With my old 2d engine I simply had a sprite sheet, containing all of the sprites for the respective character, which I would copy to a single GWorld. With OpenGL, it appears to me that I will have to load each individual frame as a seperate texture, which seems very impractical and time consuming. Is there any practical way to go about this?
Quote this message in a reply
Posts: 522
Joined: 2002.04
Post: #2
As you are submitting vertex data to OpenGL you are also submitting texture coordinate information. You can simply change the texture coordinates so that your sprite (quad) is only displaying part of your texture. If 0..1 is your entire texture, you can do some arithmetic to figure out what the coordinates of a certain segment are.

Quote this message in a reply
Posts: 3,591
Joined: 2003.06
Post: #3
Stalin55: You can do essentially the same thing with OpenGL. You can put many sprites in one image and load it as a single texture. It'll probably be most logical to use something like 512x512 or 1024x1024 for your image size. Once the texture is loaded then all you have to do is do glBindTexture to the textureName (or ID, as I call it) of that group of sprites. Then when you draw your quads you use coordinates that correspond with the particular portion of the texture you want to use, which would be the coordinates for the rectangle surrounding a particular sprite. I'll assume you'll be using GL_TEXTURE_2D... For simple tutorials with OpenGL it might seem like you'd always use coordinates like 0.0f, 0.0f for the lower left of the texture and 1.0f, 0.0f for the lower right of the texture. For your purposes, you can define those anywhere in-between 0.0f and 1.0f (or even outside of 0-1 if you wanted to for some reason). Something like 0.0f, 0.5f would only be referring to half of the image. You can use any numbers you want to zoom in on any particular area of a texture. This is hard to explain in words. Consult the Red Book for examples, or experiment a little yourself.

[edit] darn it, aarku just barely posted while I was previewing. Oh well, I'll leave it for the sake of repetiveness.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Sprite game with OpenGL/GLKit InvisibleMoustache 6 13,906 Oct 10, 2012 09:20 AM
Last Post: OneSadCookie
  Sprite transparency in OpenGL? Guest! 26 44,391 Feb 17, 2012 09:24 AM
Last Post: Skorche
  SDL + OpenGL Sprite Loading Problem Greywhind 3 6,973 Jun 29, 2006 04:44 PM
Last Post: OneSadCookie
  2D Sprite Tutorial in OpenGL DJBlufire 4 9,846 May 12, 2003 12:46 AM
Last Post: arekkusu