Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: Buffer selection questions

  1. #1
    Junior Member Newbie
    Join Date
    Dec 2018
    Posts
    19

    Buffer selection questions

    Centos Linux, OpenGL within a Qt environment. Novice. Fundamentally no knowledge of linear algebra and matrices. This is a 2D application. It will not use any 3D, perspective changes, rotations, color blends, etc.
    So far I have developed a basic GL window working within a Qt environment. It draws a polygon, colors it, and moves it by changing the glOrtho() arguments. For the next step I return to the book:
    OpenGL Programming Guide
    Addison Wesley
    Jackei Neider, Tom Davis, Mason Woo
    In listing 1.3 it has
    Code :
    glPushMatrix();
    Now for my ignorance: Push what matrix? Push it where? And mostly: Why?
    Code :
    glXSwapBuffers( auxDisplay(), auxXWindow() );
    The author explains that GL does not have a swap buffers command and that is for X window system. I am aware that two buffers will be needed: One for display and one for writing. What I cannot detect is: What buffers are to be selected? Why those buffers?
    I have searched, without success, for tutorials that explain open GL for a novice and for 2D users. If you know of such please advise.

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,596
    Quote Originally Posted by mbkelly View Post
    CIn listing 1.3 it has ... glPushMatrix();

    Now for my ignorance: Push what matrix? Push it where? And mostly: Why?
    Read: Chapter 3: Viewing (OpenGL Programming Guide, ver 1.1) <--- This is from one of the oldest versions


    Code :
    glXSwapBuffers( auxDisplay(), auxXWindow() );
    The author explains that GL does not have a swap buffers command and that is for X window system. I am aware that two buffers will be needed: One for display and one for writing.

    What I cannot detect is: What buffers are to be selected? Why those buffers?
    If you create a double-buffered window, then associated with it are two buffers: front and back. Back is the one your application is rendering to. Front is the one that's being displayed.
    Last edited by Dark Photon; 01-11-2019 at 05:33 PM.

  3. #3
    Junior Member Newbie
    Join Date
    Dec 2018
    Posts
    19
    Hello Dark Photon,
    Thank your taking the time to post. Here is the fundamental problem. 3D graphics are beyond my knowledge level. Hopefully, 2D is not. My goal is a 2D display. I have the paperback book referenced in hand. Thank you for the link to the soft copy, it has already been helpful.
    In the referenced chapter 3 the example code contains:
    Code :
     glLoadIdentity ();  /* clear the matrix */

    The word “the” in the context of the comment implies that there is one specific matrix being addressed. Ok. Which matrix is that? The author presumes that the reader already knows. Just below in the text is:

    In this code example, before the viewing transformation can be specified, the current matrix is set to the identity matrix with glLoadIdentity().
    I searched this document, then searched chapters 2 and 1. This is the first use of the phrase: “the current matrix.” It is not defined. Exactly what is this current matrix? Is there a one and only current matrix? Or is the current matrix selected from a set of matrices? I suspect the latter. The author presumes the reader already knows.

    To become what I phrase as: fluent in open GL, would require a year or more of studying linear algebra and matrix mathematics. I have no desire to do that. I only need to create a simple 2D strip chart.

    While I have two urgent questions experience indicates I should concentrate on one at a time. I presume that you, dear reader, are familiar with a strip chart. The X axis represents time, always moving, the Y axis represents the value of a selected measurement. Every measurement to be displayed falls naturally into the X/Y coordinate system as time/value. To my knowledge, so far, I see two fundamental methods of presenting the always scrolling X axis.

    The first method is to use the current time to develop the two X values for function glOrtho(). The first two arguments of that function are left_clip and right_clip values. If I keep those two arguments, say, 10 seconds apart, and increment them, say, 10 times a second by having a 100 millisecond timer, the X values will always represent the latest 10 seconds of time. That means that glOrtho() is called 10 times a second with new values to the left and right clip values on each call. That is expected to result in the plotted Y values marching across the monitor.

    The second method is to set glOrtho() one time. The time/value pairs must then have their X coordinates shifted within each of the 10 updates a second to cause the value points to march across the screen.

    As I write this I recognize a third possible method, about which I know practically nothing. Use a matrix transformation. That can shift a display matrix along any or multiple axes. I am only concerned with shifting the X axis. From my readings I conclude that Open GL can assign this task to the video display device which can do it far faster than the general purpose CPU. Beyond that, I haven’t a clue.

    From my very limited perspective, shifting the arguments for glOrtho makes the most sense. It always keeps the right time associated with the value of each measurement. I can then use gl_Begin( GL_LINE_STRIP ) and just plot all the points within the desired time frame.

    Is this a satisfactory method, a great method, or maybe the worst?
    Last edited by mbkelly; 01-14-2019 at 11:01 AM. Reason: clarify & typos

  4. #4
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,067
    Quote Originally Posted by mbkelly View Post
    In the referenced chapter 3 the example code contains:
    Code :
     glLoadIdentity ();  /* clear the matrix */

    The word “the” in the context of the comment implies that there is one specific matrix being addressed. Ok. Which matrix is that?
    The current matrix, as set by glMatrixMode(). The model-view matrix is initially the current matrix.

    The current matrix is the one affected by all of the matrix operations: glOrtho, glTranslate, etc.

    Quote Originally Posted by mbkelly View Post
    To become what I phrase as: fluent in open GL, would require a year or more of studying linear algebra and matrix mathematics.
    If you're familiar with algebra, the amount of time required should be somewhere between a day and a week of full-time study, depending upon how quickly you grasp it. Even linear algebra as taught in a mathematics degree doesn't take a year, and that covers vastly more ground. OpenGL only requires the most basic topics.

    Quote Originally Posted by mbkelly View Post
    The first method is to use the current time to develop the two X values for function glOrtho(). The first two arguments of that function are left_clip and right_clip values. If I keep those two arguments, say, 10 seconds apart, and increment them, say, 10 times a second by having a 100 millisecond timer, the X values will always represent the latest 10 seconds of time. That means that glOrtho() is called 10 times a second with new values to the left and right clip values on each call. That is expected to result in the plotted Y values marching across the monitor.

    The second method is to set glOrtho() one time. The time/value pairs must then have their X coordinates shifted within each of the 10 updates a second to cause the value points to march across the screen.
    The first method is the logical one, as you only need to update a small amount of data each frame (one matrix), rather than needing to update the X coordinate of every point.

    Quote Originally Posted by mbkelly View Post
    As I write this I recognize a third possible method, about which I know practically nothing. Use a matrix transformation. That can shift a display matrix along any or multiple axes. I am only concerned with shifting the X axis. From my readings I conclude that Open GL can assign this task to the video display device which can do it far faster than the general purpose CPU. Beyond that, I haven’t a clue.
    That's exactly what glOrtho() does. It modifies one of the matrices by which all vertex positions are transformed. Conventionally, glOrtho() is used on the projection matrix, but in the 2D case it could just as well be applied to the model-view matrix. Vertex positions are transformed by both, and only the end result matters in terms of the screen coordinates. The distinction is only relevant if you use more advanced features such as lighting, which aren't relevant to this application.

    Like most of the OpenGL matrix functions, glOrtho() concatenates (multiplies) a matrix with the current matrix, rather than replacing it. To replace a matrix, you first call glLoadIdentity() to reset the current matrix to an identity matrix (one which leaves the coordinates unchanged).

  5. #5
    Junior Member Newbie
    Join Date
    Dec 2018
    Posts
    19
    I think I understand what you have written. No questions about that right now.
    One new question. When I use glOrtho() to move the plotted points making a strip chart, is that a relatively expensive or cheap operation? Asked anaother way: Is it a CPU or GPU hog or is that a quick operation?

  6. #6
    Senior Member OpenGL Guru
    Join Date
    Jun 2013
    Posts
    3,067
    Quote Originally Posted by mbkelly View Post
    I think I understand what you have written. No questions about that right now.
    One new question. When I use glOrtho() to move the plotted points making a strip chart, is that a relatively expensive or cheap operation? Asked anaother way: Is it a CPU or GPU hog or is that a quick operation?
    Cheap.

    Generally speaking, the main issues for performance are operations which are performed many times per frame or those which can cause synchronisation (which is basically anything returning information from the GPU to the CPU or overwriting portions of buffers or textures with data from CPU memory).

    Beyond that: you don't really need to worry about performance. A 2D strip chart wouldn't have been a particularly demanding application on the earliest OpenGL-capable hardware, and modern video hardware is several orders of magnitude faster.

  7. #7
    Junior Member Newbie
    Join Date
    Dec 2018
    Posts
    19
    Cool. That was a big question for me.
    Thank you for your time and patience.

Posting Permissions

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