Fondo transparente en sdl

Tratamos sobre el manejo de APIs frecuentemente utilizadas en el desarrollo de videojuegos, como SDL, pygame o SFML.

Fondo transparente en sdl

Notapor Tras » Mar Ene 06, 2009 10:53 pm

Hola este es mi primer post en este foro así que comienzo con un saludo a todos y una pregunta :D .

El caso es que estoy empezando con sdl en plan curiosidad , me gusta enredar y tal.
Estoy intentando hacer una pequeña aplicación y pretendo que la ventana principal sea transparente o translúcida, lo intente hacer creando una imagen con gimpl que era transparente pero la cargarla imagen me aparecía el fondo de la ventana negro y yo lo que busco es que se vea el fondo del escritorio, estuve buscando por google pero no encontré la respuesta de como hacerlo , tengo que reconocer que buscar nunca se me a dado bien, asi que recurro a este foro para ver si alguien me puede dar una idea de que función podria usar o como podría conseguir esa ventana transparente.
Lo estoy haciendo en debian lo digo por si hay algún problema con las X y demás.

Un saludo y gracias
Tras
 
Mensajes: 7
Registrado: Mar Ene 06, 2009 10:36 pm

Notapor lacabra25 » Dom Ene 11, 2009 12:49 pm

Hola, navegando por internet he encontrado la solucion a tu post (puede que ya la tengas pues la encontre en un foro en el que aparece tu mismo nombre de usuario).

Mira el siguiente codigo:
Código: Seleccionar todo
/*
   Copied from: http://lists.freedesktop.org/pipermail/xorg/2005-October/010877.html

   Save as this code to "xshape1.c"

* Compile it:
* gcc -Wall -g -lX11 -lXext xshape1.c -o xshape1
*/

/* This program *attempts* to create a "transparent" window (using
* the XShape extension) and draw four white (opaque) squares in
* each corner of the window
*/

// Moma: Check this
// http://mi.eng.cam.ac.uk/~er258/code/x11.html

#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <X11/Xlib.h>
#include <unistd.h>
#include <X11/Xutil.h>
#include <X11/extensions/shape.h>

/* size of the window */
#define W_WIDTH 640
#define W_HEIGHT 480

/* size of the four rectangles that will be drawn in the window */
#define R_WIDTH 80
#define R_HEIGHT 60

Display *dpy;
Window w;

/* convenience variables */
int BLACK_PIXEL;
int WHITE_PIXEL;

/* the four rectangles that will be drawn: one in each corner of the
* window */
XRectangle rectangles[4] =
{
    { 0, 0, R_WIDTH, R_HEIGHT },
    { 0, W_HEIGHT-R_HEIGHT, R_WIDTH, R_HEIGHT },
    { W_WIDTH-R_WIDTH, W_HEIGHT-R_HEIGHT, R_WIDTH, R_HEIGHT },
    { W_WIDTH-R_WIDTH, 0, R_WIDTH, R_HEIGHT }
};
       
int main(int argc, char **argv)
{
    XGCValues shape_xgcv;
    Pixmap pmap;
    GC shape_gc;
    GC gc;
    XGCValues gcv;
    int event_base, error_base;
    int run = 1; /* loop control variable */

    /* open the display */
    if(!(dpy = XOpenDisplay(getenv("DISPLAY")))) {
        fprintf(stderr, "can't open display\n");
        return EXIT_FAILURE;
    }

    /* convenience */
    BLACK_PIXEL = BlackPixel(dpy, DefaultScreen(dpy));
    WHITE_PIXEL = WhitePixel(dpy, DefaultScreen(dpy));

    w = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0,
            W_WIDTH, W_HEIGHT, 0, CopyFromParent,
            InputOutput, CopyFromParent, 0, NULL);

    // Check if X supports the SHAPE extension
    if (!XShapeQueryExtension(dpy, &event_base, &error_base) )
    {
      fprintf(stderr, "Your X installation does not have the SHAPE extension\n");
      exit(-1);
    }

    /* Try to create a transparent background.
     *
     * The idea/technique attempts to mimic lines 342--360 of
     * "Eyes.c", from the "xeyes" source.  (The xeyes source is part
     * of the X11 source package.)
     *
     * Every other example I've seen uses a pixmap, but I'd like to
     * not have a pixmap as a requirement.
     */

    pmap = XCreatePixmap(dpy, w, W_WIDTH, W_HEIGHT, 1);
    shape_gc = XCreateGC(dpy, pmap, 0, &shape_xgcv);
    XSetForeground(dpy, shape_gc, 0);
    XFillRectangle(dpy, pmap, shape_gc, 0, 0, W_WIDTH, W_HEIGHT);

    XShapeCombineMask (dpy, w, ShapeBounding, 0, 0, pmap, ShapeSet);

    /* If I remove everything above (until the comment), and replace
     * with the following, this application works as expected (e.g.,
     * draws a black window with white rectanles at each corner */
    /* XSetWindowBackground(dpy, w, BLACK_PIXEL); */

    /* create a graphics context for drawing */
    gcv.foreground = WHITE_PIXEL;
    gcv.line_width = 1;
    gcv.line_style = LineSolid;
    gc = XCreateGC(dpy, w,
            GCForeground | GCLineWidth | GCLineStyle, &gcv);

    /* register events: ExposureMask for re-drawing, ButtonPressMask
     * to capture mouse button press events */
    XSelectInput(dpy, w, ExposureMask | ButtonPressMask);

    XMapWindow(dpy, w);
    XSync(dpy, False);

    while(run) {
        XEvent xe;
        XNextEvent(dpy, &xe);
        switch (xe.type) {
            case Expose:
                /* whenever we get an expose, draw the rectangles */
                XSetForeground(dpy, gc, WHITE_PIXEL);
                XDrawRectangles(dpy, w, gc, rectangles, 4);
                XFillRectangles(dpy, w, gc, rectangles, 4);
                XSync(dpy, False);
                break;
            case ButtonPress: /* quit if a button is pressed */
                /* note that when using XShapeCombineMask(), i.e.
                 * trying to get a "transparent" background,
                 * no ButtonPress events are ever recognized
                 */
                printf("ButtonPress\n");
                run = 0;
                break;
            default:
                printf("Caught event %i\n", xe.type);
        }
    }

    XDestroyWindow(dpy, w);
    XCloseDisplay(dpy);

    return 0;
}


Al parecer se trata de modificar las propiedades de la ventana y no del contenido de la ventana, hay que usar con SDL la funcion SDL_GetWMInfo() para llenar una estructura tipo SDL_SysWMinfo. Esta estructura contiene los handlers tanto del display (info.x11.display) como de la ventana (info.x11.window).

Esto es todo lo que he encontrado por el momento sobre la cuestion que planteas en este post.
Esta cuenta ahora a pasado a la cuenta jhg
Avatar de Usuario
lacabra25
 
Mensajes: 222
Registrado: Mié Abr 02, 2008 9:45 pm
Ubicación: Tenerife (España)

Notapor Tras » Lun Ene 12, 2009 11:51 am

Sip ya lo tenia, yo encontré el codigo , lo iba a publicar aquí pero siempre se me olvidaba :lol: .

Al final lo publicaste tu :D soy un desastre :oops: .
Tras
 
Mensajes: 7
Registrado: Mar Ene 06, 2009 10:36 pm


Volver a Sobre las bibliotecas multimedia

¿Quién está conectado?

Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 1 invitado