[Kde-games-devel] Re: Coordinate System in QGLWidget

Andreas Beckermann b_mann at gmx.de
Mon Apr 21 20:31:03 CEST 2003


On Monday 21 April 2003 17:22, Christoph Keller wrote:
> I have created an OpenGl Widget using a class derived of QGLWidget. I
> can draw in this Widget, but the left bottom Corner has the Coordinates
> (-1/-1) and the upper right corner the coordiantes (1/1). But i Want to
> draw in Pixels, and access the widget in Pixels. I know how to do this
> with a Window created with the glut Toolkit, but found nothing about it
> in the Qt-Documentation and the OpenGl Documentation at sgi.com. I am
> Thankful for help.
>
> Christoph Keller

Hi
This isn't a Qt issue, but rather an OpenGL issue, so you won't find much on 
this in the Qt docs. For OpenGL (0,0) is lower left, whereas (width(), 
height()) is upper right.

As you want to draw in pixels I assume you want to draw 2D ?
Then you should probably use something like this in your resizeGL():
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, width(), 0.0, height());
glMatrixMode(GL_MODELVIEW);
...

Then you can access in pixel coordinates, but you must remember that the 
y-coordinate is flipped in OpenGL. So instead of
glVertex3f(100.0, 100.0, 0.0);
you use
glVertex3f(100.0, -100.0, 0.0);
to render a vertex at (100,100).

btw: the "red book" is usually recommended as the best start into OpenGL. You 
can read an (older but still valid) version at
http://www.dcc.unicamp.br/~lmarcos/courses/mc603/redbook/
and probably other locations (happy googling)

CU
Andi



More information about the kde-games-devel mailing list