View Full Version : OpenGL and Qt by Trolltech
06-12-2006, 03:34 PM
I am working on an application that imbeds some OpenGL into Qt (the C++ GUI builder by Trolltech, not QuickTime). 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 and Qt for the last 9 months, so I know how to handle simple things like this. But this is confusing me like crazy as I have never used both Qt and OpenGL in the same project! Does anyone have any idea why this behaves like this? Thanks!
06-13-2006, 01:47 AM
This is because all three of your given glOrtho() calls must have thrown a GL_INVALID_VALUE error and been ignored because zNear must not equal zFar.
Read the OpenGL 2.0 spec page 46.
During debugging add glGetError() calls to your code to catch such.
06-13-2006, 09:21 AM
Thanks for your reply. I did not realize that about the values for z. Another question I have is I am trying to draw a white box from the point a user clicks and drags until. (This is inside the QGLWidget) 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!
06-13-2006, 10:04 AM
"I did not realize that about the values for z."
Read the spec, it's the same for x and y.
"But how do I convert these to the grid coordinates?"
For unrotated ortho projection that's a simple rule of proportion math exercise and this is the advanced forum ;)
If you don't want to do it yourself just use gluUnProject.
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.