From 740cae1384d8f1b7c7551141e12694d0fe61a43b Mon Sep 17 00:00:00 2001 From: NishiOwO Date: Tue, 14 Oct 2025 09:14:56 +0000 Subject: [PATCH] i forgor sizeof(long) was 8 on x86_64 linux git-svn-id: http://svn2.nishi.boats/svn/milsko/trunk@319 b9cfdab3-6d41-4d17-bbe4-086880011989 --- examples/glclock.c | 29 +++++++++++++++++++++++++++++ src/backend/x11.c | 9 ++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/examples/glclock.c b/examples/glclock.c index 6c27d86..c36d9a9 100644 --- a/examples/glclock.c +++ b/examples/glclock.c @@ -18,6 +18,9 @@ void tick(MwWidget handle, void* user, void* call) { time_t t = time(NULL); int i; double rad; + int render = 0; + int w = MwGetInteger(opengl, MwNwidth); + int h = MwGetInteger(opengl, MwNheight); if(last != t) { char* wday[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; char* mon[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; @@ -31,6 +34,8 @@ void tick(MwWidget handle, void* user, void* call) { sprintf(buf, "%02d:%02d %s", tm->tm_hour % 12, tm->tm_min, tm->tm_hour >= 12 ? "PM" : "AM"); MwSetText(ltime, MwNtext, buf); + render = 1; + last = t; } @@ -68,6 +73,30 @@ void tick(MwWidget handle, void* user, void* call) { glVertex2f(cos(rad) * 0.5, sin(rad) * 0.5); glEnd(); + if(render && w > 0 && h > 0){ + unsigned char* buffer = malloc(w * h * 4); + MwLLPixmap px; + int j; + + glReadPixels(0, 0, w, h, GL_RGBA, GL_UNSIGNED_BYTE, buffer); + for(i = 0; i < h / 2; i++){ + for(j = 0; j < w * 4; j++){ + unsigned char b = buffer[i * w * 4 + j]; + + buffer[i * w * 4 + j] = buffer[(h - i - 1) * w * 4 + j]; + buffer[(h - i - 1) * w * 4 + j] = b; + } + } + + px = MwLoadRaw(window, buffer, w, h); + MwVaApply(window, + MwNiconPixmap, px, + NULL); + MwLLDestroyPixmap(px); + + free(buffer); + } + MwOpenGLSwapBuffer(opengl); } diff --git a/src/backend/x11.c b/src/backend/x11.c index 8fbbcb3..fce0a2a 100644 --- a/src/backend/x11.c +++ b/src/backend/x11.c @@ -320,10 +320,13 @@ MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int hei r->height = height; r->display = handle->display; r->use_shm = XShmQueryExtension(handle->display) ? 1 : 0; - r->data = malloc(width * height * 4); + r->data = malloc(sizeof(unsigned long) * width * height); r->use_render = XRenderQueryExtension(handle->display, &evbase, &erbase) ? 1 : 0; + /* FIXME */ + r->use_shm = 0; + if(r->use_shm) { r->image = XShmCreateImage(handle->display, DefaultVisual(handle->display, DefaultScreen(handle->display)), 24, ZPixmap, NULL, &r->shm, width, height); @@ -355,7 +358,7 @@ MwLLPixmap MwLLCreatePixmap(MwLL handle, unsigned char* data, int width, int hei p <<= 8; p |= px[2]; XPutPixel(r->image, x, y, p); - *(unsigned long*)(&r->data[(x + y * width) * 4]) = p; + *(unsigned long*)(&r->data[(y * width + x) * sizeof(unsigned long)]) = p; } } @@ -486,7 +489,7 @@ void MwLLSetIcon(MwLL handle, MwLLPixmap pixmap) { icon[1] = pixmap->height; for(i = 0; i < pixmap->width * pixmap->height; i++) { - icon[2 + i] = *(unsigned long*)(&pixmap->data[i * 4]); + icon[2 + i] = *(unsigned long*)(&pixmap->data[i * sizeof(unsigned long)]); } XChangeProperty(handle->display, handle->window, atom, 6, 32, PropModeReplace, (unsigned char*)icon, 2 + pixmap->width * pixmap->height);