DrawAlphaImage - drawing in wrong order

Just starting out? Need help? Post your questions and find answers here.
KianV
User
User
Posts: 16
Joined: Thu Dec 26, 2019 3:31 pm

DrawAlphaImage - drawing in wrong order

Post by KianV »

Hi all,
I have created 4 transparent images which need to be layered in a specific order.
When I draw them onto the background using the following code:

Code: Select all

      DrawAlphaImage(ImageID(#calque1),(188),100)
      DrawAlphaImage(ImageID(#calque2),(188),100)
      DrawAlphaImage(ImageID(#calque3),(188),100)
      DrawAlphaImage(ImageID(#calque4),(188),100)         
the final layer 'calque4' always appears behind the others.
I have even tried drawing layer 4 onto layer 3 first, but still the same behaviour :?

Can anyone provide an explanation for this ?

Thanks in advance,
Kian
User avatar
STARGÅTE
Addict
Addict
Posts: 2228
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: DrawAlphaImage - drawing in wrong order

Post by STARGÅTE »

I can't confirm this report.

In this code, the drawing order is exactly the oder of the call of DrawAlphaImage()

Code: Select all

Enumeration
	#Window
	#Gadget
	#Image1
	#Image2
	#Image3
	#Image4
EndEnumeration

Define Image.i

For Image = #Image1 To #Image4
	If CreateImage(Image, 128, 128, 32, #PB_Image_Transparent)
		If StartDrawing(ImageOutput(Image))
			DrawingMode(#PB_2DDrawing_AlphaBlend)
			Select Image
				Case #Image1
					Box(0, 0, 128, 128, $FF0000FF)
				Case #Image2
					Box(16, 16, 96, 96, $FF00FF00)
				Case #Image3
					Box(32, 32, 64, 64, $FFFF0000)
				Case #Image4
					Box(48, 48, 32, 32, $FF000000)
			EndSelect
			StopDrawing()
		EndIf
	EndIf
Next

OpenWindow(#Window, 0, 0, 800, 450, "Canvas Gadget", #PB_Window_MaximizeGadget|#PB_Window_MaximizeGadget|#PB_Window_SizeGadget|#PB_Window_ScreenCentered)
CanvasGadget(#Gadget, 0, 0, WindowWidth(#Window), WindowHeight(#Window), #PB_Canvas_Keyboard)
If StartDrawing(CanvasOutput(#Gadget))
	DrawAlphaImage(ImageID(#Image1), 64, 64)
	DrawAlphaImage(ImageID(#Image2), 64, 64)
	DrawAlphaImage(ImageID(#Image3), 64, 64)
	DrawAlphaImage(ImageID(#Image4), 64, 64)
	StopDrawing()
EndIf

Repeat
	Select WaitWindowEvent()
		Case #PB_Event_CloseWindow
			Break
	EndSelect
ForEver

End
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
KianV
User
User
Posts: 16
Joined: Thu Dec 26, 2019 3:31 pm

Re: DrawAlphaImage - drawing in wrong order

Post by KianV »

Your code works correctly for me also.
I don't know if it makes any difference but the 'background' I am merging them onto is another (non.transparent) image, rather than a canvas.
Little John
Addict
Addict
Posts: 4786
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: DrawAlphaImage - drawing in wrong order

Post by Little John »

As always: Posting a short executable code that demonstrates the problem would help a lot.
KianV
User
User
Posts: 16
Joined: Thu Dec 26, 2019 3:31 pm

Re: DrawAlphaImage - drawing in wrong order

Post by KianV »

Unfortunately I cannot create a small bit of code which does the same.
I did indeed write a small example, but it behaves exactly as it should. The program which it is part of is very large.
I was hoping that at some point someone had come across something similar and had a eureka moment.
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: DrawAlphaImage - drawing in wrong order

Post by IceSoft »

KianV wrote: Tue Jul 15, 2025 7:38 pm Unfortunately I cannot create a small bit of code which does the same.
I did indeed write a small example, but it behaves exactly as it should. The program which it is part of is very large.
I was hoping that at some point someone had come across something similar and had a eureka moment.
Check your code. There is the problem. I think you draw sprites anywhere again.
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4953
Joined: Sun Apr 12, 2009 6:27 am

Re: DrawAlphaImage - drawing in wrong order

Post by RASHAD »

Hi
Most probably you have a conflict with enumeration or you are using ImageID(#calque4) in other place before or after
Check your ImageID()
Egypt my love
KianV
User
User
Posts: 16
Joined: Thu Dec 26, 2019 3:31 pm

Re: DrawAlphaImage - drawing in wrong order

Post by KianV »

IceSoft was kind of right and lead me to the solution.
The code which drew the layers was erroneously called twice. The first time was after drawing the 'top' layer (calque4). Essentially the program is reversing the order of the layers, so it drew the top layer, added it to the background. cleared the layer graphics then it drew the lower layers before outputting them on top.
My thanks to everyone who contributed to what was a slightly vaguely presented problem.
Post Reply