![]() |
SDL transparent primary surface (main window) ? | ![]() |
![]() |
![]() |
meuchel
![]() |
![]() |
no one knows?
I found this GL sample to manage transparent background which works but I have no idea how to adapt this with SDL2. https://gist.github.com/je-so/903479 I tried the following in the render function: Instead of SDL_RenderClear(mRenderer) I've added // Create an OpenGL context associated with the window. SDL_GLContext glcontext = SDL_GL_CreateContext(mWindow); // now you can make GL calls. glClearColor( 0.7, 0.7, 0.7, 0.7) ; // light gray bg glClear(GL_COLOR_BUFFER_BIT); // Once finished with OpenGL functions, the SDL_GLContext can be deleted. SDL_GL_DeleteContext(glcontext); ... and finally SDL_RenderPresent(mRenderer); In principle it works, the bg will be shown light gray but unfortunatly solid instead of transparent. What I missed (couldn't archive it from the sample)? Above GL stuff seems nothing other than SDL_SetRenderDrawColor(renderer, 0xC0, 0xC, 0xC, 127) which also didn't helped to make it transparent. I assume that there is maybe a OS dependent hack neecessary e.g. in SDL_X11window.c ? I use to get it to work with Ubuntu 14.04 LTS. Any help would be fine. ![]() |
||||||||||
|
![]() |
![]() |
meuchel
![]() |
![]() |
I thought I would find here SDL specialists with a solution...
![]() Because I got no answer I solved it myself with help of regular SDL_CreateWindowFrom and share it with you. Its not perfect but it works for me under Ubuntu. It works only with GL. Another bad thing is that the window doesn't post SDL events. On the fly I couldn't find a solution to manage this. Maybe someone other can tell how this can be done. Meanwhile below you will find too how to handle X events. Add this variables to your App class or whereever
Here is the custom SDL create window function with transparent background.
SDL_CreateTransparentWindow can be used as usual
Add this to the beginning of your render procedure to clear the transparent background. You can place your drawing objects as usual. Also blending your objects is still working.
Event handler
Add finally following to your cleanup procedure
|
||||||||||||||||||||||
|
![]() |
SDL transparent primary surface (main window) ? | ![]() |
Iván José Dasilva Fr...
Guest
![]() |
![]() |
I know that this comes a bit late, but maybe this can help you, meuchel.
I was making a 'clone' of Pong and I was asked to make it for a terminal window, so I decided to use ncurses. As I wanted to manage the keyboard events with SDL, I need an SDL window that received the events. In order to receive them, the window needs to have the focus, but I wanted it to be 'transparent', so this is what I used. I have this window (which is the one I use for menus): Â window = SDL_CreateWindow("Poing!", 100, 100, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN); and when I want it to be 'transparent', I use this: Â SDL_DestroyWindow(window); Â window = SDL_CreateWindow("", 0, 0, 100, 0, SDL_WINDOW_BORDERLESS); I know this can looks horrible to someone with more experience in SDL than me (that's not too difficult ![]() Greetings. |
||||||||||
|
![]() |
Alpha-blended overlay widgets (transparent window) | ![]() |
Egal
![]() |
![]() |
Hi there,
I found an interesting feature for SDL2: alpha-blended overlay widgets, see links for examples: http://www.getlazarus.org/forums/viewtopic.php?t=40 http://www.getlazarus.org/forums/viewtopic.php?t=37 Anyways, the source is found at: https://github.com/sysrpl/Cross.Codebot/tree/master/source I am thinking about learning SDL2 and porting (maybe) the win32/win64 portion. -Egal |
||||||||||
|