GL_UNPACK_SKIP_ROWS causes a crash?


I’m trying to make an application where the user can translate around an image. When the image moves upwards or rightwards, all is well. I simply adjust the raster position. Also, when the user translates leftwards, I adjust GL_UNPACK_SKIP_PIXELS, and it works well (although it redisplays the lefmost part of the image on the righthand side).

My problem is when the user wants to translate downwards. I try to adjust GL_UNPACK_SKIP_ROWS, and it crashes at the glDrawPixels call (I put printf’s before and after).

Any ideas on where to start debugging?
I should mention that the image is contained within its own window, separately from another window displaying a 3d model.

I’ll post my redisplay function below.


void imageWindow::CallBackDisplayFunc(void){

if (myImage.GetData()){

	zoom = (zoom < 0.0) ? .1 : zoom;

	if (trans_XY[0] < 0.0){
		int transx = (int)ceil(trans_XY[0]);
		trans_XY[0] = 0.0;
	int transy = (int)floor(trans_XY[1]);
	if (trans_XY[1] < 0.0 ) {
		trans_XY[1] = 0.0;

	glRasterPos2f( trans_XY[0],trans_XY[1]);
	glDrawPixels( myImage.GetWidth(), myImage.GetHeight(), GL_RGB, 
		     GL_UNSIGNED_BYTE, myImage.GetData());


This is a misuse and you are overflowing your array boundary. The raster position is used for positioning “a invisible cursor” from where you can glDrawPixels.

Why do you want to “skip rows”?


I’m really new to this, and the first way I could think of to scroll downwards on an image was simply not to draw the first few rows. I thought I was being careful by ensuring that rasterpos doesn’t go negative, but does incrementing SKIP_ROWS make pixelDraw(…) go outside the array boundaries?

I’m completely open - what would be the best way to scroll around an image?

Thanks for the help,

you could use a textured quad and change the texture coordinates

Thanks - hadn’t thought of that - it should work well. The only problem with this is that I would have to deal with rescaling the image so that each dimension is a power of 2, whereas it is currently 1280x960. Is there an easy way to do this?

Also - do you know what caused the previous implementation to crash? I’m still a bit clueless there…

You can pass negative values to rasterPos. With non standard opengl (extensions required such as NV_rectangle_whatever, you can supply non power of 2)

It’s not necessary to scale in your case for standard opengl. You can padd the edges with black pixels and send adjusted TexCoords to opengl so that the black areas dont become visible. It’s a bit tricky for this case.

Personally, I would stick to glRasterPos and glDrawPixels.