PDA

View Full Version : 'SOIL_load_image()' returns null.



bNoCoad
03-21-2015, 05:58 PM
Hello, I followed tutorial and have been trying to load texture into OpenGL since yesterday but 'SOIL_load_image' seems always to return null.



GLuint texture;
glGenTextures(1, &texture);

glBindTexture(GL_TEXTURE_2D,texture);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

int T_WIDTH, T_HEIGHT;
unsigned char* image = SOIL_load_image("sprite.bmp",&T_WIDTH,&T_HEIGHT,0,SOIL_LOAD_RGB);

if (!image) {
std::cout << "Failed to load texture: " << sizeof(image) << std::endl;
}

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, T_WIDTH, T_HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
glGenerateMipmap(GL_TEXTURE_2D);

SOIL_free_image_data(image);
glBindTexture(GL_TEXTURE_2D,0);


I get "Failed to load texture: 4" in console. I do not understand.

I try many file types. I search everywhere on internet, and I can not find an answer.

bNoCoad
03-24-2015, 01:29 PM
So no one knows? Is it because I use Visual Studio 2010? Is it because I had to remove the 64x configurations from soil.vcproj before compiling SOIL.lib? What have I done differently than what was taught to me in the tutorial?

carsten neumann
03-24-2015, 01:59 PM
It probably does not find your texture file. The file is most likely being looked for in the working directory (aka current directory) when your program executes - it is not necessarily the same directory your executable is in. In Visual Studio you can see/change the working directory that is used in the Project Properties dialog under General/Debugging.

PS: Not really an OpenGL question, so a general programming forum may be a better option and give you an answer quicker.

bNoCoad
03-24-2015, 04:27 PM
I checked the working directory and it's set to project folder like it should, but I tried setting it to the folder where my textures were anyways and it didn't fix it.

bNoCoad
03-28-2015, 04:22 PM
So I guess it's just me then???

I guess I just somehow always manage to cause something to break despite it working perfectly fine for others???

I've been looking back and forth between my code and the tutorial writer's code, why doesn't this work?

What possible reason could there be for this to not work? I have everything set exactly like he does.

bNoCoad
03-28-2015, 05:41 PM
Alright, it turns out it will load the texture if I launch the .exe within the debug folder directly instead of from Visual Studio. Why? I don't know.

Now my program just shows white then crashes if I set the fragment shader to use the texture.

EDIT: Hoorah I finally fixed it

The last step was to change the first number from this



glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)(2* sizeof(GLfloat)));

to this


glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)(2* sizeof(GLfloat)));