Results 1 to 6 of 6

Thread: 'SOIL_load_image()' returns null.

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    6

    'SOIL_load_image()' returns null.

    Hello, I followed tutorial and have been trying to load texture into OpenGL since yesterday but 'SOIL_load_image' seems always to return null.

    Code :
    	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.

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    6
    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?

  3. #3
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896
    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.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    6
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    6

    Exclamation

    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.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2015
    Posts
    6
    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

    Code :
        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)(2* sizeof(GLfloat)));
    to this
    Code :
        glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), (GLvoid*)(2* sizeof(GLfloat)));

Similar Threads

  1. shrFindFilePath() returns null
    By piyush in forum OpenCL
    Replies: 0
    Last Post: 02-04-2014, 08:39 PM
  2. glfwOpenWindow returns null
    By compmaster in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 03-09-2013, 10:32 PM
  3. GL_RENDER returns null
    By Vincent22 in forum OpenGL: macOS
    Replies: 2
    Last Post: 04-24-2012, 01:32 PM
  4. help ** glGetString returns NULL
    By Super13 in forum OpenGL: Basic Coding
    Replies: 12
    Last Post: 12-08-2003, 01:06 PM
  5. wglCreateContext returns NULL
    By clunis_immensus in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 07-15-2002, 09:11 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean