Texture from file

Hi! my question is in the title :wink: I show a source in win32 borland c++:

 bitmap = new Graphics::TBitmap;
    GLubyte bits[64][64][4];
    for(int i = 0; i < 64; i++)
    	for(int j = 0; j < 64; j++)
            bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
            bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
            bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
            bits[i][j][3]= (GLbyte)255;

so that is what i want to do in linux, maybe with .jpg or .png images.


Use libpng or libjpg. They are installed on most Linux systems. It wouldn’t very hard follow its documentation and they’ll save you from many troubles. You can also use SDL_Image if you are using SDL in order to load the textures directly from .jpg or .png files.

Thanx! I try it.

I can’t find the libjpg in the gentoo portage:(

It’s probably libjpeg

NO :smiley: it’s only “jpeg”. Interesting…

Originally posted by zeedee:
NO :smiley: it’s only “jpeg”. Interesting…
Make sure you also install the development packages e.g.: .h files and import libraries. On my system:

$> rpm -qa | grep jpeg

The first one contains the dynamic libraries; the second, header files and all the stuff needed to compile.

most of the GNU/Linux distributions come with a great library called “GdkPixbuf”.

look if it is installed on your system:
pkg-config --list-all | grep “GdkPixbuf”

if it is installed you will get the following result:
gdk-pixbuf-xlib-2.0 GdkPixbuf Xlib - GdkPixbuf rendering for Xlib
gdk-pixbuf-2.0 GdkPixbuf - Image loading and scaling

and it means you can use it:

GdkPixbuf* pixbuf = NULL;

pixbuf = gdk_pixbuf_new_from_file ("/path/to/textures/texture_256x256.png", &error );

const guchar* pixels = gdk_pixbuf_get_pixels(pixbuf);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*)pixels );


GdkPixbuf lib will load you .png, .bmp, .jpg, etc.

I can’t find the libjpg in the gentoo portage:(
Just install it yourself, then. LibPNG is rather easy to compile/install (note that you do need zlib as well). Heck, I installed it on my MinGW/MSYS Win32 box.

If you’re using Qt, you get PNG & JPEG support via Qt’s QImage that can easily be used to load your images.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.