Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Translucent Allegro Windows

This thread is locked; no one can reply to it. rss feed Print
 1   2 
Translucent Allegro Windows
Edgar Reynaldo
Major Reynaldo
May 2007
avatar

It's time to join the future.

Allegro needs custom OpenGL contexts and translucent windows. SDL has it, why not us?

So, I'm starting a project to get it done.

Step 1) Create a basic working example on every platform without using allegro. OpenGL and system calls only.

Step 2) Integrate custom OpenGL context creation into Allegro.

1a) Win32 and WGL

1b) X11, XLib, and XGL

1c) OSX, OpenGL

I'll start working on 1a. A Win32 example with WGL.

If anyone can tackle 1b or 1c, we'll get this done in no time.

This is something I have wanted to do for a long time, and I'm going to get it done if it kills me.

Edgar

GullRaDriel
Member #3,861
September 2003
avatar

Good idea. I'm not fluent enough in OpenGL to help you, but I can make some tests if needed (Windows/Linux/Android)

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Well, I've got a win32 OpenGL solution 'mostly' working.

It's translucent, but for some reason, it's like it's over gray at 1/2 alpha and I can't explain why.

https://github.com/EdgarReynaldo/TransAllegro

{"name":"Trans3.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/6\/36fa9553a11faa418c6300affd33af6b.png","w":1920,"h":1080,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/3\/6\/36fa9553a11faa418c6300affd33af6b"}Trans3.png

MikiZX
Member #17,092
June 2019

This is definitely way over my skill level and a good addition to Allegro.
Though, I am not sure even what could be suggested to help understand why it would be like that.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

In all actuality, once you get past all the misinformation and crap on the internet, it's actually quite easy.

Working win32 demo. Try it!

MikiZX
Member #17,092
June 2019

Sorry to report... I get a blank black rectangle in top-left corner of the screen.

EDIT: not sure if this helps:

#SelectExpand
1display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 5.87641] -- 2display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 5.87644] Decoding visual no. 98... 3display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 5.93237] Decoding: 4display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:210 display_pixel_format [ 5.93243] Accelerated: no 5display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:211 display_pixel_format [ 5.93247] Single-buffer: no 6display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:213 display_pixel_format [ 5.93250] Swap method: copy 7display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:216 display_pixel_format [ 5.93253] Color format: r8 g8 b8 a8, 32 bit 8display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:222 display_pixel_format [ 5.93256] Depth buffer: 16 bits 9display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:223 display_pixel_format [ 5.93260] Sample buffers: no 10display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:224 display_pixel_format [ 5.93263] Samples: 0 11display D E:\LIBS\LIBS81Rebuild\A5FORK\src\display_settings.c:212 debug_display_settings [ 5.93266] color: 32 (rgba 8888), depth: 16, stencil: 8, acc: 16161616, samples: 0/0 12display D E:\LIBS\LIBS81Rebuild\A5FORK\src\display_settings.c:527 _al_score_display_settings [ 5.93269] Score is : 1025 13display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 5.93272] -- 14display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 5.93275] Decoding visual no. 99... 15display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 5.98865] Decoding: 16display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:326 decode_pixel_format_attrib [ 5.98873] Not RGBA mode 17display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 5.98876] -- 18display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 5.98879] Decoding visual no. 100... 19display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 6.04412] Decoding: 20display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:326 decode_pixel_format_attrib [ 6.04418] Not RGBA mode 21display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 6.04421] -- 22display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 6.04424] Decoding visual no. 101... 23display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 6.09996] Decoding: 24display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:326 decode_pixel_format_attrib [ 6.10003] Not RGBA mode 25display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 6.10006] -- 26display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 6.10009] Decoding visual no. 102... 27display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 6.15576] Decoding: 28display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:326 decode_pixel_format_attrib [ 6.15582] Not RGBA mode 29display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 6.15585] -- 30display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 6.15588] Decoding visual no. 103... 31display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 6.21173] Decoding: 32display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:321 decode_pixel_format_attrib [ 6.21180] Can't draw to window 33display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 6.21184] -- 34display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 6.21187] Decoding visual no. 104... 35display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 6.26753] Decoding: 36display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:321 decode_pixel_format_attrib [ 6.26760] Can't draw to window 37display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 6.26764] -- 38display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 6.26767] Decoding visual no. 105... 39display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 6.32312] Decoding: 40display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:321 decode_pixel_format_attrib [ 6.32321] Can't draw to window 41display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 6.32324] -- 42display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 6.32327] Decoding visual no. 106... 43display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 6.37919] Decoding: 44display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:321 decode_pixel_format_attrib [ 6.37927] Can't draw to window 45display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 6.37930] -- 46display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 6.37933] Decoding visual no. 107... 47display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:306 decode_pixel_format_attrib [ 6.43517] Decoding: 48display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:321 decode_pixel_format_attrib [ 6.43524] Can't draw to window 49display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:732 get_available_pixel_formats_ext [ 6.43528] -- 50display I E:\LIBS\LIBS81Rebuild\A5FORK\src\win\wgl_disp.c:733 get_available_pixel_formats_ext [ 6.43531] Decoding visual no. 108...

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

What version of Windows are you using?

Is your desktop 32 bit color depth?

I'm on IRC on #allegro right now. Meet me there. Allegro.cc is being sketchy.

MikiZX
Member #17,092
June 2019

Windows 10, 32 bit.
I'll try the IRC though have never used it before so might be a minute or two...

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

MikiZX
Member #17,092
June 2019

log

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Since the first demo doesn't work for you, try this one :

https://www.allegro.cc/files/attachment/612221

The first one uses a hacked Allegro.

This one is straight win32 and OpenGL, with a little help from datenwolf.

MikiZX
Member #17,092
June 2019

Both work - I just needed a little patience for the bitmaps to load.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

All source code for the stand alone win32 opengl demo can be found here :

https://github.com/EdgarReynaldo/TransAllegro/tree/master/src/win

Note it borrows some helper functions from datenwolf and his wglarb demo, which can be found here :

https://github.com/datenwolf/wglarb

The gist of it is really simple.

1) Register a window class. The class style can be 0 or CS_OWNDC or perhaps others (not tested).

2) Create a window with CreateWindowEx, specifying WS_EX_APPWINDOW for the extended style and WS_POPUP for the style.

3) Create an OpenGL context that has 32 bit color, 8 bit alpha, and the WGL_TRANSPARENT_ARB extension enabled.

4) Use DWM to blur the window. DwmEnableBlurBehindWindow and DwmExtendFrameIntoClientArea are necessary to set up the window correctly so that the client area is NOT blurred (only non-blurred regions are drawn using alpha values [ yes this is as backwards as your reflection in the mirror ]).

   DWM_BLURBEHIND bb = {0,0,0,0};
   
   bb.dwFlags = DWM_BB_ENABLE;
   bb.fEnable = TRUE;
   bb.hRgnBlur = NULL;
   HRESULT hr = DwmEnableBlurBehindWindow(hwnd, &bb);
   if (FAILED(hr)) {
      printf("Could not enable blur behind.");
   }

   MARGINS margins = {-1};
   DwmExtendFrameIntoClientArea(hwnd, &margins);

5) Draw with OpenGL and enjoy.

UPDATE :
I found working source code on the internet from datenwolf for an XGLX translucency example. I haven't figured out exactly what does what yet, but I'm working on that.

source code

#SelectExpand
1/*------------------------------------------------------------------------ 2 * A demonstration of OpenGL in a ARGB window 3 * => support for composited window transparency 4 * 5 * (c) 2011 by Wolfgang 'datenwolf' Draxinger 6 * See me at comp.graphics.api.opengl and StackOverflow.com 7 8 * License agreement: This source code is provided "as is". You 9 * can use this source code however you want for your own personal 10 * use. If you give this source code to anybody else then you must 11 * leave this message in it. 12 * 13 * This program is based on the simplest possible 14 * Linux OpenGL program by FTB (see info below) 15 16 The simplest possible Linux OpenGL program? Maybe... 17 18 (c) 2002 by FTB. See me in comp.graphics.api.opengl 19 20 -- 21 <___/> 22 / O O \ 23 _____/ FTB. 24 25------------------------------------------------------------------------*/ 26 27#include <stdlib.h> 28#include <stdio.h> 29#include <string.h> 30#include <math.h> 31 32#include <GL/gl.h> 33#include <GL/glx.h> 34#include <GL/glxext.h> 35#include <X11/Xatom.h> 36#include <X11/extensions/Xrender.h> 37#include <X11/Xutil.h> 38 39#define USE_CHOOSE_FBCONFIG 40 41static void fatalError(const char *why) 42{ 43 fprintf(stderr, "%s", why); 44 exit(0x666); 45} 46 47static int Xscreen; 48static Atom del_atom; 49static Colormap cmap; 50static Display *Xdisplay; 51static XVisualInfo *visual; 52static XRenderPictFormat *pict_format; 53static GLXFBConfig *fbconfigs, fbconfig; 54static int numfbconfigs; 55static GLXContext render_context; 56static Window Xroot, window_handle; 57static GLXWindow glX_window_handle; 58static int width, height; 59 60static int VisData[] = { 61GLX_RENDER_TYPE, GLX_RGBA_BIT, 62GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, 63GLX_DOUBLEBUFFER, True, 64GLX_RED_SIZE, 8, 65GLX_GREEN_SIZE, 8, 66GLX_BLUE_SIZE, 8, 67GLX_ALPHA_SIZE, 8, 68GLX_DEPTH_SIZE, 16, 69None 70}; 71 72static int isExtensionSupported(const char *extList, const char *extension) 73{ 74 75 const char *start; 76 const char *where, *terminator; 77 78 /* Extension names should not have spaces. */ 79 where = strchr(extension, ' '); 80 if ( where || *extension == '\0' ) 81 return 0; 82 83 /* It takes a bit of care to be fool-proof about parsing the 84 OpenGL extensions string. Don't be fooled by sub-strings, 85 etc. */ 86 for ( start = extList; ; ) { 87 where = strstr( start, extension ); 88 89 if ( !where ) 90 break; 91 92 terminator = where + strlen( extension ); 93 94 if ( where == start || *(where - 1) == ' ' ) 95 if ( *terminator == ' ' || *terminator == '\0' ) 96 return 1; 97 98 start = terminator; 99 } 100 return 0; 101} 102 103static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg) 104{ 105 return d && e && arg && (e->type == MapNotify) && (e->xmap.window == *(Window*)arg); 106} 107 108static void describe_fbconfig(GLXFBConfig fbconfig) 109{ 110 int doublebuffer; 111 int red_bits, green_bits, blue_bits, alpha_bits, depth_bits; 112 113 glXGetFBConfigAttrib(Xdisplay, fbconfig, GLX_DOUBLEBUFFER, &doublebuffer); 114 glXGetFBConfigAttrib(Xdisplay, fbconfig, GLX_RED_SIZE, &red_bits); 115 glXGetFBConfigAttrib(Xdisplay, fbconfig, GLX_GREEN_SIZE, &green_bits); 116 glXGetFBConfigAttrib(Xdisplay, fbconfig, GLX_BLUE_SIZE, &blue_bits); 117 glXGetFBConfigAttrib(Xdisplay, fbconfig, GLX_ALPHA_SIZE, &alpha_bits); 118 glXGetFBConfigAttrib(Xdisplay, fbconfig, GLX_DEPTH_SIZE, &depth_bits); 119 120 fprintf(stderr, "FBConfig selected:\n" 121 "Doublebuffer: %s\n" 122 "Red Bits: %d, Green Bits: %d, Blue Bits: %d, Alpha Bits: %d, Depth Bits: %d\n", 123 doublebuffer == True ? "Yes" : "No", 124 red_bits, green_bits, blue_bits, alpha_bits, depth_bits); 125} 126 127static void createTheWindow() 128{ 129 XEvent event; 130 int x,y, attr_mask; 131 XSizeHints hints; 132 XWMHints *startup_state; 133 XTextProperty textprop; 134 XSetWindowAttributes attr = {0,}; 135 static const char *title = "FTB's little OpenGL example - ARGB extension by WXD"; 136 137 Xdisplay = XOpenDisplay(NULL); 138 if (!Xdisplay) { 139 fatalError("Couldn't connect to X server\n"); 140 } 141 Xscreen = DefaultScreen(Xdisplay); 142 Xroot = RootWindow(Xdisplay, Xscreen); 143 144 fbconfigs = glXChooseFBConfig(Xdisplay, Xscreen, VisData, &numfbconfigs); 145 fbconfig = 0; 146 for(int i = 0; i<numfbconfigs; i++) { 147 visual = (XVisualInfo*) glXGetVisualFromFBConfig(Xdisplay, fbconfigs[i]); 148 if(!visual) 149 continue; 150 151 pict_format = XRenderFindVisualFormat(Xdisplay, visual->visual); 152 if(!pict_format) 153 continue; 154 155 fbconfig = fbconfigs[i]; 156 if(pict_format->direct.alphaMask > 0) { 157 break; 158 } 159 } 160 161 if(!fbconfig) { 162 fatalError("No matching FB config found"); 163 } 164 165 describe_fbconfig(fbconfig); 166 167 /* Create a colormap - only needed on some X clients, eg. IRIX */ 168 cmap = XCreateColormap(Xdisplay, Xroot, visual->visual, AllocNone); 169 170 attr.colormap = cmap; 171 attr.background_pixmap = None; 172 attr.border_pixmap = None; 173 attr.border_pixel = 0; 174 attr.event_mask = 175 StructureNotifyMask | 176 EnterWindowMask | 177 LeaveWindowMask | 178 ExposureMask | 179 ButtonPressMask | 180 ButtonReleaseMask | 181 OwnerGrabButtonMask | 182 KeyPressMask | 183 KeyReleaseMask; 184 185 attr_mask = 186 CWBackPixmap| 187 CWColormap| 188 CWBorderPixel| 189 CWEventMask; 190 191 width = DisplayWidth(Xdisplay, DefaultScreen(Xdisplay))/2; 192 height = DisplayHeight(Xdisplay, DefaultScreen(Xdisplay))/2; 193 x=width/2, y=height/2; 194 195 window_handle = XCreateWindow( Xdisplay, 196 Xroot, 197 x, y, width, height, 198 0, 199 visual->depth, 200 InputOutput, 201 visual->visual, 202 attr_mask, &attr); 203 204 if( !window_handle ) { 205 fatalError("Couldn't create the window\n"); 206 } 207 208#if USE_GLX_CREATE_WINDOW 209 int glXattr[] = { None }; 210 glX_window_handle = glXCreateWindow(Xdisplay, fbconfig, window_handle, glXattr); 211 if( !glX_window_handle ) { 212 fatalError("Couldn't create the GLX window\n"); 213 } 214#else 215 glX_window_handle = window_handle; 216#endif 217 218 textprop.value = (unsigned char*)title; 219 textprop.encoding = XA_STRING; 220 textprop.format = 8; 221 textprop.nitems = strlen(title); 222 223 hints.x = x; 224 hints.y = y; 225 hints.width = width; 226 hints.height = height; 227 hints.flags = USPosition|USSize; 228 229 startup_state = XAllocWMHints(); 230 startup_state->initial_state = NormalState; 231 startup_state->flags = StateHint; 232 233 XSetWMProperties(Xdisplay, window_handle,&textprop, &textprop, 234 NULL, 0, 235 &hints, 236 startup_state, 237 NULL); 238 239 XFree(startup_state); 240 241 XMapWindow(Xdisplay, window_handle); 242 XIfEvent(Xdisplay, &event, WaitForMapNotify, (char*)&window_handle); 243 244 if ((del_atom = XInternAtom(Xdisplay, "WM_DELETE_WINDOW", 0)) != None) { 245 XSetWMProtocols(Xdisplay, window_handle, &del_atom, 1); 246 } 247} 248 249static int ctxErrorHandler( Display *dpy, XErrorEvent *ev ) 250{ 251 fputs("Error at context creation", stderr); 252 return 0; 253} 254 255static void createTheRenderContext() 256{ 257 int dummy; 258 if (!glXQueryExtension(Xdisplay, &dummy, &dummy)) { 259 fatalError("OpenGL not supported by X server\n"); 260 } 261 262#if USE_GLX_CREATE_CONTEXT_ATTRIB 263 #define GLX_CONTEXT_MAJOR_VERSION_ARB 0x2091 264 #define GLX_CONTEXT_MINOR_VERSION_ARB 0x2092 265 render_context = NULL; 266 if( isExtensionSupported( glXQueryExtensionsString(Xdisplay, DefaultScreen(Xdisplay)), "GLX_ARB_create_context" ) ) { 267 typedef GLXContext (*glXCreateContextAttribsARBProc)(Display*, GLXFBConfig, GLXContext, Bool, const int*); 268 glXCreateContextAttribsARBProc glXCreateContextAttribsARB = (glXCreateContextAttribsARBProc)glXGetProcAddressARB( (const GLubyte *) "glXCreateContextAttribsARB" ); 269 if( glXCreateContextAttribsARB ) { 270 int context_attribs[] = 271 { 272 GLX_CONTEXT_MAJOR_VERSION_ARB, 3, 273 GLX_CONTEXT_MINOR_VERSION_ARB, 0, 274 //GLX_CONTEXT_FLAGS_ARB , GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, 275 None 276 }; 277 278 int (*oldHandler)(Display*, XErrorEvent*) = XSetErrorHandler(&ctxErrorHandler); 279 280 render_context = glXCreateContextAttribsARB( Xdisplay, fbconfig, 0, True, context_attribs ); 281 282 XSync( Xdisplay, False ); 283 XSetErrorHandler( oldHandler ); 284 285 fputs("glXCreateContextAttribsARB failed", stderr); 286 } else { 287 fputs("glXCreateContextAttribsARB could not be retrieved", stderr); 288 } 289 } else { 290 fputs("glXCreateContextAttribsARB not supported", stderr); 291 } 292 293 if(!render_context) 294 { 295#else 296 { 297#endif 298 render_context = glXCreateNewContext(Xdisplay, fbconfig, GLX_RGBA_TYPE, 0, True); 299 if (!render_context) { 300 fatalError("Failed to create a GL context\n"); 301 } 302 } 303 304 if (!glXMakeContextCurrent(Xdisplay, glX_window_handle, glX_window_handle, render_context)) { 305 fatalError("glXMakeCurrent failed for window\n"); 306 } 307} 308 309static int updateTheMessageQueue() 310{ 311 XEvent event; 312 XConfigureEvent *xc; 313 314 while (XPending(Xdisplay)) 315 { 316 XNextEvent(Xdisplay, &event); 317 switch (event.type) 318 { 319 case ClientMessage: 320 if ((unsigned int)event.xclient.data.l[0] == del_atom) 321 { 322 return 0; 323 } 324 break; 325 326 case ConfigureNotify: 327 xc = &(event.xconfigure); 328 width = xc->width; 329 height = xc->height; 330 break; 331 } 332 } 333 return 1; 334} 335 336/* 6----7 337 /| /| 338 3----2 | 339 | 5--|-4 340 |/ |/ 341 0----1 342 343*/ 344 345GLfloat cube_vertices[][8] = { 346 /* X Y Z Nx Ny Nz S T */ 347 {-1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0}, // 0 348 { 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 0.0}, // 1 349 { 1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0}, // 2 350 {-1.0, 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0}, // 3 351 352 { 1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0}, // 4 353 {-1.0, -1.0, -1.0, 0.0, 0.0, -1.0, 1.0, 0.0}, // 5 354 {-1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 1.0, 1.0}, // 6 355 { 1.0, 1.0, -1.0, 0.0, 0.0, -1.0, 0.0, 1.0}, // 7 356 357 {-1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0}, // 5 358 {-1.0, -1.0, 1.0, -1.0, 0.0, 0.0, 1.0, 0.0}, // 0 359 {-1.0, 1.0, 1.0, -1.0, 0.0, 0.0, 1.0, 1.0}, // 3 360 {-1.0, 1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 1.0}, // 6 361 362 { 1.0, -1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0}, // 1 363 { 1.0, -1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 0.0}, // 4 364 { 1.0, 1.0, -1.0, 1.0, 0.0, 0.0, 1.0, 1.0}, // 7 365 { 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 1.0}, // 2 366 367 {-1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 0.0, 0.0}, // 5 368 { 1.0, -1.0, -1.0, 0.0, -1.0, 0.0, 1.0, 0.0}, // 4 369 { 1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 1.0, 1.0}, // 1 370 {-1.0, -1.0, 1.0, 0.0, -1.0, 0.0, 0.0, 1.0}, // 0 371 372 {-1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0}, // 3 373 { 1.0, 1.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0}, // 2 374 { 1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 1.0, 1.0}, // 7 375 {-1.0, 1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0}, // 6 376}; 377 378static void draw_cube(void) 379{ 380 glEnableClientState(GL_VERTEX_ARRAY); 381 glEnableClientState(GL_NORMAL_ARRAY); 382 glEnableClientState(GL_TEXTURE_COORD_ARRAY); 383 384 glVertexPointer(3, GL_FLOAT, sizeof(GLfloat) * 8, &cube_vertices[0][0]); 385 glNormalPointer(GL_FLOAT, sizeof(GLfloat) * 8, &cube_vertices[0][3]); 386 glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat) * 8, &cube_vertices[0][6]); 387 388 glDrawArrays(GL_QUADS, 0, 24); 389} 390 391float const light0_dir[]={0,1,0,0}; 392float const light0_color[]={78./255., 80./255., 184./255.,1}; 393 394float const light1_dir[]={-1,1,1,0}; 395float const light1_color[]={255./255., 220./255., 97./255.,1}; 396 397float const light2_dir[]={0,-1,0,0}; 398float const light2_color[]={31./255., 75./255., 16./255.,1}; 399 400static void redrawTheWindow() 401{ 402 float const aspect = (float)width / (float)height; 403 404 static float a=0; 405 static float b=0; 406 static float c=0; 407 408 glDrawBuffer(GL_BACK); 409 410 glViewport(0, 0, width, height); 411 412 // Clear with alpha = 0.0, i.e. full transparency 413 glClearColor(0.0, 0.0, 0.0, 0.0); 414 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 415 416 glMatrixMode(GL_PROJECTION); 417 glLoadIdentity(); 418 glFrustum(-aspect, aspect, -1, 1, 2.5, 10); 419 420 glMatrixMode(GL_MODELVIEW); 421 glLoadIdentity(); 422 423 glEnable(GL_DEPTH_TEST); 424 glEnable(GL_CULL_FACE); 425 426 glEnable(GL_BLEND); 427 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 428 429 glLightfv(GL_LIGHT0, GL_POSITION, light0_dir); 430 glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_color); 431 432 glLightfv(GL_LIGHT1, GL_POSITION, light1_dir); 433 glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_color); 434 435 glLightfv(GL_LIGHT2, GL_POSITION, light2_dir); 436 glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_color); 437 438 glTranslatef(0., 0., -5.); 439 440 glRotatef(a, 1, 0, 0); 441 glRotatef(b, 0, 1, 0); 442 glRotatef(c, 0, 0, 1); 443 444 glEnable(GL_LIGHT0); 445 glEnable(GL_LIGHT1); 446 glEnable(GL_LIGHTING); 447 448 glEnable(GL_COLOR_MATERIAL); 449 glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); 450 451 glColor4f(1., 1., 1., 0.5); 452 453 glCullFace(GL_FRONT); 454 draw_cube(); 455 glCullFace(GL_BACK); 456 draw_cube(); 457 458 a = fmod(a+0.1, 360.); 459 b = fmod(b+0.5, 360.); 460 c = fmod(c+0.25, 360.); 461 462 glXSwapBuffers(Xdisplay, glX_window_handle); 463} 464 465int main(int argc, char *argv[]) 466{ 467 createTheWindow(); 468 createTheRenderContext(); 469 470 while (updateTheMessageQueue()) { 471 redrawTheWindow(); 472 } 473 474 return 0; 475}

Can people with some flavor of *NIX compile this and try it?

Compilation should be as easy as :

g++ -Wall -g -I/usr/include -c xglx_trans.cpp -o xglx_trans.o

g++ -L/usr/X11/lib -L/usr/lib/x86_64-linux-gnu -o XTranslucency xglx_trans.o  -lX11 -lGLX -lGLU -lGL -lXrender

UPDATE
I know y'all are a bunch of nerds with computers. Help me test this and I'll give you a free lollipop. :D

Windows :
https://www.allegro.cc/files/attachment/612221 Spinny triangle
https://www.allegro.cc/files/attachment/612219 This one's fun

Linux
https://www.allegro.cc/files/attachment/612224 Spinny cube

LennyLen
Member #5,313
December 2004
avatar

I tried the Windows example. The translucency on the triangle was working fine but there was none on the running man.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

{"name":"lollipop1.jpg","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/8\/48d0423c04adcaa027b88d78ae5a5195.jpg","w":390,"h":600,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/4\/8\/48d0423c04adcaa027b88d78ae5a5195"}lollipop1.jpg

Interesting, LennyLen. I'll look into it. What version of Windows are you running?

The running man example was with a quickly hacked allegro.

The triangle was clean win32 and opengl with help from wglarb by datenwolf.

LennyLen
Member #5,313
December 2004
avatar

Interesting, LennyLen. I'll look into it. What version of Windows are you running?

Windows 10, version 1903, OS build 18362.476

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

I'm running the same version, and it works for me.... ?

And I can't tell the difference between what I did with datenwolf's wglarb and my hacked allegro.

So I don't know why it's not working. Can you post your allegro.log file for me?

You can also run it from the command line and see if there are any errors.

LennyLen
Member #5,313
December 2004
avatar

I'm running the same version, and it works for me.... ?

Is the running man himself supposed to be translucent or is the background just supposed to be transparent? Because if it's the latter, then it is working.

There were no errors while running from the command line, and the log file is attached.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Ah, good. So it is working. There was no aliasing on the running man, just wanted to see him run around my desktop. So no square window right?

EDIT
I should note, WGL_TRANSPARENT_ARB is not required at all. It's a total duck. The only thing necessary for a translucent win32 window is WS_POPUP style and enabling blur behind with DWM (note the invalid margins are important!).

*EDIT*
Here's the same running man demo, but he's on top, and up and down keys control alpha value, so you can see he's really translucent.

allegro_trans.7z

LennyLen
Member #5,313
December 2004
avatar

So no square window right?

Correct.

Quote:

Here's the same running man demo, but he's on top, and up and down keys control alpha value, so you can see he's really translucent.

I think you attached the wrong project.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

LennyLen
Member #5,313
December 2004
avatar

Seems to be working fine.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

When you turned the alpha down, was it still pretty red on his shoes when he was supposed to be all translucent?

So because you only need DWM, this also works for DX, so it's now a win32 translucency function that I'm adding to allegro.

LennyLen
Member #5,313
December 2004
avatar

I made a short video of it running while I adjusted the settings:

video

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Thanks to Elias, we can do it on X11 with GLX now too.

Any OSX users out there? We need your help!

EDIT
Can anyone on OSX test this code?

https://stackoverflow.com/questions/34531118/how-can-i-create-a-window-with-transparent-background-with-swift-on-osx#34533768

Peter Hull? Mark Oates? SiegeLord? Anybuddy?

EDIT2
Derp. doesn't anyone use OSX?

 1   2 


Go to: