Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QGLWidget incorrectly scales image in ortho mode
steps3d last edited by
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;
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 ?
TheDestroyer last edited by
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.