diff --git a/panda/src/tinydisplay/tinyXGraphicsWindow.cxx b/panda/src/tinydisplay/tinyXGraphicsWindow.cxx index ba0f50fb67..1c3b594849 100644 --- a/panda/src/tinydisplay/tinyXGraphicsWindow.cxx +++ b/panda/src/tinydisplay/tinyXGraphicsWindow.cxx @@ -223,7 +223,7 @@ begin_flip() { } XPutImage(_display, _xwindow, _gc, _ximage, 0, 0, 0, 0, - _properties.get_x_size(), _properties.get_y_size()); + _frame_buffer->xsize, _frame_buffer->ysize); XFlush(_display); } @@ -316,7 +316,7 @@ process_events() { properties.set_size(event.xconfigure.width, event.xconfigure.height); system_changed_properties(properties); ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size()); - _pitch = _properties.get_x_size() * _bytes_per_pixel; + _pitch = (_frame_buffer->xsize * _bytes_per_pixel + 3) & ~3; create_ximage(); } break; @@ -1588,7 +1588,7 @@ create_frame_buffer() { } _frame_buffer = ZB_open(_properties.get_x_size(), _properties.get_y_size(), mode, 0, 0, 0, 0); - _pitch = _properties.get_x_size() * _bytes_per_pixel; + _pitch = (_frame_buffer->xsize * _bytes_per_pixel + 3) & ~3; } @@ -1609,15 +1609,15 @@ create_ximage() { _ximage = NULL; } - int image_size = _properties.get_x_size() * _properties.get_y_size() * _bytes_per_pixel; + int image_size = _frame_buffer->ysize * _pitch; char *data = NULL; if (_bytes_per_pixel != 4) { data = (char *)PANDA_MALLOC_ARRAY(image_size); } _ximage = XCreateImage(_display, _visual, _depth, ZPixmap, 0, data, - _properties.get_x_size(), _properties.get_y_size(), - 8, 0); + _frame_buffer->xsize, _frame_buffer->ysize, + 32, 0); } #endif // IS_LINUX diff --git a/panda/src/tinydisplay/zbuffer.c b/panda/src/tinydisplay/zbuffer.c index 2b74e92546..b2c80592b9 100644 --- a/panda/src/tinydisplay/zbuffer.c +++ b/panda/src/tinydisplay/zbuffer.c @@ -22,6 +22,9 @@ ZBuffer *ZB_open(int xsize, int ysize, int mode, if (zb == NULL) return NULL; + /* xsize must be a multiple of 4 */ + xsize = xsize & ~3; + zb->xsize = xsize; zb->ysize = ysize; zb->mode = mode; @@ -98,7 +101,6 @@ void ZB_resize(ZBuffer * zb, void *frame_buffer, int xsize, int ysize) zb->linesize = (xsize * PSZB + 3) & ~3; size = zb->xsize * zb->ysize * sizeof(unsigned short); - gl_free(zb->zbuf); zb->zbuf = gl_malloc(size); @@ -331,7 +333,7 @@ void ZB_clear_viewport(ZBuffer * zb, int clear_z, int z, } if (clear_color) { color = RGBA_TO_PIXEL(r, g, b, a); - pp = zb->pbuf + xmin + ymin * zb->xsize; + pp = zb->pbuf + xmin + ymin * (zb->linesize / PSZB); for (y = 0; y < ysize; ++y) { memset_l(pp, color, xsize); pp += zb->xsize;