Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Problem with texturing - textures are mirrored

  1. #1

    Problem with texturing - textures are mirrored

    :arrow:System: Windows Vista, Pentium D 805 2,66 GHz, GeForce 7600 GS
    :arrow:Compiler/IDE: Delphi 2007 for Win32
    :arrow:API: OpenGL, Vampyre Imaging Library

    Hello men.

    I have a little problem with my texturing unit. I've noticed that the textures are mirrored. Is it a problem with the graphics library I use or maybe OpenGL can be at fault?

    Here is a screenshot (and for those who don't know, how it should look like, here is the correct version ) and below is the code I use for loading a texture. Please not that the texture file itself IS NOT mirrored.
    [pascal]
    procedure TTexture.LoadTexture(TheFile: TFileEntry);
    var
    ImagesArray: TDynImageDataArray;
    MainLevelIndex: Integer;
    ImgFormat: TImageFormat;
    begin
    if LoadMultiImageFromStream(TheFile.TheData, ImagesArray) and
    (Length(ImagesArray) > 0) then
    begin
    case FTexDetail of
    tdLow: MainLevelIndex := 2;
    tdMedium: MainLevelIndex := 1;
    tdHigh: MainLevelIndex := 0;
    end;
    case FTexComp of
    tcNone: ImgFormat := ifUnknown;
    tcDXT1: ImgFormat := ifDXT1;
    tcDXT3: ImgFormat := ifDXT3;
    tcDXT5: ImgFormat := ifDXT5;
    end;
    FTexHandle := CreateGLTextureFromMultiImage(ImagesArray, 0, 0, True,
    MainLevelIndex, ImgFormat);
    if (FTexHandle > 0) then
    begin
    Log.Log('Texture created successfully.', 'UBETexturing');
    FTexFile := TheFile.FileName;
    end else
    Log.Log('Unable to create the texture.', 'UBETexturing');
    end else
    Log.Log('Unable to load texture.', 'UBETexturing');

    TheFile.TheData.Seek(0, soFromBeginning);
    FreeImagesInArray(ImagesArray);
    end;
    [/pascal]

    Thank you in advance!

  2. #2

    Problem with texturing - textures are mirrored

    It depends on your model perhaps, more precisely texture coordinates. Is it generated sphere or ready planet from some modelling tool?

    If you want to test your texture with a simple quad, use glTexCoord2f(0,0) for upper left corner of texture and 1,1 for lower right.

  3. #3
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Problem with texturing - textures are mirrored

    I got the same problem with DirectX. The solution I use is kinda cappy, but works: I flip the image. Better would be to use 1 - TexCoord I think on only the X or Y when loading the model. Anyways if you find a solution tell me, I;m also interested!
    (My problem is only when I export from 3Ds Max to .ASE or .OBJ (didn't try other formats))
    NecroSOFT - End of line -

  4. #4

    Problem with texturing - textures are mirrored

    Using User137's code:
    [pascal]
    procedure RectT(x1, y1, x2, y2: Single);
    begin
    glBegin(GL_QUADS);
    glTexCoord2f(0.0, 0.0); glVertex2f(x1, y1);
    glTexCoord2f(0.0, 1.0); glVertex2f(x1, y2);
    glTexCoord2f(1.0, 1.0); glVertex2f(x2, y2);
    glTexCoord2f(1.0, 0.0); glVertex2f(x2, y1);
    glEnd();
    end;
    [/pascal]
    This is what I get:
    .

    So I think that the texture loading is wrong, then. Any ideas how to fix it? NecroDOME's solution is good, but well, it's pretty inconvenient to flip every image I want to use. :?

  5. #5
    Legendary Member NecroDOME's Avatar
    Join Date
    Mar 2004
    Location
    The Netherlands, Eindhoven
    Posts
    1,059

    Problem with texturing - textures are mirrored

    isn't that OpenGL's coordinat system is upside down compaired with DirectX.
    NecroSOFT - End of line -

  6. #6

    Problem with texturing - textures are mirrored

    This is what I've found after a lighting-fast googlin'
    OpenGL's coordinate system makes sense: bottom-up orientation, pixel and texel centers on half-integer coordinates, normalized device coordinates are -1 to 1 in all axes. Direct3D is a mess: device coordinates are bottom-up with centers on integers — which has the nice side effect of making the projection transform viewport-dependent — but functions that take integer screen-space rects are top-down, and textures are top-down with centers on half-integers. NDC X and Y are -1 to 1 but Z is 0 to 1. Argh!

  7. #7

    Problem with texturing - textures are mirrored

    Quote Originally Posted by Brainer
    Using User137's code:
    Sorry, i use RectT in ortho mode normally where Y axis is flipped. It doesn't matter with textures that are sideless though.

    This code makes it correctly on me:
    [pascal] glLoadIdentity;
    glDisable(GL_CULL_FACE);
    glTranslatef(0,0,-3);
    tex.SetTex(1);
    RectT(-1,1,1,-1);
    nxFlip;[/pascal]

  8. #8

    Problem with texturing - textures are mirrored

    Yip, that solves the problem and it seems that my sphere's coordinates are wrong. Can you please take a look at the code and tell me what's wrong?
    [pascal]
    procedure TSphere.DoRender;
    var
    I, J: Integer;
    drho, dtheta, ds, dt, S, T, rho, srho, crho, srhodrho, crhodrho, theta,
    stheta, ctheta, X, Y, Z: Single;
    begin
    drho := PI / FStacks;
    dtheta := 2.0 * PI / FSlices;
    ds := 1.0 / FSlices;
    dt := 1.0 / FStacks;
    T := 1.0;
    S := 0.0;

    for I := 0 to FStacks -1 do
    begin
    rho := I * drho;
    srho := Sin(rho);
    crho := Cos(rho);
    srhodrho := Sin(rho + drho);
    crhodrho := Cos(rho + drho);

    glBegin(GL_TRIANGLE_STRIP);
    S := 0.0;
    for J := 0 to FSlices do
    begin
    if (J = FSlices) then
    theta := 0.0
    else
    theta := J * dtheta;
    stheta := -Sin(theta);
    ctheta := Cos(theta);

    X := stheta * srho;
    Y := ctheta * srho;
    Z := crho;

    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, S, T);
    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, S, T);
    glMultiTexCoord2fARB(GL_TEXTURE2_ARB, S, T);
    glMultiTexCoord2fARB(GL_TEXTURE3_ARB, S, T);
    glNormal3f(X, Y, Z);
    glVertex3f(X * 1.0, Y * 1.0, Z * 1.0);

    X := stheta * srhodrho;
    Y := ctheta * srhodrho;
    Z := crhodrho;

    glMultiTexCoord2fARB(GL_TEXTURE0_ARB, S, T - dt);
    glMultiTexCoord2fARB(GL_TEXTURE1_ARB, S, T - dt);
    glMultiTexCoord2fARB(GL_TEXTURE2_ARB, S, T - dt);
    glMultiTexCoord2fARB(GL_TEXTURE3_ARB, S, T - dt);
    S := S + ds;
    glNormal3f(X, Y, Z);
    glVertex3f(X * 1.0, Y * 1.0, Z * 1.0);
    end;
    glEnd();

    T := T - dt;
    end;
    end;
    [/pascal]
    Thanks in advance!

  9. #9

    Problem with texturing - textures are mirrored

    If all you need to do is flip texture X coordinates, set S := 1; instead of 0 and replace S := S + ds; with S := S - ds;

  10. #10

    Problem with texturing - textures are mirrored

    You're my hero, User137!
    @NecroDOME: How about tryin' to do the same as User137 suggested me to do? Try flipping the X coordinate and it should work for you as well.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

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