Any way to make the window transparent?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Any way to make the window transparent?
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?
Re: Any way to make the window transparent?
You can use "ffi" and windows api (user32.dll etc) to handle that.
Re: Any way to make the window transparent?
Alrighty thanks
- 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?
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 True 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.
Re: Any way to make the window transparent?
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 am just not sure if that will be respected when you draw with OpenGL as love does
- 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?
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.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
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.
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 True 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.
- NotARaptor
- Citizen
- Posts: 59
- Joined: Thu Feb 22, 2018 3:15 pm
Re: Any way to make the window transparent?
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).
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).
Who is online
Users browsing this forum: Bing [Bot] and 5 guests