Results 1 to 9 of 9

Thread: Qt and OpenGL

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face Qt and OpenGL

    I am working on an application that imbeds some OpenGL into Qt. I have a red 'L' drawing onto the screen using a GL_LINE_LOOP from (0,1) to (0,0) to (1,0). The 'L' always draws, but it always goes from the top-center of the screen to the middle of the screen to the right-middle of the screen. This never matters on what my glOrtho( ) is. It can be something like (-100, 100, -100, 100, 0, 0) or (-5, 5, -5, 5, 0, 0) or even (-10, -5, -10, -5, 0, 0). This last one should theoretically result in an empty black screen but it doesn't. I have no idea why this is doing this. Does Qt have its own glOrtho type function that I have not found for a QGLWidget? I have been using OpenGL for over a year now so I know how to handle simple things like this. But this is confusing me like crazy! Does anyone have any idea why this behaves like this? Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt and OpenGL

    Qt doeasn't introduce any own interpretation to OpenGL command -- it just calls them on an internal GL context which renders the display to the widget (or not :P). So the thing has to do something with plain OpenGL. Maybe that's because you use 2D coordinates? Or you change one of matrices and simply didn't notice that?

    Maybe you should try the same piece of code with glut and see if the effect persists?

  3. #3
    Join Date
    Apr 2006
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Qt and OpenGL

    I've been using QGLWidget in the past and it behaves essentially like any other toolkit such as the glut framework. Maybe we could see some code ?

    If this is not really an answer I may point you out to libqglviewer which is a wonderfull opengl library for QT.

    It provides a lot of functionnalities and gets rid of a lot of problems for you. I've been using it for a while in long term development and it is very useful.
    Last edited by jwintz; 12th June 2006 at 23:11.

  4. #4
    Join Date
    Mar 2006
    Posts
    172
    Thanks
    30
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and OpenGL

    Quote Originally Posted by ToddAtWSU
    I am working on an application that imbeds some OpenGL into Qt. I have a red 'L' drawing onto the screen using a GL_LINE_LOOP from (0,1) to (0,0) to (1,0). The 'L' always draws, but it always goes from the top-center of the screen to the middle of the screen to the right-middle of the screen. This never matters on what my glOrtho( ) is. It can be something like (-100, 100, -100, 100, 0, 0) or (-5, 5, -5, 5, 0, 0) or even (-10, -5, -10, -5, 0, 0). This last one should theoretically result in an empty black screen but it doesn't. I have no idea why this is doing this. Does Qt have its own glOrtho type function that I have not found for a QGLWidget? I have been using OpenGL for over a year now so I know how to handle simple things like this. But this is confusing me like crazy! Does anyone have any idea why this behaves like this? Thanks!

    A few points to ponder:

    1. You are using a Line_loop to draw an 'L'? This should give you a right angle triangle and not a plain 'L'

    2. Try using gluOrtho2d(-x,x,-y,y) and not just plain gluOrtho(). Set the coordinates to (0,100,0,100). This will draw your 'L' on the bottom left corner.

    3. Is this what you wanted?

    hope it helps

    Nupul

  5. #5
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Smile Re: Qt and OpenGL

    Yes I meant GL_LINE_STRIP and not LINE_LOOP. Been working on my previous OpenGL project way too long... I didn't think this would be a Qt problem but didn't know since stuff was behaving very funny. Someone on the OpenGL forums said my problem was I made the znear and zfar values the same and that they need to be different. So I will try this out. Thanks though for your help and I will check out that library you mentioned, jwintz. Thanks!

  6. #6
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face Re: Qt and OpenGL

    One other thing I am trying to do is draw a white box from the point a user clicks and drags until. I just trigger a bool to true when the user left clicks on the screen and set the bool to false when the user releases the left mouse button and while the button is held and the mouse is moved, I calculate the new position of the mouse. I want to draw a box from the initial click position to the current position. I know how to and successfully retrieve the screen coordinates. But how do I convert these to the grid coordinates? Especially if my grid goes from -x1 to +x2 and -y1 to +y2? I think this shouldn't be too bad if the grid lies entirely in the positive or negative planes, but when the grid overlaps, I have no idea how to approach this. Thanks for your help in trying to solve this problem!

  7. #7
    Join Date
    Apr 2006
    Posts
    29
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Qt and OpenGL

    I guess this is for selection purposes. Once again this is not really a Qt issue, but in the libqglviewer library you have selection tools provided which draw selection regions. See http://artis.imag.fr/~Gilles.Debunne...ltiSelect.html

    If it is not for selection purpose, the same library provides the following functions :

    - virtual void startScreenCoordinatesSystem (bool upward=false) const
    - virtual void stopScreenCoordinatesSystem () const

    See http://artis.imag.fr/~Gilles.Debunne...QGLViewer.html, section Display functions.

    Of course the corresponding OpenGL code can be found here. I can provide you some code but it would be easier to use this ...

  8. #8
    Join Date
    May 2006
    Location
    Bangalore
    Posts
    23
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Qt and OpenGL

    Quote Originally Posted by nupul
    Try using gluOrtho2d(-x,x,-y,y) and not just plain gluOrtho()
    Following is the relation between gluOrtho2d() and glOrtho().
    Qt Code:
    1. void GLAPIENTRY
    2. gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, GLdouble top)
    3. {
    4. glOrtho(left, right, bottom, top, -1, 1);
    5. }
    To copy to clipboard, switch view to plain text mode 
    For gluOrtho2D() is equivalent to calling glOrtho() with near = −1 and far = 1 .

    Quote Originally Posted by ToddAtWSU
    I know how to and successfully retrieve the screen coordinates. But how do I convert these to the grid coordinates? Especially if my grid goes from -x1 to +x2 and -y1 to +y2? I think this shouldn't be too bad if the grid lies entirely in the positive or negative planes, but when the grid overlaps, I have no idea how to approach this.
    What do you mean by Grid coordinates?
    In case you are looking for a conversion from window coordinates to object coordinates, you can use gluUnproject().
    You can get to know about gluUnproject() at gluUnproject man page and Nehe gluUnProject Article

    If you aren't using libQGLViewer, then you are looking at wrong place. You should rather refer to Nehe's GameDev Forum for a OpenGL related help.

    -Shobhit

  9. The following user says thank you to bits for this useful post:

    Mikael (28th September 2012)

  10. #9
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Smile Re: Qt and OpenGL

    I just figured out my problem and I just did some quick mathematic conversions from the screen coordinates so I could convert them to my ortho (grid) coordinates. It appears to me that either OpenGL or Qt puts a default ortho of (-1, 1, -1, 1, -1, 1) if you provide a min and max as the same values. So sorry if this ended up not being a real Qt question, but when the orthos were acting in a way I had never seen when I used the glut functions, I thought maybe the QGLWidget did something a little different. But thanks for all your help!

Similar Threads

  1. Does OpenGL be supported in opensource of Qt-4.1.2?
    By showhand in forum Qt Programming
    Replies: 1
    Last Post: 15th May 2006, 10:46
  2. OpenGl 2d
    By Lele in forum Qt Programming
    Replies: 10
    Last Post: 9th May 2006, 21:37
  3. help on openGL context
    By mickey in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2006, 19:21
  4. Qt's optimized OpenGL context switching
    By sverhoff in forum Qt Programming
    Replies: 0
    Last Post: 28th March 2006, 16:40
  5. Example OpenGL project?
    By brcain in forum Qt Tools
    Replies: 9
    Last Post: 23rd February 2006, 21:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.