pkgsrc-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: devel/sdl2 pkgsrc-2026Q3 transparent/corrupted X11 window





El 27/9/26 a las 13:46, Michael van Elst escribió:
ea1abz%gmail.com@localhost (Ramiro Aceves) writes:

I believe there is a problem with SDL2 and X11 in pkgsrc-2026Q3 on NetBSD.
After updating my system to pkgsrc-2026Q3, applications using SDL2 create
  a corrupted/transparent X11 window. The desktop contents can be seen
through the application window.


The window is not refreshed by the application, so the previous screen
content is still visible.

You need to add an event loop that calls something like

SDL_UpdateWindowSurface(window);

to refresh the window contents.


E.g.:

      SDL_Event event;
      bool end;

      end = false;
      while (!end) {
        if (SDL_WaitEvent(&event)) {
          switch (event.type) {
          case SDL_QUIT:
            end = true;
            break;
          case SDL_WINDOWEVENT:
            switch (event.window.event) {
            case SDL_WINDOWEVENT_EXPOSED:
              SDL_UpdateWindowSurface(window);
              break;
            }
            break;
          }
        }
      }


This reacts to window exposure and handles a QUIT event from the
window manager to exit the loop.

This has always been necessary, but maybe not that obvious. If
enough render commands have been pushed before waiting, these
could have been flushed out to the display arelady, but there
is no guarantee.

Waiting for an event triggers such a flush.

Handling the exposure event makes sure that the display is
updated when the window is e.g. moved, resized, exposed, etc...

Hi Michael,

I tried your suggestion exactly as described, adding the event
loop with SDL_WaitEvent() and handling SDL_WINDOWEVENT_EXPOSED
by calling SDL_UpdateWindowSurface(window).

Unfortunately, the result is exactly the same: the window is
still displayed with the horizontal stripes/corrupted contents.

I have also tested several other SDL2 programs and they all
 show the same problem, including sdlpop game. QEMU also has the
 problem when using its SDL display, while its GTK display
works correctly.

So I think it does not seem to be related to the application failing to refresh the window.

Also have tested the c11 example of this series of tests (they compile fine using gmake):

https://github.com/xyproto/sdl2-examples

C11 test does not work. I have tested it in Linux and FreeBSD and it works, it shows a beautiful cat image.

Something seems to be broken in NetBSD.


Regards,
Ramiro



netbsd-nuc$ cat test_michael.c
#include <SDL.h>
#include <stdio.h>
#include <stdbool.h>

int
main(void)
{
    SDL_Window *window;
    SDL_Surface *surface;
    SDL_Event event;
    bool end;

    if (SDL_Init(SDL_INIT_VIDEO) != 0) {
        fprintf(stderr, "SDL_Init: %s\n", SDL_GetError());
        return 1;
    }

    window = SDL_CreateWindow(
        "SDL2 test",
        SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED,
        800, 600,
        SDL_WINDOW_SHOWN
    );

    if (window == NULL) {
        fprintf(stderr, "SDL_CreateWindow: %s\n", SDL_GetError());
        SDL_Quit();
        return 1;
    }

    surface = SDL_GetWindowSurface(window);

    if (surface == NULL) {
        fprintf(stderr, "SDL_GetWindowSurface: %s\n", SDL_GetError());
        SDL_DestroyWindow(window);
        SDL_Quit();
        return 1;
    }

    /* Pintamos inicialmente la ventana de azul */
    Uint32 blue = SDL_MapRGB(
        surface->format,
        0, 128, 255
    );

    SDL_FillRect(surface, NULL, blue);
    SDL_UpdateWindowSurface(window);

    end = false;

    while (!end) {
        if (SDL_WaitEvent(&event)) {
            switch (event.type) {

            case SDL_QUIT:
                end = true;
                break;

            case SDL_WINDOWEVENT:
                switch (event.window.event) {

                case SDL_WINDOWEVENT_EXPOSED:
                    SDL_UpdateWindowSurface(window);
                    break;
                }
            }
        }
    }

    SDL_DestroyWindow(window);
    SDL_Quit();

    return 0;
}






Home | Main Index | Thread Index | Old Index