Sign in to follow this  

2D images in openGL(how to animate)

This topic is 4290 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The animation is done by mapping your sprites on quads, ast textures.Then you must use your alpha channel from your textures(32 bit textures, like TGA) for making transparencies.

Share this post


Link to post
Share on other sites
actually, meeshoo explained it perfectly. here's something to add transparency.

for(int i = 0; i < imageWidth * imageHeight; i++)
{
if(pixels[i].r == transparentColor.r
&& pixels[i].g == transparentColor.g
&& pixels[i].b == transparentColor.b)
{
pixels[i].a = 0;
}
}

Share this post


Link to post
Share on other sites
I am a nebie with OpenGL and I unfortunately only know the basics and I have not found any 'shortcuts' or 'tricks' yet so can you give me a working program? aybe one animated too?

Thanks!

Share this post


Link to post
Share on other sites
As mentioned by the above posters, to draw a sprite on screen using OpenGL you need to load your file into memory, and then map it on to a quad (basically a rectangle) as a texture. Lesson #6 at NeHe explains how to do texture mapping with a bitmap in OpenGL. Be aware that this lesson builds on code created during earlier lessons on the site.

To create transparency you would usually use the alpha channel of your graphic, using a format such as targa (.tga) or PNG (.png) which supports transparency. If you don't have a graphics editor capable of creating files of this type, you could try the freely available Paint.NET or The GIMP. NeHe's Lesson #33 covers loading compressed or uncompressed TGA files (which you can then texture map just like you could with the bitmap).

If you need further documentation on the functions used, you could check out The OpenGL Reference Manual ('Blue book'). If you're just starting out with OpenGL, you may also be interested in The OpenGL Programming Guide ('Red book'), although many people consider it to not be particularly beginner friendly.


Lastly, just as a potential alternative if you're having trouble with OpenGL and are trying to work in 2d, you could potentially look into using a simpler library such as SDL instead.

Hope that helps. [smile]

Share this post


Link to post
Share on other sites
Hehe. I am not that much of a newbie. I just don't undertstand how you would implement a transparency and the 'animated' quad.

Would you do something like this?(For a horizontal bitmap with frames of 9):

Object[0].width = 90; //width by height, we are only finding width 90x20 bitmap
Object[0].frames = 9;
Object[0].framesz = Object[0].width/Object[0].frames;
Object[0].currentf = 0;
/*width / frames = a size 10 for the 9 frames*/

...
int currentf = Object[0].currentf;
glBindTexure(GL_TEXTURE_2D);
glTexCoord2f(Object[0].framesz*currentf, 20);

...




Something like that to seperate the frames and put them down on a 10x20 quad?
PS: I have photoshop ,therfore I can do the transparency. Thanks about that.

Share this post


Link to post
Share on other sites
When you're blitting your image just check for the magenta colour and just don't draw it. Or preprocess it by searching through your array of data and setting magenta's transparency to 0 or something along those lines depending on how you do your drawing.

Share this post


Link to post
Share on other sites

This topic is 4290 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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