Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14

Thread: Request advice on strip chart concepts

  1. #11
    Junior Member Newbie
    Join Date
    Dec 2018
    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.

    Code :
    void C_GL_Strip_Chart:: paintGL()
    // Used constants for glOrtho because nothing is changing, a static display.
    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
    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.
    Last edited by mbkelly; 01-10-2019 at 12:12 PM. Reason: typo

  2. #12
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    You need to call glLoadIdentity() before glOrtho(). Otherwise, each glOrtho() transformation is combined with the previous glOrtho() transformations.

  3. #13
    Junior Member Newbie
    Join Date
    Dec 2018
    Adding glLoadIdentity() looks good. Meanwhile I added some functions, slots, and connected two pushbuttons to some functions as follows:

    Code :
    const GLdouble FUDGE_IT = 1.0;
    void C_GL_Strip_Chart::move_ortho_left()
    std::cout << “called move left \n”;
    ortho-left_clip -= FUDGE_IT;
    ortho-right_clip -= FUDGE_IT;
    glLoadIdentity( );
    glOrtho( ortho_left_clip, 
                 ortho_far_clip );
    Meaning the buttons were connected such that the shown function(s) gets called.

    There is a move_ortho_right that does +=. In paintGL() there is now a little while loop just before exiting that calls glGetError() and outputs any error messages. It outputs messages to show that the loop ran and has discovered N errors. None have been discovered.

    I expected that the changes to glOrtho() argument would cause the polygon to move within the QGLWidget display. I see no effect at all.
    Is there a method to fetch/get the ortho and view values to be sure they contain the values expected?

    Added a bit of code to get the clip plane values discovering that there are over 3000 of them.
    Code :
    for( i = 0; i <= 4; i ++ ) 
    glGetClipPlane( i, ortho_clip_plane );  // arg 2 is array of 4 GLdouble
    std::cout << “clip plane = “ << stuff to print each of four values << “\n”
    This runs right after one of the calls to glOrtho(…) where the arguments are changing. I looked at the first four of the the clip planes and none of the values get changed, nothing but zeroes. Is that indicating that my glOrtho(…) call is incorrect?
    Note that the first call to glOrtho() seems to have the expected effect and the arguments are not not all zeroes.

    Edit again: All the calls to glOrtho() have been prefixed and postfixed as follows:

    Code :
    glMatrixMode( GL_PROJECTION );
    glOrtho( six_arguments );
    glMatrixMode( GL_MODELVIEW );

    Those two calls before and two after produced no detectable effect.

    Bonus Question: Is there a book or tutorial written for people that only need 2D displays? My searches for that were unproductive.
    Last edited by mbkelly; 01-10-2019 at 05:25 PM. Reason: typo and more info

  4. #14
    Junior Member Newbie
    Join Date
    Dec 2018
    Just had a possible realization. From reading tutorials and forums I discovered the need to override method: paintGL().
    My OOP is not well developed but I suspect that the original paintGL() code within openGL itself still gets called. However, when I create another function that requires a repaint, calling paintGL() directly calls my local code but it does not invoke the original openGL method paintGL().

    Please help with the terminology. What is the code needed to invoke paintGL() at the openGL level?

    With that idea I found than I cannot call the openGL original paintGL() because it is protected. So, additional searches discovered that I should use update();

    and that gave me the moving ortho window that I want. On each interval of time I can set the window to show the desired time period, then plot the points using the received value along the Y axis and the recorded value along the X axis. There is more to it, but I now have the concept.

    EDIT 2:
    I work for the government and have discovered that some buttons in forums are not displayed. Is there a way to mark this thread as resolved. Or maybe change the title at the OP level to include the word Resolved.

    Thank you for the time you spent assisting me.
    Last edited by mbkelly; 01-11-2019 at 04:21 PM. Reason: new info, resolved this problem.

Posting Permissions

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