Sign in to follow this  
nunosantos

OpenGL Problems loading texture directly

Recommended Posts

Hi, I cant load textures directly with opengl. I think i'm failing some parameter because everything works perfectly if i use images[i] = Ilut.ilutGLBindTexImage(); But if i use: Gl.glBindTexture(Gl.GL_TEXTURE_2D, images[i]); Gl.glTexImage2D(Gl.GL_TEXTURE_2D, 0, 3, Il.ilGetInteger(Il.IL_IMAGE_WIDTH), Il.ilGetInteger(Il.IL_IMAGE_HEIGHT), 0, Gl.GL_RGB, Gl.GL_UNSIGNED_BYTE, Il.ilGetData()); It doesnt work. I was not very worried about this as i was already achieving what i wanted. The thing is that now, i realize that i suffer of a memory leak problem as Ilut.ilutGLBindTexImage(); seems to be generating new textures everytime it's called. And it is called a lot of times because i really need to. If i could load the texture in a manual way, everything would be fine. Can anyone give me a tip here? Thx, Nuno

Share this post


Link to post
Share on other sites
You need to load the texture image from a .tga, .bmp whatever file you like with either your own loader or use a library e.g. Devil or one of the many other libraries out there. Then you take the data it loaded and send that to the glTexImage2D(). HTH

Share this post


Link to post
Share on other sites
Hi,

Someone has give me the answer using glDeleteTextures:

Here is my actual loadImages function:

private bool LoadImages()
{
Console.WriteLine("Loading images!");

try
{
Il.ilGenImages(2, imageIds); // Generate Image Ids

if (images[0] != -1) // Free up old textures
{
Gl.glDeleteTextures(2, images);
images[0] = -1;
images[1] = -1;
}

for (int i = 0; i < 2; i++)
{
Il.ilBindImage(imageIds[i]); // Bind Image Id to Be Current
if (!Il.ilLoadImage(imagesName[i]))
{
Il.ilDeleteImages(2, imageIds);
return false;
}

Console.WriteLine(
"Image name: " + imagesName[i] +
" Width: " + Il.ilGetInteger(Il.IL_IMAGE_WIDTH) +
" Height: " + Il.ilGetInteger(Il.IL_IMAGE_HEIGHT));

images[i] = Ilut.ilutGLBindTexImage();

if (Il.ilGetError() != 0)
{
Console.WriteLine("Image loading error report: " + Ilu.iluErrorString(Il.ilGetError()));
Il.ilDeleteImages(2, imageIds);
return false;
}

Il.ilDeleteImages(2, imageIds); // Should not need the ilImage since there is now an OpenGL Image
}
}
catch (AccessViolationException error)
{
Console.WriteLine("Access Violation Exception: " + error.Message);
}

return true;
}

Best regards,

Nuno

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this