Any way to make the window transparent?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Jamtoad
Prole
Posts: 2
Joined: Sun Feb 24, 2019 10:45 pm

Any way to make the window transparent?

Post by Jamtoad »

I am using ZeroBrane Studio and LOVE to develop some software, but I have encountered a problem and I was wondering if it is possible to make the window transparent? :awesome:
User avatar
Alexar
Party member
Posts: 174
Joined: Thu Feb 05, 2015 1:57 am
Location: Chengdu,China

Re: Any way to make the window transparent?

Post by Alexar »

You can use "ffi" and windows api (user32.dll etc) to handle that.
Jamtoad
Prole
Posts: 2
Joined: Sun Feb 24, 2019 10:45 pm

Re: Any way to make the window transparent?

Post by Jamtoad »

Alrighty thanks :)
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Any way to make the window transparent?

Post by zorg »

If anything, that can only make the whole window equally transparent; you can't have stuff like the background be transparent and a sprite not be that, for example.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
St. Cosmo
Prole
Posts: 8
Joined: Wed Nov 07, 2018 6:53 pm

Re: Any way to make the window transparent?

Post by St. Cosmo »

actually you can set a transparent color for a window. https://docs.microsoft.com/en-us/window ... attributes

I am just not sure if that will be respected when you draw with OpenGL as love does
User avatar
zorg
Party member
Posts: 3468
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Any way to make the window transparent?

Post by zorg »

St. Cosmo wrote: Mon Feb 25, 2019 8:32 am actually you can set a transparent color for a window. https://docs.microsoft.com/en-us/window ... attributes

I am just not sure if that will be respected when you draw with OpenGL as love does
I read that article, and a few others; i might be wrong, but for one, it seems like it only works for child windows of a main one, and it also needs win8 at least ("In order to use layered child windows, the application has to declare itself Windows 8-aware in the manifest.") which i don't have.

That said, i tried using this code to test, which complained about the parameters i've given the function
(87 (0x57) - ERROR_INVALID_PARAMETER - The parameter is incorrect.) which let me tell you, was useful when it has multiple parameters. :D

That said, if any of you want to experiment further, here's what i tried:

Code: Select all

local ffi = require 'ffi'

ffi.load('user32.dll')

ffi.cdef[[

typedef void *HWND;

typedef int BOOL;
typedef unsigned long COLORREF;
typedef unsigned char BYTE;
typedef unsigned long DWORD;

HWND GetActiveWindow(

);

BOOL SetLayeredWindowAttributes(
  HWND     hwnd,
  COLORREF crKey,
  BYTE     bAlpha,
  DWORD    dwFlags
);

DWORD __stdcall GetLastError(void);
]]

function love.load()
	local hwnd = ffi.C.GetActiveWindow()
	local colorref = ffi.cast('COLORREF', 0x000000ff)
	local alpha = ffi.cast('BYTE', 127)
	local flags = ffi.cast('DWORD', 0x00000001)
	print(hwnd)
	local result = ffi.C.SetLayeredWindowAttributes(
		hwnd, -- hwnd
		colorref, -- colorref
		alpha, -- alpha, 50% 
		flags) -- flags (1: alpha->opacity, 2: colorkey -> transparency color)
	print(result)
	if result == 0 then
		print(ffi.C.GetLastError())
	end
end
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
NotARaptor
Citizen
Posts: 59
Joined: Thu Feb 22, 2018 3:15 pm

Re: Any way to make the window transparent?

Post by NotARaptor »

I can't test right now, but I have used a lot of win32 apis in the past (in C/C++) including these ones.

I think that firstly you need to call SetWindowLong (or is it SetWindowLongPtr now? it's been a while!) to add the WS_EX_LAYERED extended style to the window, THEN call SetLayeredWindowAttributes to update the info.

Also according to the docs, your flags are the wrong way around - 1 is for colour key and 2 is for alpha (and 3 is both).
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests