Results 1 to 3 of 3

Thread: OpenGL question

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default OpenGL question

    Hi,

    I'm new to OpenGL.
    I have an image loaded from a JPEG file into a char array(8 bit depth).
    I'm using this pice of code to paint a texture on a rectangle just to show the image:

    Qt Code:
    1. glTexImage2D(GL_TEXTURE_2D,0,1,iWidth,iHeight,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,pcData);
    2. glBegin(GL_QUADS);
    3. //glTexCoord2f(0.0f, 1.0f);
    4. glTexCoord2f(0.0f, 0.0f);
    5. glVertex2f(0.0f, 0.0f);
    6.  
    7. //glTexCoord2f(1.0f, 1.0f);
    8. glTexCoord2f(1.0f, 0.0f);
    9. glVertex2f(float(width()), 0.0f);
    10.  
    11. //glTexCoord2f(1.0f, 0.0f);
    12. glTexCoord2f(1.0f, 1.0f);
    13. glVertex2f(float(width()), float(height()));
    14.  
    15. //glTexCoord2f(0.0f, 0.0f);
    16. glTexCoord2f(0.0f, 1.0f);
    17. glVertex2f(0.0f, float(height()));
    18. glEnd();
    19. glFlush();
    To copy to clipboard, switch view to plain text mode 

    If I use the uncommented "glTexCoord2f" functions, the image that I can see is inverted. I think that JPEG files store every line inverted(don't really know why but I think bmps also do this).
    If I use the commented "glTexCoord2f" functions, the image is well shown but really don't understand why because I don't understand how "glTexCoord2f" works.

    Can anyone tell me this simple question? Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    May 2007
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: OpenGL question

    You mean that the texture is mirrored? That is a well known issue, there are some possibilities to solve that problem:

    * Mirror the loaded image line by line
    * Use the texture matrix (Scale Y with -1.0 and translate by 1.0)
    * Use a vertex shader (same effect like the texture matrix)

    Many picture formats are encoded from top to bottom, in OpenGL it starts at the Coordinates 0;0 (bottom left)

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: OpenGL question

    Hi,

    I'm saying that using the "glTexCoord2d" with the same values of the "glVertex2f", the image is mirrored. Then I changed the "glTexCoord2d" to the other ones that are uncommented and it works ok, but I don't understand why because I'm new to OpenGl and don't understand how does it work.

    Thanks,
    Òscar Llarch i Galán

Similar Threads

  1. OpenGL and Qt Question
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 18th April 2009, 18:04
  2. openGL with QT
    By me_here_me in forum Qt Programming
    Replies: 4
    Last Post: 2nd July 2007, 01:19
  3. Qtopia Core & OpenGL ES?
    By zelko in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 28th May 2007, 07:21
  4. OpenGL ES, Qt/11 - Qtopia Core?
    By zelko in forum Qt Programming
    Replies: 0
    Last Post: 3rd May 2007, 10:56
  5. Qt's optimized OpenGL context switching
    By sverhoff in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 16:40

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
  •  
Qt is a trademark of The Qt Company.