SOIL_load_OGL_texture - failing to load texture

Apprentice
Posts: 6
Joined: 2012.08
Post: #1
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
Quote this message in a reply
Member
Posts: 245
Joined: 2005.11
Post: #2
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.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #3
Code:
[[NSBundle mainBundle] pathForResource:ofType:inDirectory:]
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2012.08
Post: #4
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Starting with SDL, can't load BMP :( ngoles 14 10,344 Jan 21, 2014 11:19 AM
Last Post: SethWillits
  Occlusion query code failing on ATI 9600 TomorrowPlusX 4 5,366 Mar 10, 2007 08:52 AM
Last Post: arekkusu
  Occlusion query failing for fogged occluders TomorrowPlusX 12 6,335 Jan 8, 2006 05:03 PM
Last Post: arekkusu
  How can I load a PNG without premultiplied alpha? Prime 6 7,060 Feb 15, 2005 08:52 PM
Last Post: arekkusu
  need help getting quicktime to load textures xDexx 8 4,371 May 7, 2003 03:57 PM
Last Post: xDexx