QGLWidget incorrectly scales image in ortho mode



  • Hi,

    I'm trying to render a 2D image in class inherited from QGLWidget.
    The following code is used to setup matrices before rendering a texture
    glViewport( 0, 0, width (), height () );

    glMatrixMode   ( GL_PROJECTION );
    glPushMatrix   ();   
    glLoadIdentity ();   
    gluOrtho2D     ( 0, width(), 0, height() );
    glMatrixMode   ( GL_MODELVIEW );
    glPushMatrix   ();                             
    glLoadIdentity ();                             
    

    After this the quad with 256*256 pixels texture is rendered by the following code

    glBegin ( GL_QUADS );
    float sz = 256;
    glTexCoord2f(0,0);
    glVertex2f(x,y);
    glTexCoord2f(1,0);
    glVertex2f(x+sz,y);
    glTexCoord2f(1, 1);
    glVertex2f(x+sz,y+sz);
    glTexCoord2f(0, 1);
    glVertex2f(x,y+sz);
    glEnd ();

    This should produce a rect 256*256 pixels with the texture.
    However the texture is distorted (look at characted in the last line), but the rectangle size is correct,
    How I can cope with it ?

    Thanks,
    Alexey
    Distrorted image
    !http://steps3d.narod.ru/shot-distorted.png(distorted image)!

    Original texture
    !http://steps3d.narod.ru/font.png(original texture)!



  • Hey there,

    I think you need to use shaders and anti-aliasing to avoid such distortion. Such simple code doesn't produce clear objects. Notice that in the original texture you have a very obvious gradient in the colours. If you wan't to be sure that this is the cause of the problem, resize your window so that you could make it fill the screen and use more than 1000x800 pixels. If you find this problem only on the edges of the objects, then you need to use, as I said, some filtering for the scene.

    I think you gotta have a good OpenGL course to get over this and understand how to deal with 3D objects being sampled. Many courses are available online.

    Regards.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.