Results 1 to 3 of 3

Thread: What wrong with my texture loading code?

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Lithuania
    Posts
    25

    What wrong with my texture loading code?

    What wrong with my texture loading code? Sometimes when i load with mipmaping disabled textures doesn't load (shapes binded with that texture apear white)
    =============================================
    AUX_RGBImageRec *LoadBMP(char *Filename)
    {
    if (!Filename) return NULL;

    FILE *File = NULL;

    File = fopen(Filename, "r");

    if (File)
    {
    fclose(File);
    return auxDIBImageLoad(Filename);
    }

    return NULL;
    }

    void Load(char *file2, bool mipmap)
    {
    AUX_RGBImageRec *TexImage ;

    memset(&TexImage, 0, sizeof (void *));

    char file[256];

    strcpy(file, "Textures\\");
    strcat(file, file2);

    TexImage = LoadBMP(file);

    if (!TexImage)
    {
    Log("ERROR: Cannot load texture: %s", file);

    if (TexImage)
    {
    if (TexImage->data)
    free(TexImage->data);
    free (TexImage);
    }

    return;
    }

    glGenTextures(1, &Tex);
    glBindTexture(GL_TEXTURE_2D, Tex);

    if (!mipmap)
    {
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

    glTexImage2D(GL_TEXTURE_2D, 0, 3, TexImage->sizeX, TexImage->sizeY, 0,GL_RGB, GL_UNSIGNED_BYTE, TexImage->data);
    }

    //jeigu reikia mipmapo
    if(mipmap)
    {
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TexImage->sizeX, TexImage->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TexImage->data);
    }

    if (TexImage)
    {
    if (TexImage->data)
    free(TexImage->data);
    free (TexImage);
    }

    Log("Texture %s loaded", file2);
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2001
    Location
    Princeton, NJ
    Posts
    380

    Re: What wrong with my texture loading code?

    remember that texture dimensions must be powers of 2

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2003
    Location
    Lithuania
    Posts
    25

    Re: What wrong with my texture loading code?

    Yes, i know that...

Similar Threads

  1. GLSL shader texture , what is wrong with my code
    By mythcat in forum OpenGL: GLSL
    Replies: 2
    Last Post: 08-22-2010, 11:38 AM
  2. TGA loading appear with wrong colour and flipped!
    By clocKwize in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 05-31-2010, 10:43 AM
  3. what is wrong with this code?
    By openman in forum OpenGL: Linux
    Replies: 1
    Last Post: 08-04-2008, 04:21 AM
  4. What wrong with this 24bit BMP loading code:
    By Jnz86 in forum OpenGL: Basic Coding
    Replies: 9
    Last Post: 06-16-2004, 02:06 PM
  5. What's wrong with this code?
    By Seamoon in forum OpenGL: Advanced Coding
    Replies: 8
    Last Post: 02-26-2003, 09:07 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