Dark Bit Factory & Gravity

PROGRAMMING => General coding questions => Topic started by: energy on September 06, 2007

Title: glaux - loading an image from memory
Post by: energy on September 06, 2007
Hi!
does anybody know how to load a bitmap with glaux from memory??

thank yu in forward...

Title: Re: glaux - loading an image from memory
Post by: Jim on September 06, 2007
Nobody really uses glaux any more (since years ago).  It has some problems, and noone will know anything much about it.  Can you use one of our other loaders?
http://dbfinteractive.com/index.php?topic=2334.0 (http://dbfinteractive.com/index.php?topic=2334.0)
http://dbfinteractive.com/index.php?topic=73.0 (http://dbfinteractive.com/index.php?topic=73.0)
http://dbfinteractive.com/index.php?topic=116.0 (http://dbfinteractive.com/index.php?topic=116.0)

You didn't say which language you're coding in, or if you can use Windows API.

Jim
Title: Re: glaux - loading an image from memory
Post by: energy on September 07, 2007
Hi Jim!

Thanx for answer.... im Coding in Purebasic....
I just tested the OpenGL Engline from here ... http://dbfinteractive.com/index.php?topic=1575.0
In the function there is glaux used for loading bitmap as file from disk....

Im OPENGL Beginner and i just tried to load a bitmap from memory for converting as texture...
I thought OGL has an internal LOader for this....!!

to load a bitmap with purebasic in memory is not the problem, but how to convert it as Texture???

Cheers .....eNeRGy
Title: Re: glaux - loading an image from memory
Post by: Jim on September 07, 2007
OpenGL itself doesn't support any file formats, you have to do that bit yourself.  What OpenGL needs is a pointer to the raw picture data, usually an array which is a power of 2 wide and a power of 2 high, eg. 32x128 or 256x256.  The array is best kept as 32 bit unsigned integers which holds the r,g,b and a.  Then you call glTexture2d() with a pointer to that array to set the texture.
The code you linked to is able to load .tga files or .raw files - raw files have no header they're just plain rgb data.

Is it possible in PureBASIC to get a pointer to the raw graphics data once it's loaded an image?  If not, you could always just draw it to the screen in the normal way and read back the pixels in to an array.  Remember to set the alpha to 255.

Keep posting if this doesn't make any sense and we'll try to fix you up :)

Jim
Title: Re: glaux - loading an image from memory
Post by: energy on September 07, 2007
Hi Jim!

Now i wrote a routine to get the RGB Data of any file in a Array....
Could yu please explain me now the way to get them into the texture?

thanks and cheers....
energy
Title: Re: glaux - loading an image from memory
Post by: Rbz on September 08, 2007
Now that you have your RGB data array, to create your texture is simple, first, generate ogl texture:

Code: [Select]
GLuint texture;
glGenTextures(1, &texture);

Bind texture
Code: [Select]
glBindTexture(GL_TEXTURE_2D, texture);
you can add an image filter:
Code: [Select]
//Create Linear Filtered Texture
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);

Now build your data array into ogl texture
Code: [Select]
gluBuild2DMipmaps (GL_TEXTURE_2D, 3, TEX_Width, TEX_Height,  GL_RGB, GL_UNSIGNED_BYTE, your_image_array_buffer);
Title: Re: glaux - loading an image from memory
Post by: energy on September 10, 2007
Thanx RBRAZ!!!
Will test tommorow....
 :carrot: