resizing issues

This commit is contained in:
David Rose 2008-05-05 06:54:51 +00:00
parent cf12fbfef7
commit f119c9c63c
2 changed files with 10 additions and 8 deletions

View File

@ -223,7 +223,7 @@ begin_flip() {
} }
XPutImage(_display, _xwindow, _gc, _ximage, 0, 0, 0, 0, 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); XFlush(_display);
} }
@ -316,7 +316,7 @@ process_events() {
properties.set_size(event.xconfigure.width, event.xconfigure.height); properties.set_size(event.xconfigure.width, event.xconfigure.height);
system_changed_properties(properties); system_changed_properties(properties);
ZB_resize(_frame_buffer, NULL, _properties.get_x_size(), _properties.get_y_size()); 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(); create_ximage();
} }
break; 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); _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; _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; char *data = NULL;
if (_bytes_per_pixel != 4) { if (_bytes_per_pixel != 4) {
data = (char *)PANDA_MALLOC_ARRAY(image_size); data = (char *)PANDA_MALLOC_ARRAY(image_size);
} }
_ximage = XCreateImage(_display, _visual, _depth, ZPixmap, 0, data, _ximage = XCreateImage(_display, _visual, _depth, ZPixmap, 0, data,
_properties.get_x_size(), _properties.get_y_size(), _frame_buffer->xsize, _frame_buffer->ysize,
8, 0); 32, 0);
} }
#endif // IS_LINUX #endif // IS_LINUX

View File

@ -22,6 +22,9 @@ ZBuffer *ZB_open(int xsize, int ysize, int mode,
if (zb == NULL) if (zb == NULL)
return NULL; return NULL;
/* xsize must be a multiple of 4 */
xsize = xsize & ~3;
zb->xsize = xsize; zb->xsize = xsize;
zb->ysize = ysize; zb->ysize = ysize;
zb->mode = mode; 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; zb->linesize = (xsize * PSZB + 3) & ~3;
size = zb->xsize * zb->ysize * sizeof(unsigned short); size = zb->xsize * zb->ysize * sizeof(unsigned short);
gl_free(zb->zbuf); gl_free(zb->zbuf);
zb->zbuf = gl_malloc(size); zb->zbuf = gl_malloc(size);
@ -331,7 +333,7 @@ void ZB_clear_viewport(ZBuffer * zb, int clear_z, int z,
} }
if (clear_color) { if (clear_color) {
color = RGBA_TO_PIXEL(r, g, b, a); 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) { for (y = 0; y < ysize; ++y) {
memset_l(pp, color, xsize); memset_l(pp, color, xsize);
pp += zb->xsize; pp += zb->xsize;