Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: How to make VertexArray with RenderState semi transparent.  (Read 5333 times)

0 Members and 1 Guest are viewing this topic.

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
How to make VertexArray with RenderState semi transparent.
« 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.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #1 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?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11037
    • View Profile
    • development blog
    • Email
AW: How to make VertexArray with RenderState semi transparent.
« Reply #2 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).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #3 on: September 24, 2013, 07:47:29 am »
Rather (255, 255, 255, 200), if you want to see the tile's texture ;)
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #4 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.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11037
    • View Profile
    • development blog
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #5 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #6 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.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #7 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).
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #8 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.
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #9 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?
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #10 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
« Last Edit: September 24, 2013, 01:47:21 pm by BaneTrapper »
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #11 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.
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #12 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
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #13 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.
Laurent Gomila - SFML developer

BaneTrapper

  • Full Member
  • ***
  • Posts: 213
  • Do you even see this, i dont need it.
    • View Profile
    • Email
Re: How to make VertexArray with RenderState semi transparent.
« Reply #14 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...
BaneTrapperDev@hotmail.com Programing, Coding
Projects: Not in development(unfinished/playable):
http://en.sfml-dev.org/forums/index.php?topic=11073.msg76266#msg76266
UP and in Development: The Wanderer - Lost in time
http://en.sfml-dev.org/forums/index.php?topic=14563.0