SFML community forums

Help => Graphics => Topic started by: BaneTrapper on September 23, 2013, 10:25:43 pm

Title: How to make VertexArray with RenderState semi transparent.
Post by: BaneTrapper on September 23, 2013, 10:25:43 pm
Hello.
I was experimenting with minimap and i am drawing it as vertexArray with RenderState witch only has texture.
My question is how would i set its alpha color to (200) of 255, or 80% or something big so its just transparent?
Using BlendMode gave me weird results... and i think that is not what i am looking for, so any help is apprechiated.
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: Ixrec on September 23, 2013, 10:44:27 pm
Draw your minimap to a rendertexture, then make a semi-transparent sprite which uses the texture from that rendertexture and then draw the sprite to the window?
Title: AW: How to make VertexArray with RenderState semi transparent.
Post by: eXpl0it3r on September 24, 2013, 06:15:44 am
I'm not 100% sure, but each vertex takes a color, thus if you set each vertex's color to {0, 0, 0, 200}, you should be getting the wanted result (I think).
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: Laurent on September 24, 2013, 07:47:29 am
Rather (255, 255, 255, 200), if you want to see the tile's texture ;)
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: BaneTrapper on September 24, 2013, 12:08:34 pm
Rather (255, 255, 255, 200), if you want to see the tile's texture ;)
That is exactly what i want to do.
But i fear i have not explained what i require in detail so i will do it now:
First of all i am drawing a map that has colors (255,255,255,255).
When i am drawing minimap i am actually drawing a map but in other view.
And i want to be able to set minimap transparency.

1: Editing each vertex color to 255,255,255,200 for each minimap draw and to 255,255,255,255 for each Map draw is not efficient at all. So i am looking for something i did not figure out yet.
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: eXpl0it3r on September 24, 2013, 12:30:54 pm
Well you can't draw the same thing twice and hope to change the transparency without changing the color. ;)
I only see a) draw to render texture and set sprite color b) change vertices color. The question you have to ask yourself anyways is, whether you really want to draw the whole map again and then adjust the view, or whether you can to render something specifically for the minimap.
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: BaneTrapper on September 24, 2013, 12:51:23 pm
The question you have to ask yourself anyways is, whether you really want to draw the whole map again and then adjust the view, or whether you can to render something specifically for the minimap.
It seams really easy and efficient to draw map on 2 views. It takes so little cpu usage to do so that i don't mind it.
I just want to add transparency to minimap as optimal option. I personally don't mind the minimap but on my last project i had requests for transparency so they can see more of game so i want to :
Add minimap in different sizes as Slider in options, Add minimap transparency as Slider in options,
Currently i have done the size, but i cant figure out how to make transparency i am missing something.
I am currently looking intro making 2 sf::VertexArray of map... The game currently takes about 15mb on runtime and its pc game so it can go allot above that point imo.
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: Laurent on September 24, 2013, 12:57:15 pm
You should pre-render your whole minimap to a render-texture (it's not that big, is it?), rebuilding it when needed (user changed minimap size in options) -- or render it at maximum size and then just scale it. Then you just have to draw it with a sf::Sprite with color (255, 255, 255, transparency).
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: BaneTrapper on September 24, 2013, 01:12:25 pm
You should pre-render your whole minimap to a render-texture (it's not that big, is it?), rebuilding it when needed (user changed minimap size in options) -- or render it at maximum size and then just scale it. Then you just have to draw it with a sf::Sprite with color (255, 255, 255, transparency).
The map size currently is 1000*1000*4, i do not know what scale "big" is.
I have just made another vertexArray that holds another map with different color.
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: Laurent on September 24, 2013, 01:16:34 pm
Quote
The map size currently is 1000*1000*4, i do not know what scale "big" is.
What is the maximum size of your rendered minimap, in pixels?
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: BaneTrapper on September 24, 2013, 01:44:25 pm
Quote
The map size currently is 1000*1000*4, i do not know what scale "big" is.
What is the maximum size of your rendered minimap, in pixels?
WINDOW_WIDTH = 800, WINDOW_HEIGHT = 600
sf::View viewMinimap is
Code: [Select]
viewMinimap.setViewport(sf::FloatRect(0.74f, 0.01f, 0.25f, 0.25f));
200x150 for minimap render in default but is resizable.
To draw minimap i use same code as i use for Map, i just change the view.

Size goes from +50% - 25%
so X goes from 200 default to 300 max 150 min
and Y goes from 150 default to 225 max 112.5
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: Laurent on September 24, 2013, 02:11:45 pm
But does this 300x225 minimap area shows the whole map, or does it scroll? What I'm interested in is the total size of the minimap in pixels, not what you show of it. To know if you can pre-render it to a sf::RenderTexture safely.
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: BaneTrapper on September 24, 2013, 02:41:19 pm
But does this 300x225 minimap area shows the whole map, or does it scroll? What I'm interested in is the total size of the minimap in pixels, not what you show of it. To know if you can pre-render it to a sf::RenderTexture safely.
Currently its drawing whole map witch is Huge 10k size width and height.
But i will eventually split the map intro small sections to improve performance so your suggestion would be more efficient and one i will use.

Splited map size width and height would be around 640pixels by 640 pixels. 32*32*4 in vertexArray size

Therefore my answer would be the size is 1280x1280 that i would draw to render texture
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: Laurent on September 24, 2013, 02:54:54 pm
1280x1280 pixels is too high for very old graphics cards, but I think it's ok for relatively old graphics cards.
Title: Re: How to make VertexArray with RenderState semi transparent.
Post by: BaneTrapper on September 24, 2013, 07:32:03 pm
1280x1280 pixels is too high for very old graphics cards, but I think it's ok for relatively old graphics cards.
Oh good point.
I have not thought about that...