Results 1 to 9 of 9

Thread: Misaligned Targa

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    2

    Misaligned Targa

    Hello,
    I followed the NeHe tutorial here: http://nehe.gamedev.net/data/lessons....asp?lesson=24

    I can load Targas and use them as textures but I've encountered a problem and I don't know how to solve it.

    The two images are using the same drawing code. The only difference is that the targa file in the first image was saved at 32 BPP and the targa in the second image was saved at 24 BPP.
    There is no transparency in the image.

    32 BPP:


    24 BPP:


    As you can see, the 24BPP file draws misaligned. The only change is a resave of the image at a different BPP.

    Here is the code I'm using to draw:
    glPushAttrib(GL_ALL_ATTRIB_BITS);

    glLoadIdentity();

    glColor4f(1.0f, 1.0f, 1.0f, mTransparency);

    glBindTexture(GL_TEXTURE_2D, mTextureID[0]);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    glEnable(GL_BLEND);
    glEnable(GL_TEXTURE_2D); glEnable(GL_CULL_FACE);

    if (mRotation){
    glTranslatef(x, y + height, 0); // Move to bottom left of image
    glRotatef(mRotation, 0, 0, 1);
    glTranslatef(-x, -(y + height), 0.0f); // Reverse move
    }

    glTranslatef(x, y, 0);

    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f);
    glVertex2d(0, height + 1); // Bottom Left Of The Texture and Quad

    glTexCoord2f(1.0f, 0.0f);
    glVertex2d(width + 1, height + 1); // Bottom Right Of The Texture and Quad

    glTexCoord2f(1.0f, 1.0f);
    glVertex2d(width + 1, 0); // Top Right Of The Texture and Quad

    glTexCoord2f(0.0f, 1.0f);
    glVertex2d(0, 0); // Top Left Of The Texture and
    glEnd();

    glPopAttrib();

    Can anyone tell me why this occurs?

  2. #2
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Misaligned Targa

    The problem will probably be your texture loading code.

  3. #3
    V-man
    Guest

    Re: Misaligned Targa


  4. #4
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Misaligned Targa

    Look at the glPixelStore function.
    Use glPixelStore(GL_UNPACK_ALIGNMENT, 1) before allowing opengl texture data with glTexImage2D if there is no row alignement in your texture data.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Feb 2006
    Location
    Sweden
    Posts
    744

    Re: Misaligned Targa

    It would be helpful if you posted some actually relevant code, you should also double check your code as a single typo could cause this, though i do not know where exactly.

  6. #6
    Junior Member Newbie
    Join Date
    Dec 2008
    Posts
    2

    Re: Misaligned Targa

    Tell me which code sections you consider relevant and I'd be happy to post them.

  7. #7
    Member Contributor IneQuation.pl's Avatar
    Join Date
    Aug 2008
    Location
    Gliwice, Poland
    Posts
    69

    Re: Misaligned Targa

    The Targa loader.

  8. #8
    Senior Member Frequent Contributor _NK47's Avatar
    Join Date
    Mar 2008
    Posts
    574

    Re: Misaligned Targa

    the targa loader itself looks pretty simple.

    // read pixels
    imageSize = texture->width*texture->height*bytesPerPixel;
    texture->imageData=(GLubyte *)malloc(imageSize);
    fread(texture->imageData, 1, imageSize, file)!=imageSize);
    // swap channels
    for(GLuint i=0; i<int(imageSize); i+=bytesPerPixel)
    { temp=texture->imageData[i];
    texture->imageData[i] = texture->imageData[i + 2];
    texture->imageData[i + 2] = temp;
    }


    makes no difference in 24/32 bit. seems to be probably the OpenGL loading code. better to debug step by step and confirm that f.e. imageSize is your actuall image width * height * bpp/8 (calculator).

  9. #9
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: Misaligned Targa

    Sarashinai, have you tried what V-man and me pointed out about pixel unpack alignment? This is typically this kind of problem that happens with bad alignment.

    I have found the Kilgard's explanation which is very instructive. Look at paragraph 7 for pixel alignement.
    http://www.opengl.org/resources/feat...es/oglpitfall/

    IMO, the tga loader is good, I don't know anyone who has not copied and paste the tga loading source code or just translated in his favourite language. Why reinvent the wheel.

Similar Threads

  1. Misaligned/askew textures?
    By posixoptions in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-18-2010, 07:31 AM
  2. Misaligned Seymour Bones
    By grnbriar in forum COLLADA
    Replies: 0
    Last Post: 05-25-2007, 10:48 PM
  3. Targa File Textures Help Needed
    By Erfdain in forum OpenGL: Basic Coding
    Replies: 7
    Last Post: 05-09-2007, 12:51 PM
  4. targa image files
    By Nick's a Novice in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-08-2005, 06:17 AM
  5. Targa Playback
    By haw6434 in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 09-06-2000, 05:25 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