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

Author Topic: Drawing sf::RectangleShape with texture into sf::RenderTexture  (Read 2163 times)

0 Members and 1 Guest are viewing this topic.

Daedheldir

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hi everyone!

I have a question about sf::RenderTexture. I'm trying to create perlin noise tile map, but I want each tile to have a noise texture. It works when I draw all the tiles through render window, but having 1024^2 iterations in each drawing cycle isn't desireable... So I decided to draw them into sf::RenderTexture first, and then use that texture to draw only once, but when I tried that, the noise texture on the tiles is gone. Here is my code:

Code:
(click to show/hide)

Images:

Current effect when drawing the render texture
https://imgur.com/gO4Yy84

Desired effect
https://imgur.com/3pTNzn9

Am I missing something obvious?
« Last Edit: May 31, 2018, 12:40:33 pm by Daedheldir »
Sorry for any misspellings, english isn't my native language : (

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10989
    • View Profile
    • development blog
    • Email
Re: Drawing sf::RectangleShape with texture into sf::RenderTexture
« Reply #1 on: May 31, 2018, 01:56:28 pm »
I'm not certain, but you may need to adjust the texture rect of the shape. You can also achive this by add true as 2nd parameter when setting the texture.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Daedheldir

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Drawing sf::RectangleShape with texture into sf::RenderTexture
« Reply #2 on: May 31, 2018, 09:37:13 pm »
Still doesn't work :( In the meantime I swapped the rectangle shape for vertices because memory allocation started to become problematic, but even with vertices I can't draw them into render texture, while still using the  noise texture :(

EDIT:
I've just wrote a simple program that sets texture to a rectangle and then draws it into render texture, the render texture is then set to another rectangle, which is then drawn into the render window, and the result is a white rectangle, so I assume that the render texture only saves the shape and its color, not its texture :/ Is it intended ?
« Last Edit: May 31, 2018, 09:56:56 pm by Daedheldir »
Sorry for any misspellings, english isn't my native language : (

Daedheldir

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Drawing sf::RectangleShape with texture into sf::RenderTexture
« Reply #3 on: June 04, 2018, 11:49:59 am »
I have found out that because my tile is 1 pixel wide it only draws one pixel from the texture regardless of the texture rect, not sure how to change that...
Sorry for any misspellings, english isn't my native language : (

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10989
    • View Profile
    • development blog
    • Email
Re: Drawing sf::RectangleShape with texture into sf::RenderTexture
« Reply #4 on: June 04, 2018, 11:59:56 am »
Well if your shape is only one pixel wide, how should it draw more? If you want to display more, make the shape larger.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Daedheldir

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Drawing sf::RectangleShape with texture into sf::RenderTexture
« Reply #5 on: June 04, 2018, 02:36:48 pm »
The size of the shape wasn't actually the problem, the size of the render texture was, it was unable to contain all the detail I wanted it to. Thank you very much eXpl0it3r for your help!
Sorry for any misspellings, english isn't my native language : (

 

anything