OpenGL Texture loading using Devil

Hello,

I am using QT eclipse opengl in my project, I am using DevIl libraries(IL, ILU, ILUT) for Image generation and Loading purpose.
Problem here is, it says “ilutGLLoadImage” cannot be resolved. Which i need for loading an image from the specified path.
Could anyone kindly tell me how to use this with QT? Any alternate suggestions are most welcome!

Thanks!

Are you sure your linker is setup correctly? Are you really linking against ILUT? IIRC, DevIL provides seperate libraries for each package, IL, ILU and ILUT. Make sure you’re linking your program against the right libs.

For Qt 4.7 check out the following API reference.

http://doc.qt.nokia.com/latest/qglwidget.html

The calls bindTexture() are what you’re looking for. Be sure to store the handle of the texture object persistently, so you can delete it with deleteTexture() or glDeleteTextures().

Thanks for the Response!

Would bindTexture() of QGlwidget does the same thing as ilutGLLoadimage()?
If it is same I will try to use bindTexture() for loading all the png’s.

one more question:
When i am trying to give path to the Image like
img.load("./Car_New1.png"); it gives red unerline below the .png and it says The word PNG is not correctly spelled.
Any idea?
Sorry for asking basic questions, I am new to this environment.
Thanks!

QGLWidget::bindTexture does only bind a texture just like GL does it, plus, it seams, a previous texture generation (very strange to me).

See http://doc.qt.nokia.com/stable/qglcontext.html#bindTexture for more information about it. (note: google is your friend !).

For your second question, it looks like it should work. Ensure that you don’t use special characters (for example I once had an error for the character ‘-’ when copied from a browser, it was because the browser encoded this character as another one).

bindTexture() encapsulates the calls necessary to generate a tex object, upload data to vidmem and setting filtering modes. However, you’ll have to pass a QImage object into the function, which is very simple to do - for instance:



// assume your QGLWidget object is name glw
// and you store the tex object handle in
// GLuint tex_object

QImage img;

if(img.load("./Car_New1.png"))
  tex_object = glw.bindTexture(img);


This should take care of it. Note that in this case the default parameters for ‘target’ and ‘format’ are used in bindTexture(). If your texture does not have an alpha channel you’d have to call


  tex_object = glw.bindTexture(img, GL_TEXTURE_2D, GL_RGB);

See the API doc for further information.

ilutGLLoadImage() does the same only with less control over the resulting texture object.

Still, with both approaches you’ll be able to set everything afterwards using the GL handle returned by either function.

The red underline seems to be inserted by the spellchecker built into Eclipse. It has no meaning whatsoever.

Don’t sweat it. :slight_smile:

Thanks for the response!

Now, I have made changes to my code by adding the same. But, unfortunately it compiles well but Application doesn’t get activated, I mean, when i click on run button it says .exe encountered a problem!

What I am doing is, I am calling a function from GLWidget::initialize()
{
picData(“PIC Path”, struct PICdata)
}
And in that function I am doing the same as you said.
if(img.load(_sPath))
{
PICdata.iId = this->bindTexture(img, GL_TEXTURE_2D, GL_RGBA);
PICdata.iHeight = img.height();
PICdata.iWidth = img.width();
}
And after that I am calling another function from Initialize()
to bind the loaded texture and I am using glNewlist and glCallList commands for creating and drawing texture.

Could you please help me in this regards?
Would there be any possibility of some configuration issue?

Thanks in Advance!

What kind of problem?

To verify your code does was it’s supposed to do, put out the tex object handle to the console and make sure img.load() returns true (either by assertion, or by putting something out the console inside the if block, or by using a debugger.

Looks like its related to some other issue…because even after commenting out the texture mapping code it says the same thing “.exe has encountered an error”.
I dont know what is the issue, looks like some problem with memory or some DEP.

Do you have any idea?

Maybe memory corruption. Can’t tell with this little information. You should really run it through a debugger.

I got it! Its because some wrong code in resizeGl(); method.

Now I ran the Texture mapping code, I cannot see the Image being displayed. Please find the code below.

void GLWidget::initializeGL()
{

PicData( “./PICS/Car_New1.png” , Structure holding PIC id, Height and width );
//ANd.

iTexture = glGenLists( 10 );
bindingImage( 1 ,GLUINT );

}
void GLWidget::vStorePicData( QString _sPath , sPic_Data _sPic )
{
imgLoaded = img.load(_sPath);

if(true == imgLoaded)
{
	_sPic.iId = this->bindTexture(img, GL_TEXTURE_2D, GL_RGB);
	_sPic.iHeight = img.height();
	_sPic.iWidth  = img.width();
}

}

void GLWidget::bindingImage
(
int PIC_Index ,
GLuint PIC_ID
)
{

glNewList(PIC_Index, GL_COMPILE );

glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

glBindTexture(GL_TEXTURE_2D, PIC_ID );

glBegin(GL_QUADS);

glTexCoord2d(0.0,1.0);
glVertex3f( -150 , -150 , 0.0f);

glTexCoord2d(0.0,0.0);
glVertex3f( -150 , +150 , 0.0f);

glTexCoord2d(1.0,0.0);
glVertex3f( +150 , +150 , 0.0f);

glTexCoord2d(1.0,1.0);
glVertex3f( +150 , -150 , 0.0f);

glEnd();

glEndList();

}

So finally in PaintGL() i will call the function to draw texture.
void GLWidget::DrawImage
(
Positions pos,
Rotations Rot,
Color col,
int index
)
{
makeCurrent();

glPushMatrix( );

/*Translate, Rotate, Color the Position*/

glTranslated( pos.fX , pos.fY , pos.fZ );
glRotatef( rot.Angle , rot.fX, rot.fY, rot.fZ );
glColor4f( col.Red , col.Green , col.Blue , 1.0f );

// Call the required texture from the list
glCallList( index );
/drawTexture(rect, _iIndex, GL_TEXTURE_2D );/

/*Return the Screen back to normal scenario*/

glPopMatrix();

}

in glCalllist() I am sending the texture index that i have used for glnewList in bindingImage function.

Can you tell where this has gone wrong or do I need to adapt a new way to this problem?

Thanks in Advance!

Looks like problem lies in Image loading. Code written for Image is not picking the Image from the Path specified.
imgLoaded = img.load(_sPath); always returns false!
Path given is : ./PICS/Car_New1.png, Passed as a QString to PICData function.

Is there a other way to give Path info? I have a project inside Eclipse workspace and inside that i have folder called “PICS”, I am just giving that path to it.

Any Idea?

Thanks!

Generally the directory structure is regarding where the executable is launched from (it’s often its directory), not where your project root directory is.

Anyway, a forum about eclipse (and/or Qt) would be more suitable for such questions.

You can also check if you’re passing the correct path and filename with QFile. Also, you can simply check if the QString contains the correct path.



// check if path string is correct
std::cout << "Path: " << _sPath.toStdString() << std::endl;

// check existence of file
QFile img_file("./PICS/Car_New1.png");

// either handle a potential error
if(!img_file.exists())
  std::cout << img_file.fileName() << " does not exist!" << std::endl; 

// or consider the existence of the file mandatory and assert
assert(img_file.exists());


In the latter case the program will terminate with an error message if you’re running a debug build.

Like arts already pointed out, the most common case is that the local folder is set to the path where the executable resides. However, it is possible to set a working directory which effectively make it the local folder.

Check this simple file system structure:


Folder "Workspace"
  |---- Folder PICS
          |---- Car_New1.png
  |---- Folder "ImageLoader"
          |---- File "ImgL.exe"

If your working directory is “ImageLoader”, for instance if you run the executable from the explorer or the command line directly (or with the standard settings made by Eclipse), then “…/PICS/Car_New1.png” is correct, not “./PICS/Car_New1.png” which would imply the the folder “PICS” exists inside “ImageLoader”.

Check this out: Path (computing) - Wikipedia