Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Tecture loading doesn't work ?

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012

    Tecture loading doesn't work ?

    Hello Every one,

    Am new to OpenGL and i need help in the following code,

    #include "SDL/SDL_opengl.h"

    unsigned int loadTexture(std::string filename){
    SDL_Surface* img=SDL_LoadBMP(filename.c_str());
    if(img==NULL)return 0;
    unsigned int id;
    glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,img->w, img->h,0,GL_RGB,GL_UNSIGNED_SHORT_5_6_5, img->pixels);
    return id;

    the problem is that this code used to once -_-, but now the image never gets loaded... Can anyone plz point out what i have done wrong?
    Last edited by _Steam; 07-06-2012 at 04:51 AM.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Debug into it, break at

    Code :
    SDL_Surface* img=SDL_LoadBMP(filename.c_str());

    check the filename, which you should pass as a const std::string& not by value, and see if it really contains what you're looking for. If not, check the filename argument at the place you invoke loadTexture() and see if you pass valid filenames in the first place. If all that's fine see the SDL API doc and check under which circumstances SDL_LoadBMP() can fail - I assume it fails if the file doesn't exist, can't be accessed or isn't an image encoded in a valid image format.

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2012
    Thanks Thokra, well the file is of valid format, it used to work once on my other laptop, this is weird but when i copied the project to my new laptop and included the necessary files it didn't work. I was thinking if you could share with me any other way of loading an image in opengl using sdl. thanks in advance for your help

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts