5

I've got a path to my file defined this way:

const char* GROUND_TEXTURE_FILE = "objects/textures/grass.jpg";

And here is the function, which I use to load image:

bool loadTexImage2D(const string &fileName, GLenum target) {
    ...
    // this will load image data to the currently bound image
    // at first, we must convert fileName, for ascii, this method is fine?
    wstring file(fileName.begin(), fileName.end());

    if(ilLoadImage(file.c_str()) == IL_FALSE) { //here the program falls

What's wrong in my code? Why the program falls when ilLoadImage is called? I think, that file.c_str() should work fine as a wchar_t * type or not? Thanks for answer :)

ketysek
  • 1,159
  • 1
  • 16
  • 46
  • I'm curious. Why use wchar at all? What happen if you load using fileName? – Andreas May 06 '16 at 14:36
  • because const char * is incompatible with const wchar_t * ... but I've figured it out ... the problem is not here, I did not initialize DevIl library using `ilInit();` ... my mistake – ketysek May 06 '16 at 14:44

1 Answers1

1

As the author's said, you can do pretty anything without initializing the lib :D

#include <iostream>
#include <IL/il.h>

int main ()
{
    std::string filename = "objects/textures/grass.jpg";

    ilInit();

    if (!ilLoadImage(filename.c_str())) {
        std::cout << ilGetError() << std::endl;
        return 1;
    }

    std::cout << ilGetInteger(IL_IMAGE_WIDTH) << std::endl;
    std::cout << ilGetInteger(IL_IMAGE_HEIGHT) << std::endl;

    return 0;
}

build:

g++ -Wall -pedantic --std=c++11 -g -o app main.cpp -lIL
Hugo do Carmo
  • 179
  • 1
  • 10