View Full Version : glDrawPixels issue

31st July 2007, 20:06
I am developing an app with OpenGL. Here is my hierarchy:

GLImage(my own object) which is a GLDisplay object (also my own object) which is a QGLWidget.
I have written the paintGL() method in GLImage and intializeGL and resizeGL in the GLDisplay

I have CameraImage class (my own object) that is inherited from another class (my own - DisplayMdiWindow) that inherits from QMdiSubWindow.

In the CameraImage class, I set the GLImage instance as the widget of the window using setWidget();

What I want to do is to display an image in the GLImage class. In paintGL(), I have:

glRasterPos(0,0); // the x,y to start drawing at
glDrawPixels(imageWidth, imageHeight, GL_LUMINANCE, GL_UNSIGNED_BYTE, buffer);

I believe that, for C++, drawing the pixels starts at (0,0) in the left hand corner and then draws the width and height that I specify.

What I have noticed is that while the bottom left is 0 for the x-coordinate, 0 does not appear to work for the
y-coordinate because I don't see anything. I've tried values like 10, 20, etc for the y_coordinate and doing so
moves the image up a little but depending on the size of the CameraImage window, the image sometimes gets cropped. I even tried to start drawing at the top left corner (0, viewport height) but that was wrong as well.

I've looked through the forums and online to see if there is any additional information about QGLWidget and glDrawPixels but I haven't seen any.

Is anyone trying to do something like this?


2nd August 2007, 06:47

Follow th link to get an idea

2nd August 2007, 18:25
Thanks for the link. I did look at that before but there is nothing specific to glDrawPixels. The examples given are for texture mapping.

I've done this outside of Qt (inside of glut windows) but it is behaving differently here. The real issue is coming up with a way to determine consistently where I should move to (using RasterPos) to get the full image to appear in the QMdiSubWindow via the QGLWidget.

-- Nisha

9th August 2007, 00:07
It was an openGL issue. I forgot to add a

glViewport(0, 0, width, height);
in my resizeGL() code before:

glOrtho(0.0, (double)width, 0.0, (double)height, -1.0, 1.0);

and then the drawing does start in the lower lefthand corner (0,0) as expected.