2d animations
Hey, this is prolly a lamo question for all those hardcore openGl''ers, but i''m just getting into it all and lov''n it!
ok, here''s the problem:
i want to make a 2d character be able to run around the screen much like mario and have different animations for different actions.... ie: running, jumping, etc...
the best way i can think of to do this is to have all the frames of the animations all in say mario.bmp in a strip and in my program i''ll have an array of textures of each frame from this ONE file.
the question basically is i''m not sure how i would go about loading each frame in from the one file rather than multiple files..?
i was thinking about using the function below, and somehow using data as each frame... argg.. hheellpp meee
gluBuild2DMipmaps(..,..,..,...,...,...,data);
thanks in advance
Read NeHe''s tga/bmp text loading tutorial, each charactor is
in the same file...
in the same file...
www.jinx.com www.thebroken.org www.suprnova.org www.mozilla.org
ahh.. i had a good look through the tutorials and i can''t see the one that you''re talking about.
all the text ones that i can see seem to be created from a font.h include, rather than asdf.bmp picture file including heaps of different pictures or whatever.
which tut number is the "tga/bmp text loading" one please? sorry, i did have a look
thanks
all the text ones that i can see seem to be created from a font.h include, rather than asdf.bmp picture file including heaps of different pictures or whatever.
which tut number is the "tga/bmp text loading" one please? sorry, i did have a look
thanks
July 01, 2003 11:46 PM
i load one frame from one file
i dont know why jam all frames into one file
whats the difference of two 4kb files and one 8kb file?
i dont know why jam all frames into one file
whats the difference of two 4kb files and one 8kb file?
July 02, 2003 12:40 AM
quote:
Original post by Anonymous Poster
i load one frame from one file
i dont know why jam all frames into one file
whats the difference of two 4kb files and one 8kb file?
The difference is the time it takes to open two files instead of one.
-CBD
Something I made awhile ago that works to extract an image out of a file x and y are the location in pixels to start then registers the part of the image to the card and returns the id of the image for binding so you can store those into an array
class TextureImage{public: unsigned char *buffer; GLuint bpp; GLuint width; GLuint height; GLuint id; int flags;//Sample from inside the class all you need to seeTextureImage::Extract(int x, int y, int ex_width, int ex_height){ unsigned char *src = NULL,*dest = NULL, *dest2; unsigned int type = GL_RGBA; int bytes_per_pixel = bpp/8; unsigned int id; dest = new unsigned char[ex_width * ex_height * bytes_per_pixel]; x = x * (ex_width); y = y * (ex_height); src = buffer + (y * (width * bytes_per_pixel) + (x * bytes_per_pixel)); dest2 = dest; for(int index = 0; index < ex_height; index++) { memcpy(dest2, src, (ex_width * bytes_per_pixel)); dest2 += (ex_width * bytes_per_pixel); src += (width * bytes_per_pixel); } glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); if(bpp == 24) type = GL_RGB; glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D, type, ex_width, ex_height, type, GL_UNSIGNED_BYTE,dest); free(dest); dest2=NULL; src = NULL; return(id);}
quote:
Original post by Anonymous Poster
i load one frame from one file
i dont know why jam all frames into one file
whats the difference of two 4kb files and one 8kb file?
In addition, you can unleash some nice formula''s on the surface, trimming the frames to the one you want.
e.g. have an animation of 8 frames, and a short, telling you which frame to display. Then trimming so that only that one will be copied onto the buffer
Plus if you are rendering multiple copies of the animation ( say for those little shroom enemies mario loves to squash
) you won''t have to do another texture bind in between - just changing the UV coords gives the desired result.

This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement