Results 1 to 3 of 3

Thread: Trouble reloading textures in linux

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    2

    Trouble reloading textures in linux

    Hey guys.. I'm having a little trouble doing some texture stuff and was wondering if you'd help me out.

    I want to add a menu entry for toggling MIP MAPS. What I wrote works fine in windows, but when I try it in linux all my textures turn white. I am using GLUT.

    Code :
    BOOL initTextures(GLuint texs[])
    {
       RGBIMG image; /* temporary tex container */
     
       glGenTextures(TEX_NUMBER, texs);/* initialize texture array */
     
       if(!loadImage("floor.raw", 128, 128, &image))/* load ground tex */
       {
          fprintf(stderr, "Error opening file 'floor.raw'\n");
          return FALSE;
       }
       glBindTexture(GL_TEXTURE_2D, texs[FLOOR]);/* bind tex */
       parameterizeTexture(&image); /* set tex drawing parameters */
     
       free(image.data); /* no longer need image, so free */
       return TRUE;      /* SUCCESS */
     
    } /* end initTextures() */
     
    void reloadTextures(GLuint texs[])
    {
       glDeleteTextures(TEX_NUMBER, texs);
       initTextures(texs);
     
    } /* end reloadTextures() */
     
    /* the following parameters are common to all textures */
    void parameterizeTexture(const RGBIMG *i)
    {
       /* this function does not bind textures, binding must be done before
          calling this function */
       glPixelStorei(GL_UNPACK_ALIGNMENT, 1);/* texs are single byte aligned */
     
       /* now we generate the mipmaps for the textures.  this makes everything
          look better (in windows) */
       gluBuild2DMipmaps(GL_TEXTURE_2D, 3, i->width, i->height, GL_RGB,
                         GL_UNSIGNED_BYTE, i->data);
     
       if(useMipMaps)
       {
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
                          GL_LINEAR_MIPMAP_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
                          GL_LINEAR_MIPMAP_LINEAR);
       }
       else /* useMipMaps == FALSE */
       {
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
          glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
       }
     
       /* the following line takes the byte image of our texture, stored in
          i->data and copies it to video memory so we can use it */
       glTexImage2D(GL_TEXTURE_2D, 0, 3, i->width, i->height, 0,
                    GL_RGB, GL_UNSIGNED_BYTE, i->data);
     
    } /* end parameterizeTextures() */
    What happens is when I hit the menu it flips the useMipMaps bit (either true/false), then calls reloadTextures() which deletes any resident textures and reloads them with mip mapping either enabled or disabled.

    What's getting me is that it works fine in windows, but not in linux. The loadImage() functions works fine, that just loads a RAW image into memory.

    Does anyone have any idea why this won't work? If you need more code I'll supply.

    Thanks for any help guys!
    Greg

  2. #2
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    2

    Re: Trouble reloading textures in linux

    Sorry guys.. I figured it out.. I was calling glGenTextures() over and over when I should have only called it once.

    Funny that it worked in windows, though.

  3. #3
    Senior Member Regular Contributor
    Join Date
    Apr 2001
    Location
    Greece
    Posts
    477

    Re: Trouble reloading textures in linux

    Also bear in mind that Build2DMipmaps builds and uploads the mipmaps(including the full texture) so you should better do something like:
    Code :
    if(usemipmaps){
      set texparams;
      build2dmipmaps;
    }else{
      set texparams;
      loadteximage2d;
    }

Similar Threads

  1. Trouble with loading textures.
    By geomazzix in forum OpenGL: Basic Coding
    Replies: 20
    Last Post: 12-15-2017, 01:19 AM
  2. Trouble with VAO's in linux
    By HMPARTICLE in forum OpenGL: Linux
    Replies: 5
    Last Post: 09-13-2017, 04:49 AM
  3. reloading animations
    By enjoycrf in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-31-2011, 01:28 PM
  4. Having trouble with textures in HUD
    By MrUNOwen in forum OpenGL: Basic Coding
    Replies: 16
    Last Post: 01-24-2011, 12:18 AM
  5. Trouble with Textures and Materials
    By Erfdain in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-05-2005, 04:57 PM

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