2D images in openGL(how to animate)

Started by
11 comments, last by Axesor 18 years, 1 month ago
Question above and can you use Bltblt()? or any color transparency you do not want to see?
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
Advertisement
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.
Ooh, yeah. That was very descriptive...
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
actually, meeshoo explained it perfectly. here's something to add transparency.
for(int i = 0; i < imageWidth * imageHeight; i++){	if(pixels.r == transparentColor.r            && pixels.g == transparentColor.g            && pixels.b == transparentColor.b)	{		pixels.a = 0;	}}
Ahh. So how would you apply it?
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
Between the code that loads your image and the code that creates the texture
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!
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
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]

- Jason Astle-Adams

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 bitmapObject[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.
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward
I came across a snag, I will not be able to use targ files. I will have to use bitmaps... How will you do transparency with those?
.::WARNING!::. Axesor is a total newb or n00b! Beware his lack ofintellegence of OpenGL. Feel sorry for him and keep him in your thoughts.~Leader of the phsychoward

This topic is closed to new replies.

Advertisement