|
Post by n00b on Dec 7, 2020 16:46:27 GMT -6
That is because 0 for alpha is completely transparent so it is going to show the color of whatever is behind the canvas. If the window clear color is also 0 then it is pretty much going to be black.
If you want some more color try raising the alpha value. The max alpha is 255 so if you want something half way transparent then set the alpha to 128.
|
|
|
Post by rosy on Dec 8, 2020 4:47:57 GMT -6
Then it turns brown ... Which comes down to what I said before that only black is transparent. You cannot have a transparent yellow canvas.
|
|
|
Post by n00b on Dec 8, 2020 8:29:53 GMT -6
Yes you can. But a transparent clear color on a canvas is just going to blend with the color of what is behind it. You can also use SetCanvasAlpha to make the canvas itself transparent which will blend everything drawn on the Canvas with the colors of whats behind it. When you have a transparent color over another color, those 2 colors will make a new color.
Try this example. You can change canvas #0 alpha with Up/Down and canvas #1 alpha with Left/Right. There is a green square drawn on each canvas.
xmax = 1366 ymax = 768 title$ = "Clear Colour Test"
canvas1_alpha = 0 canvas2_alpha = 0
WindowOpen(0,title$,WINDOWPOS_CENTERED,WINDOWPOS_CENTERED,xmax,ymax,0) CanvasOpen(0,xmax,ymax,0,0,xmax,ymax,1) CanvasOpen(1,570,420,54,18,570,420,1)
'Canvas 1 by default will be drawn behind Canvas 0 'To change this we use the SetCanvasZ function SetCanvasZ(0, 2)
SetColor(RGB(255,255,255)) Locate(50, 10) PrintS("Press Up/Down to Change Canvas #0 Alpha") Locate(50, 20) PrintS("Press Left/Right to Change Canvas #1 Alpha") While Not Key(K_ESCAPE)
If Key(K_UP) And canvas1_alpha < 255 Then canvas1_alpha = canvas1_alpha + 1 ElseIf Key(K_DOWN) And canvas1_alpha > 0 Then canvas1_alpha = canvas1_alpha - 1 End If If Key(K_RIGHT) And canvas2_alpha < 255 Then canvas2_alpha = canvas2_alpha + 1 ElseIf Key(K_LEFT) And canvas2_alpha > 0 Then canvas2_alpha = canvas2_alpha - 1 End If
Canvas(0) setClearColor(rgba(255,128,0,canvas1_alpha)) clearcanvas
SetColor(RGB(0, 255, 0)) RectFill(80, 80, 20, 20) canvas(1) setClearColor(rgba(255,255,0,canvas2_alpha)) clearcanvas
SetColor(RGB(0, 255, 0)) RectFill(20, 20, 20, 20)
'Change Clear Color back before UPDATE SetClearColor(0) update() Wend
|
|
|
Post by rosy on Dec 9, 2020 12:55:14 GMT -6
What cleans the CLS? I did at the beginning:
setClearColor (rgb (255,255,255))
CLS
And I still see black
|
|
|
Post by n00b on Dec 9, 2020 14:20:55 GMT -6
Did you run update after that?
|
|
|
Post by rosy on Dec 9, 2020 15:27:46 GMT -6
Yes, the window turns white, but when the transparent canvas comes in, it turns black
|
|
|
Post by n00b on Dec 9, 2020 16:03:09 GMT -6
Would you mind sharing your code?
|
|
|
Post by rosy on Dec 9, 2020 16:14:24 GMT -6
After windowsopen, in the 10th line I enter these 2 lines ...
|
|
|
Post by n00b on Dec 10, 2020 8:45:36 GMT -6
If all you want is a white background behind your canvases then just set your clear color to white before update.
Try this:
xmax = 1366 ymax = 768 title$ = "Clear Colour Test" canvas1_alpha = 0 canvas2_alpha = 0 WindowOpen(0,title$,WINDOWPOS_CENTERED,WINDOWPOS_CENTERED,xmax,ymax,0) CanvasOpen(0,xmax,ymax,0,0,xmax,ymax,1) CanvasOpen(1,570,420,54,18,570,420,1) 'Canvas 1 by default will be drawn behind Canvas 0 'To change this we use the SetCanvasZ function SetCanvasZ(0, 2) SetColor(RGB(255,100,100)) Locate(50, 10) PrintS("Press Up/Down to Change Canvas #0 Alpha") Locate(50, 20) PrintS("Press Left/Right to Change Canvas #1 Alpha") While Not Key(K_ESCAPE) If Key(K_UP) And canvas1_alpha < 255 Then canvas1_alpha = canvas1_alpha + 1 ElseIf Key(K_DOWN) And canvas1_alpha > 0 Then canvas1_alpha = canvas1_alpha - 1 End If If Key(K_RIGHT) And canvas2_alpha < 255 Then canvas2_alpha = canvas2_alpha + 1 ElseIf Key(K_LEFT) And canvas2_alpha > 0 Then canvas2_alpha = canvas2_alpha - 1 End If Canvas(0) setClearColor(rgba(255,128,0,canvas1_alpha)) clearcanvas SetColor(RGB(0, 255, 0)) RectFill(80, 80, 20, 20) canvas(1) setClearColor(rgba(255,255,0,canvas2_alpha)) clearcanvas SetColor(RGB(0, 255, 0)) RectFill(20, 20, 20, 20) 'Change Clear Color back before UPDATE setClearColor (rgb (255,255,255)) update() Wend
|
|
|
Post by rosy on Dec 10, 2020 9:10:16 GMT -6
So Update clears the window ...
|
|
|
Post by rosy on Nov 6, 2021 8:21:23 GMT -6
I wanted to change the color of canvas 2. After setting SetClearColor to black again and cleaning Canvas 0 - it stopped being transparent. How to restore transparency?
|
|
|
Post by n00b on Nov 8, 2021 8:04:12 GMT -6
You should be able to use RGBA() when setting the color.
However, I would recommend just drawing a rectangle the size of the canvas for what you are doing. That way you won't have to interfere with the Canvas transparency.
|
|
|
Post by rosy on Nov 8, 2021 9:29:24 GMT -6
You said to avoid "primitives"
|
|
|
Post by n00b on Nov 8, 2021 9:49:56 GMT -6
You said to avoid "primitives" You can try setting clear color with RGBA first. But you shouldn't take a performance hit with one rectangle. The reason I suggest not using them is most of the primitives are drawing the shape to a buffer in RAM and then pushing it to video memory. I can probably speed this up in the future by moving from SDL2 to OpenGL.
|
|
|
Post by rosy on Nov 8, 2021 14:45:17 GMT -6
I don't know if the number of rectangles or their size matters.
|
|