Sign in to follow this  
vicer1234

Sprite reading through Opengl

Recommended Posts

Hi, I am trying to read a sprite from sprite sheet and want to display it using opengl(c++).I am not able to get a proper logic for extracting a particular sprite and display it using a quad in opengl.If anyone one can give me any suggestions it will be very helpfull. Thanks in advance...

Share this post


Link to post
Share on other sites
You need to bind a texture for your sprite sheet image and then draw a textured quad, with texture coordinates describing the correct part of the image. The way you find the correct part will depend on the sprite sheet, you may need to load a separate file describing the frame rectangles explicitly, or if your sprites are arranged in a regular grid you may be able to compute an offset based on the frame your on and a constant frame size.

Share this post


Link to post
Share on other sites
Quote:
Original post by Somnia
You need to bind a texture for your sprite sheet image and then draw a textured quad, with texture coordinates describing the correct part of the image. The way you find the correct part will depend on the sprite sheet, you may need to load a separate file describing the frame rectangles explicitly, or if your sprites are arranged in a regular grid you may be able to compute an offset based on the frame your on and a constant frame size.


Hi,
I will be using sprite sheet of sizes power of 2 like 512x512 or 1024x768 etc.
The sprite sizes if that too if i take it as power of 2 then whats the logic can you please elaborate.

Share this post


Link to post
Share on other sites
Sorry I'm not sure what your question is. Do you know how to load an image, bind a texture, draw a quad and use texture cordinates? If not there are lots of tutorials about, here for example: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06

If so then the only problem is knowing the correct texture coordinates that describe the image sub region for the frame you want to draw. There are lots of ways of handling this, usually involving some kind of meta-data file loaded along with the animation that contains this information.

Share this post


Link to post
Share on other sites
I created a video tutorial on this which you can download here:
http://www.marek-knows.com/downloadSection.php?Topic=OpenGL&pg=1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this