PDA

View Full Version : Texture Loading



bobGL
12-27-2005, 06:08 PM
I'm trying to dynamically load texture during my OpenGL application, but if I put the loading in the main render loop its slowing down my app.

I try to put the loading into a thread (pthread) but a soon as I access ANY gl instruction the program crash... I guess its because the GLX context is linked with the main thread? So...

How I can do the loading of my textures in a thread and then assigned them to my model when they are loaded?

I google quite a bit but didn't find anything... Please help!!!

Tks in advance...

glBug
12-27-2005, 10:52 PM
1. start your app and enter the "rendering loop"
2. when the new texture-s is/are required, start the loading thread - to load the data RGBA bytes [for example from a PNG file] into the memory. DO NOT call any gl Commands from the loading thread
3. your other thread [the one with rendering loop],
will check in some intervals, or get notified if the texture data were loaded into the memory
4. once the data were loaded [and the loading thread successfuly finished] , use the data [from the main thread] to create the texture

bobGL
12-28-2005, 08:01 PM
Hummmm, yeah this approach definetly help but how about that:

Imlib2 to OpenGL textures???

How can I render a Imlib_Image to a texture???


img = imlib_create_image_from_drawable((Pixmap)0,0,0, window_attr.width, window_attr.height,1);
imlib_context_set_image(img);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, window_attr.width, window_attr.height, GL_RGB, GL_UNSIGNED_BYTE, img);Compile but nothing happen??? help!!!!

glBug
12-29-2005, 06:34 PM
The code snippet you posted does not seem to be right. The function Imlib_create_image_from_drawable
returns ImlibImage* , and you are passing
ImlibImage* img to the function gluBuild2DMipmaps, however gluBuild2DMipmaps expects const void* img. You have to change your code from:


gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, window_attr.width, window_attr.height, GL_RGB, GL_UNSIGNED_BYTE, img);to


gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, window_attr.width, window_attr.height, GL_RGB, GL_UNSIGNED_BYTE, (const void*)(img->rgb_data));the example above is for imlib, with imlib2 the above is still true, just the type names and function names are different, you have to get the
RGB image data from the Imlib_Image calling the imlib_image_get_data_for_reading_only function:



img = imlib_create_image_from_drawable((Pixmap)0,0,0, window_attr.width, window_attr.height,1);
imlib_context_set_image(img);
DATA32* data = imlib_image_get_data_for_reading_only();

//...

gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGB, window_attr.width, window_attr.height, GL_RGB, GL_UNSIGNED_BYTE, (const void*)data);

bobGL
01-08-2006, 01:42 PM
Great! Works like a charm, however, I'm loading textures of 1024x1024, and it's a bit slow, is there another way to speed things up? or using gluBuild2DMipmaps (cuz glTexture2d is even slower...) is my only option???

I even try to "cut" the picture (like 4x512x512) but it doesn't take about the same loading time... What is the best way to load large texture REALLY fast?

Tks in advance,