Draw image to screen with transparency

Advanced game related topics
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Draw image to screen with transparency

Post by coco2 »

Is it possible to draw an image to the screen with transparency? The method in the built in help file doesn't seem to work for me. IE I'm trying to create an image using:

Code: Select all

CreateImage(0, 600, 600, 32, #PB_Image_Transparent)
And then drawing to the image using vector functions and subsequently drawing the image to screen does not keep the transparency.
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Draw image to screen with transparency

Post by coco2 »

I found it, DrawAlphaImage works

Does anyone know why the coordinates of DrawAlphaImage do not match up with the current window? I'm using a 4K screen and the width is right but the height appears to be 1440. So when I draw an image at Y=1000 it's nearly at the bottom of the screen but the 4K resolution is 3840x2160.
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: Draw image to screen with transparency

Post by SPH »

Please : a small exemple to illustrate that ? :idea:

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Draw image to screen with transparency

Post by coco2 »

If I run this on a 4K monitor:

Code: Select all

DWidth.i = DesktopWidth(0)
DHeight.i = DesktopHeight(0)
OpenWindow(0, 0, 0, DWidth, DHeight, "Test", #PB_Window_Maximize | #PB_Window_BorderLess)
InitSprite()
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), #False, 0, 0, #PB_Screen_WaitSynchronization)
Debug "Resolution detected: " + DWidth + " x " + DHeight
Debug "Resolution effective: " + WindowWidth(0) + " x " + WindowHeight(0)
InitKeyboard()
Repeat
  Event = WaitWindowEvent()
  ExamineKeyboard()
  Esc_Pressed = KeyboardPushed(#PB_Key_Escape)
Until Event = #PB_Event_CloseWindow Or Esc_Pressed
the result I get is:

Resolution detected: 3840 x 2160
Resolution effective: 2560 x 1440

I don't get the full 4K resolution when I have a WindowedScreen.

Note: edited code to only check the first monitor
Last edited by coco2 on Sat Nov 18, 2023 10:39 pm, edited 1 time in total.
miso
Enthusiast
Enthusiast
Posts: 459
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Draw image to screen with transparency

Post by miso »

You iterate trough your monitors to get screen data, but you store and use the parameters of the last one only. (The primary (0 indexed) is overwritten, when you have more than one monitor.)
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Draw image to screen with transparency

Post by coco2 »

Yes but why is it showing the wrong size when I only have one 4K monitor?
miso
Enthusiast
Enthusiast
Posts: 459
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Draw image to screen with transparency

Post by miso »

Hmm, in that case, I don't have an answer.
User avatar
Fig
Enthusiast
Enthusiast
Posts: 352
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Draw image to screen with transparency

Post by Fig »

You juste have one monitor, but do you happen to have more than one windows desktop ?
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
User avatar
HeX0R
Addict
Addict
Posts: 1197
Joined: Mon Sep 20, 2004 7:12 am
Location: Hell

Re: Draw image to screen with transparency

Post by HeX0R »

change to

Code: Select all

OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0) * DesktopResolutionX(), WindowHeight(0) * DesktopResolutionY(), #False, 0, 0, #PB_Screen_WaitSynchronization)
and enable DPI awareness in compiler options
coco2
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Nov 25, 2013 5:38 am
Location: Australia

Re: Draw image to screen with transparency

Post by coco2 »

I see, it was because I have my desktop set to 150%.

Do you know why when I turn on DPI aware executable I can't alt+tab back to the desktop and it doesn't show the debug window?
Post Reply