I'm making a program in Ubuntu with wxwidgets, the goal is to recognize faces but for now I just want to load an image into a frame. I load images by clicking on a load menu item which is linked to this function.
void Face_Catcher_Frame::on_load(wxCommandEvent &event)
{
wxFileDialog * openFileDialog = new wxFileDialog(this);
if (openFileDialog->ShowModal() == wxID_OK)
{
wxString file_name = openFileDialog->GetPath();
file_name = file_name.Mid(file_name.Find('/', true) + 1);
ILboolean success;
ilGenImages(1, &texid);
ilBindImage(texid);
printf("%ls\n", getWChars(string((const char*)file_name.mb_str(wxConvUTF8))).c_str());
//success = ilLoadImage(getWChars(string((const char*)file_name.mb_str(wxConvUTF8))).c_str());
success = ilLoadImage((const char*)file_name.mb_str(wxConvUTF8));
if(success)
{
success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
if (!success)
{
printf("Could not convert image.\n");
exit(1);
}
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
glViewport(0, 0, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT));
glGenTextures(1, &image);
glBindTexture(GL_TEXTURE_2D, image);
glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
}
else
{
printf("Could not load image.\n");
exit(1);
}
ilDeleteImages(1, &texid);
SetClientSize(ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT));
}
}
Everytime I try to load an image ilLoadImage fails. I'm able to run an example with no trouble
http://gpwiki.org/index.php/DevIL:Tutorials:Basics
But here it doesn't work even tough the path seems to be correct, I even shortened the path to just the image's file name and that didn't work either.
But what I'm really curious about is the fact that ilLoadImage seems to require an argument of type wchar_t*. It just seems weird and especially inconvenient on linux. Although when I looked at the documentation it said the function takes a char array, maybe that's because I got devil out of the ubuntu repository after I failed to compile the source, so my version is a little old.