Skip to main content
gamedev.net
🔒 Locked

DevIL

Started by JasonL220 Dec 8, 2005 at 4:08 PM 0 replies 400+ views
Original Post
JasonL220
JasonL220
I have a .jpg image that i want to load as a ilimage and convert to a opengl texture, keeping the ilimage. But i got confused with all the imagname generation. could some show me how do this?
b2b3
b2b3
I use DevIL to load images and I use code like this:
int AddMaterial(char *file, GLenum minf, GLenum magf){    ILuint img;    ILenum err;    GLuint tex_id = 0;    // Here we create new il image which will hold data    ilGenImages(1, &img);    err = ilGetError();    if (err != IL_NO_ERROR)    {        log.Write("\n! : MaterialManager : error creating texture (ilGenImages).\n");        return 0;    }    // Set newly generated image as current    ilBindImage(img);current.    err = ilGetError();    if (err != IL_NO_ERROR)    {        log.Write("\n! : MaterialManager : error creating image (ilBindImage).\n");        return 0;    }    // Load file    ilLoadImage(file);    err = ilGetError();    if (err != IL_NO_ERROR)    {        log.Write("\n! : MaterialManager : error reading image file (ilLoadImage).\n");        return 0;    }    if ((minf == GL_LINEAR_MIPMAP_LINEAR) || (minf == GL_NEAREST_MIPMAP_NEAREST) ||        (minf == GL_LINEAR_MIPMAP_NEAREST) || (minf == GL_NEAREST_MIPMAP_LINEAR))    {        // generate OpenGL texture and all mipmap levels        tex_id = ilutGLBindMipmaps();mipmaps.    }    else    {        // Generate OpenGL texture        tex_id = ilutGLBindTexImage();    }    // We do not need image any more (it is now stored in GL), so delete it    ilDeleteImages(1, &img);    return tex_id;}

This function should load any file supported by DevIL and convert it to OpenGL texture. Parameters minf and magf can be used to set minification and magnification filters for given texture. For GL_*_MIPMAP_* magnification filters all mipmap levels are automatically generated. Function returns OpenGL texture name which you can bind when rendering.
Please note that this is not copy&paste directly from my source files (I have slightly more complicated version), so it may not compile as it is [smile].
HTH

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.