Jump to content
  • Advertisement
Sign in to follow this  
nunosantos

OpenGL Problems loading texture directly

This topic is 4153 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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 = Ilut.ilutGLBindTexImage(); But if i use: Gl.glBindTexture(Gl.GL_TEXTURE_2D, images); 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
Advertisement
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); // Bind Image Id to Be Current
if (!Il.ilLoadImage(imagesName))
{
Il.ilDeleteImages(2, imageIds);
return false;
}

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

images = 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!