Viewport Limitations

I am having problem with glDrawPixels and I am wondering if I am hitting some limitations with my viewport or something else of that nature. I know there are limitations to the viewport’s width and height, but what about its starting point?

The data I am trying to draw is inside a scrolled area (using Qt) with an area about 24,000 pixels high by 2,000 pixels wide. I set my scroll bar to range from values 0-max(~24,000) and retrieve the value from the scroll bar to know which row is the first row I am seeing. 0 is at the bottom and “max” is at the top. I always start the viewing at the top of the data and display about 1000 pixels in height and width (inside the limitations I printed out using glGet( ) ). But with this much data, my glDrawPixels does not appear to draw anything to the screen until I get down to about the 6,000th-8,000th pixel starting the viewport. So what I do looks something like this: Unfortunately I do not have the code with me as this is done on a stand-alone Solaris box.

glViewport( widthOffset, heightOffset, width, height );
glOrtho( 0.0, width, 0.0, height, -1.0, 1.0 );
glRasterPos2f( 0.0, 0.0 );
glDrawPixels( width, height, GL_COLOR_INDEX, GL_UNSIGNED_SHORT, data );  

I left out the code stating when I switch matrices but I use the standard matrices for their respective calls as shown in most textbooks on OpenGL. I just left it out here since I didn’t feel like typing those all in. So width is ~1000 and height is ~1000 with widthOffset normally being 0 or ~1000, depends if I am showing the first 1000 pixels of width or the last 1000 pixels of width. The heightOffset ranges anywhere from 0 to ~23000 based on which portion of the data I choose to see.

Does anyone have any idea why I cannot see data once my viewport’s beginning point gets too high? Thanks!

You can try calling glLoadIdentity() before the glOrtho call. Maybe that’ll fix it.

N.

Sorry I left that out because I considered that a standard call as well as the glMatrix calls, but yes, I do a glLoadIdentity call before the glOrtho call and after the glMatrix call.

I see the problem now, You have to make sure that (widthOffset+width,heightOffset+height) is still in your max viewport range. 4096x4096 on recent hardware (8192x8192 on latest).

The viewport call specifies a rectangular region within your framebuffer and you can’t have a framebuffer size of 24000x2000. The viewport call determines the part of the framebuffer(window) you are writing to, not the data region you are reading from.

N.

I think what you say is incorrect based on what I have been able to do. I used a glGetIntegerV call to get my max viewport dimensions and it came back that my max width and height are both 2000. But I am only ever trying to get a viewport with width ~1000 and height ~1000.

According to what you say I shouldn’t be able to see more than the first 2000 pixels in height when in fact I can normally see the first 8000 pixels with scrolling up the data. All the offset is doing is preventing me from drawing data that is off the display since it can’t be seen anyways.

Thanks for the ideas and I will keep trying them but I find it hard to believe that the widthOffset+width must be <= 2000 and the same for heightOffset+height, since my heightOffset approaches 8000 and still displays data.

You shoudln’t use OpenGl with scrolled areas. I have no idea how Qt implements such windows, but it gets your window manager probably messed up. If you need scrolled areas, use a simple GL window and some scrollbars and emulate the scrolling.

What do you mean it gets the window manager messed up? I have a QScrollArea with a QGLWidget inside it. It is inside this QGLWidget all my rendering is done. I don’t understand how a scrolled area will screw this up. All I use the scroll area for is to get the values from the scroll bars so I know what position to set my data pointer to so I can draw the correct data. So essentially I am emulating scrolling by telling glDrawPixels what portion of my data to draw based on the position I start the pointer at.

I set the scroll area to the 2000 wide by 24000 high but the QGLWidget inside is ~1000x~1000 and like I said, I use the scroll bars positions to tell me what area of data to draw and then inside my code I set the pointer’s location to draw the correct portion of data. I have old code where if I draw all 2000x24000 pixels it works, but very slowly. I am trying to optomize the code by only drawing the data that is visible to the user on the screen.

As I said, I have no idea how scrolled areas work. But: if you gl widget is only 1000x1000, then it’s maximal viewport is always (0, 0, 1000, 1000), your call glViewport( widthOffset, heightOffset, width, height ) defines the area outside the window. What you should do is offset your pixel data. Copy the visible part into a new array and render it accordingly.

I had not thought about copying the needed data into a temp array and trying that and always making my viewport to 0,0,width,height. I will give this a try. Thanks!