Jump to content
  • Advertisement
Sign in to follow this  
dedesite

OpenGL [solved] Save a Texture with DevIL

This topic is 2645 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 everybody,

I've been a game developer (mostly tools) for 2 and a half years and now I'm working as a web developer but still doing some game development stuff as amateur :).

I try to save 32 and 16bits OpenGL textures into a file using DevIL which seems to be a very simple library.

Since my knowledge in OpenGL and DevIL is a bit limited, I'm kind of stuck... and I can't find any tutorial explaining how to do it.

Here is approximately what I do (I've simplified the code just to let the OpenGL+DevIL part) :

#include "IL/il.h"
#include "IL/ilu.h"
#include "IL/ilut.h"

void save_texture(GLuint texture)
{
int width = 128;
int height = 128;

glBindTexture(GL_TEXTURE_2D, texture);
glCopyTexImage2D(GL_TEXTURE_2D,0,GL_RGB,0, 0, width, height,0);

ILuint img_size = sizeof(BYTE) * width * height * 3;
BYTE *raw_img = (BYTE*) malloc(img_size);
glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, raw_img);

if(raw_img != NULL)
{
//Then save it using devil
ILuint ImgId = 0;
ilInit();
ilGenImages(1, &ImgId);
ilBindImage(ImgId);

//I don't know if ilCopyPixel is the right function to call
ilCopyPixels(0, 0, 0, width, height, 1, IL_RGB, IL_BYTE, raw_img);

ilSaveImage("Test.png");

ilDeleteImages(1, &ImgId);
}

free(raw_img);
}


The problem is that DevIL can't save the texture cause there is nothing in it (but raw_img is not null).
I assume that ilCopyPixels is not the right function to call but I've tried with ilSetPixels, ilSetDatas etc. and got the same result.

Am I missing something ?

Other question : how should I do to save 16 bits textures (GL_RGB5 format) since DevIL doesn't seems to manage 16 bits textures formats ? (DevIL format list)

As I said, I'm new to this problematic so I've maybe done a terrible mistake or misinterpret DevIL's behaviour, so be gentle with me please :).

Thanks for your time, greetings,
Andréas

Share this post


Link to post
Share on other sites
Advertisement
IIRC, to do this you need to use one of the methods that is not exposed as part of il.h (i.e. it's hiding away in devil_internal_exports.h). I *think* it's something along the lines of a call to ilResizeImage before copying in the pixel data (which will fail because no memory has yet been allocated for it).

Share this post


Link to post
Share on other sites
Thank you Rob for your response,

So you mean that DevIL can't *normally* save a texture from a array of pixels ? Strange... but it explains why I can't find any information on internet about that...
I'll look at devil_internal_exports.h thank you.

Andréas

Share this post


Link to post
Share on other sites
YEEEES!!! I manage to save my texture :D

In fact, it was quite simple, I just have to call ilTexImage.
Here is where I found the solution.

And for the 16 bits issue ? OpenGL automatically convert the texture in RGB 32bits for me, sweet :).

Bye,
Andréas

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!