iDevGames Forums

Full Version: SOIL_load_OGL_texture - failing to load texture
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi Everyone.

In a previous post, AnotherJake helped me to fix an array of SOIL linker errors and warnings that I was getting (thanks again!!). Although I am no longer getting any errors or warnings, I've been unable to successfully load a texture.

I'm using code that AnotherJake provided in a separate thread:

Code:
#include <stdlib.h>
#include <stdio.h>
#include <GLUT/glut.h>
#include "SOIL.h"

GLuint    myTexture;

void display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    
    glLoadIdentity();
    glTranslatef(100.0f, 100.0f, 0.0f);
    
    glBindTexture(GL_TEXTURE_2D, myTexture);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex2f(0.0f, 0.0f);
    glTexCoord2f(1.0f, 0.0f);
    glVertex2f(256.0f, 0.0f);
    glTexCoord2f(1.0f, 1.0f);
    glVertex2f(256.0f, 256.0f);
    glTexCoord2f(0.0f, 1.0f);
    glVertex2f(0.0f, 256.0f);
    glEnd();
    
    glutSwapBuffers();
}

void reshape(int width, int height)
{
    glViewport(0, 0, width, height);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluOrtho2D(0, width, 0, height);
    glMatrixMode(GL_MODELVIEW);
}

void idle(void)
{
    glutPostRedisplay();
}

int main(int argc, char** argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE);
    glutInitWindowSize(640, 480);
    glutCreateWindow("SOIL test");
    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);
    
    myTexture = SOIL_load_OGL_texture("myImage.png", 0, 1, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y);
    if (!myTexture)
    {
        printf("soil failed to load texture\n");
        //exit(0);
    }
    glEnable(GL_TEXTURE_2D);
    
    glutMainLoop();
    return EXIT_SUCCESS;
}


Things I have tried:

1. Using the png's provided by the original SOIL zip obtained at lonesock.net
2. Use my own png's, and tga's
3. Place SOIL_load_OGL_texture into a separate function
4. recreate my lib with the included makefile
5. drag SOIL.h and libSOIL.a into my project manually
6. commenting out "//exit(0);" results in an untextured, white square upon running the program
7. placing the png's/tga's into the same directory as my header, lib, and cpp

But I continue to receive the same "failed to load texture" output as dictated by:

Code:
myTexture = SOIL_load_OGL_texture("myImage.png", 0, 1, SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_INVERT_Y);
    if (!myTexture)
    {
        printf("soil failed to load texture\n");
        //exit(0);
    }

Do I fail to load the texture only b/c the texture isn't valid? Would I also get similar results if my library was screwy? Or the header?

Just to reiterate:

1. I'm using the header provided in the original zip.
2. I created a mac-compatible lib using the makefile that came in the same zip.
3. I cleared out the obj directory every time I recreated my lib.

The code AnotherJake provided is from 2009 (yup - I'm still using/searching old threads Smile ). Is it possible there might be compatibility issues?

I'm using xcode4.0.2, and am running OSX 10.6.8.
GLUT | OpenGL | C++

I realize I've thrown a lot of questions out into the open, but mostly because I'm shooting blindly now trying to resolve this. At the root of my problem, "soil failed to load texture" - and I don't know why.

If anyone could nudge me in the right direction, or share your wisdom, I would really appreciate it. Thank you again.

Sincerely,
kropcke
It's probably the path. Giving just the filename "myImage.png" assumes that the file is in the working directory - is it. Do you know where the working directory for your application is? Try specifying the absolute path of the file and see if that works.
Code:
[[NSBundle mainBundle] pathForResource:ofType:inDirectory:]
Thank you so much for the replies backslash and OneSadCookie. Turns out that specifying the absolute path did the trick! Tested for both tga's and png's, and all's well Smile

Very, very happy for your replies, and I thank you again very much!

Have a great day! Smile

-kropcke
Reference URL's