PDA

View Full Version : GL_UNPACK_SKIP_ROWS causes a crash?



gegnal
04-05-2002, 11:51 AM
Hello,

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.

Thanks,
Geoff

void imageWindow::CallBackDisplayFunc(void){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

if (myImage.GetData()){

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

if (trans_XY[0] < 0.0){
int transx = (int)ceil(trans_XY[0]);
glPixelStorei(GL_UNPACK_SKIP_PIXELS,-transx);
trans_XY[0] = 0.0;
}else{
glPixelStorei(GL_UNPACK_SKIP_PIXELS,0);
}
int transy = (int)floor(trans_XY[1]);
if (trans_XY[1] < 0.0 ) {
glPixelStorei(GL_UNPACK_SKIP_ROWS,-transy);
trans_XY[1] = 0.0;
}else{
glPixelStorei(GL_UNPACK_SKIP_ROWS,0);
}

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

glutSwapBuffers();
}

V-man
04-05-2002, 12:33 PM
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"?

V-man

gegnal
04-05-2002, 12:46 PM
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,
Geoff

chowe6685
04-06-2002, 01:48 PM
you could use a textured quad and change the texture coordinates

gegnal
04-08-2002, 03:39 AM
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...

V-man
04-08-2002, 03:12 PM
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.

V-man