I am struggling with glOrtho() and glViewport(). My current understanding is that glOrtho() sets how openGL will look at the artifacts to be displayed and calculate the display to present a orthographic projection (I think I understand those last two words). When a diagonal arrow is drawn glOrtho can be used to show that arrow with compass angles of 45, 135, 225, or 315 degrees. glOrtho() uses real world coordinates.
glViewport() defines the monitor limits of what is to be displayed. It sets the lower left corner in pixels along with the width and height in pixels. The only call to glViewport() is in resizeGL() and the only arguments changed are size and height.
The previous post that I should use glOrtho() to scroll the data makes sense. But there is something wrong in my simple test.
The QGLWidget, within an encompassing Qt widget, is given a minimum size of width 400 height 100. Within initializeGL(), call glOrtho( -4.0, 4.0, -1.0, 1.0, -1,0, 1.0 ) (those arguments are all defined constants). That looks good. I can swap some signs and see the image flip about the expected axis.
In resizeGL( width, height ) there is a call to glViewport( 0, 0, width, height ). The QGLWidget is resized along with the encompassing widget. For this app I suspect the first two arguments or glViewport(), left and bottom, will never change from 0.
In paintGL() a polygon is drawn within the QGLWidget and appears as expected. It resizes as expected.
In expectation of possibly using glOrtho() within paintGL() the call is copied from initializeGL() into paintGL(), unchanged, all arguments are constants.
The polygon is then reduced to about 10% of the original width but the height remains the same. On resize it is further reduced to a small line segment.
I cannot copy paste from my work computer, please try to accommodate typos, but the paintGL() looks mostly like this.
void C_GL_Strip_Chart:: paintGL()
{
// Used constants for glOrtho because nothing is changing, a static display.
/* glOrtho( LEFT_CLIP, RIGHT_CLIP, BOTTOM_CLIP, TOP_CLIP, NEAR_CLIP, BACK_CLIP ); */
GlClear( GL_COLOR_BUFFER_BIT );
GlColor3f( 1.0, 0.0, 0.0 );
glBegin( GL_POLYGON )
glVertex2f( -0.5, -0.5 );
glVertex2f( -0.5, 0.5 );
glVertex2f( 0.5, 0.5 );
glVertex2f( 0.5, -0.5 ); // rectangle,
glVertex2f( -0.4, -0.9 ); // with a little bump to show orientation
glEnd();
};
This indicates that glOrtho() does not belong in paintGL. But from other things I have seen and read, that appears to be a contradiction. I resolve that apparent contradiction by presuming there is something I don’t understand here. The bad behavior of goOrtho() might be a red herring, or something I have omitted.
As I wrote all this out I ran a few tests and confirmed the above concepts. Indeed, I learned and verified several things via the process of trying to pose a cogent question. There must be something wrong in how I have used glOrtho() within paintGL(). Or maybe somewhere else.