Skip to main content
GameDev.net gamedev.net
🔒 Locked

OpenGL Texture Loading Function

Started by X Abstract X Sep 7, 2008 at 5:55 PM 0 replies 650+ views
Original Post
X Abstract X
X Abstract X
Hi I'm trying to apply a texture to my isometric tiles but they are just remaining white therefore I think there might be a problem with my texture loading function even though it doesen't generate any errors. Here's my code. Also, I've applied textures to simple polygons before, just without this texture loading function which leads me to believe it's my function causing the problem.

const int NUM_TEXTURES = 1;
GLuint texture[NUM_TEXTURES];

SDL_Surface *load_image(std::string filename)
{
    SDL_Surface* loadedImage = NULL;
    loadedImage = IMG_Load(filename.c_str());
    return loadedImage;
}

void create_textures()
{
    SDL_Surface *tempBMP = NULL;
    glGenTextures(NUM_TEXTURES, &texture[0]);

    for (int i = 0; i < NUM_TEXTURES; i++)
    {
        tempBMP = load_image("texture1.bmp");

        glBindTexture(GL_TEXTURE_2D, texture);

        glTexImage2D(GL_TEXTURE_2D, 0, 3, tempBMP->w, tempBMP->h,
            0, GL_BGR, GL_UNSIGNED_BYTE, tempBMP->pixels);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   
        SDL_FreeSurface(tempBMP);
    }
}

All help/advice appreciated.
Jouei
Jouei
Well only thing i can see so far that you may want to adjust is your glGenTextures() call for the second param you pass in you array but only a single portion of it pass in the whole array as long as you tell it how much room is in the array it should work fine.

You may want to debug your for loop to check for bad pointers for your array. Besides those two things it seem ok to me i don't normaly use SDL so i can't tell you if its an sdl specific issue but just check your for loop and step through the lines of code one by one.

Regards Jouei.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.