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

Author Topic: Problem creating non-pixelated texture with sf::VertexArray, sf::RenderTexture  (Read 3230 times)

0 Members and 1 Guest are viewing this topic.

hypnotix

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
   Given a number of polygons in an sf::VertexArray(sf::PrimitiveType::Triangles), the goal is to be able to draw it with diagonal stripes, as seen in the first attached image. What's seen there is made with an sf::RenderTexture and an sf::VertexArray(sf::PrimitiveType::Lines) by translating and drawing a diagonal line ((0, 0), (64, 64)) on the RenderTexture which is of size (64, 64). This appears to work, however, and here comes the problem, when zooming, the stripes get pixelated, as seen in the second image. Given that zooming is done with the help of an sf::View object, how can I go about ensuring that the texture remains nice and crisp no matter how much it has been zoomed?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
The render texture is a fixed size and you're zooming in on that 'low-resolution' texture.

  • turning on smooth for the rendertexture may help (can impact performance),
  • you can use a larger render texture to cover more zoomed in cases. You could stick with just the high-resolution one, or switch amongst a few depending on the zoom level, or
  • you could just recreate the render texture at the required size whenever the zoom changes and redraw the lines.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

hypnotix

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
So, for the third option, I should apply the view to the RenderTexture and draw the lines then?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
I can't say that I'm certain of what your current approach is so I don't know what I'd suggest.
For that third option, I was thinking that drawing it larger on a larger render texture would be less jagged but I'm unsure how you're using the render texture exactly. (you are already drawing them onto a render texture; I was suggesting recreating it at a larger size).
Are the lines themselves images, or are they drawn by SFML? If they're images, the only option would be to use higher resolution line images.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

hypnotix

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
The lines are made with an sf::VertexArray, so yeah. The thing is, the final goal is to have the same width stripes and at the same distance from each other as seen in the second pic, but without them being jagged.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
You're drawing a line on a render texture of size 64x64. When you're zoomed in and everything is twice as large, the render texture should be 128x128 and the line can be drawn on there.

Are you using the render texture as the texture for the map? If so, remember to update the texture co-ordinates to match the new render texture size.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

hypnotix

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
Well, currently, each vertex's texture coordinate is the same as its position, how exactly should I update it to match?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Multiply them.
At normal scale, the same co-ordinates.
At double scale, the texture co-ordinates are doubled their positions etc..

(I assume you're using texture repeating)
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

hypnotix

  • Newbie
  • *
  • Posts: 28
    • View Profile
    • Email
So, in short, when I zoom, I re-create the texture with textureSize.x*zoomFactor, textureSize.y*zoomFactor, then draw the lines with a width of lineWidth *= zoomFactor and at a distance of lineDistance *= zoomFactor and also go through each vertex and make it so vertex.texCoords *= zoomFactor. That about right?