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

Author Topic: Drawing sf::Vertex with Primitive Type sf::Points two different ways  (Read 2580 times)

0 Members and 1 Guest are viewing this topic.

nathanmyersc

  • Newbie
  • *
  • Posts: 11
    • View Profile
Hello I have an issue in a 2d sidescrolling-kinda game im making.

Currently i store the static tiles in a RenderTexture and have a sprite
that uses the rendertexture as a texture and draw that to the screen.
And i have an effect where when you take damage or enemy takes damage they bleed.
And blood particles of the type sf::Vertex sf::Points fly off in random directions.
And when the particles hit a tile pixel not covered in blood it adds a copy of itself to a
array inside the tile which i draw when i call the draw function of the tile.
So this effect works with the static tiles i can update the rendertexture and it displays fine.
But i have tiles that move also. And for dynamic tiles i dont store them in a renderTexture.
i just call their draw function with the window as the renderTarget and it draws itself and all
its blood particles.
Well this is where the issue occurs. Because for some reason the pixels of blood are alot smaller when
i draw them directly to the window as opposed to when i draw them to the renderTexture.

I am using a 0.5 zoom with the sf::View::zoom feature. And i am considering maybe the zoom
has something to do with it in some way?

EDIT: i just played around a bit. i normally use a 0.5 zoom but i created a toggle between 1 and 0.5
and went in the game at 1 and got blood on a moving platform and then zoomed in.
And i found that as i zoomed in the pixels remain proportional to the zoom. aka shrinking when i zoom in.
Why is that?

The only difference between the sf::Vertex sf::Points is one is drawn to a renderTexture and the other directly to the window.

Also note i am not using the sf::View::Zoom feature actually i am using a custom function that uses
sf::View::setSize() with a float between 0 and 1 and i times that by variables i have stored for the window size.

Any ideas?

I tried messing around with the bits per pixel and antialiasing with different settings no luck.

EDIT2: to clarify a little the renderTexture Blood Pixels are the same size as the pixels of the tile.
i am zoomed in on the sf::View and everything is good. But it is not so for the sf::vertexs i am drawing directly to the screen.
« Last Edit: May 01, 2020, 09:17:26 am by nathanmyersc »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Hi!

First, I should just mention that using sf::View's zoom function changes the size itself but to have absolute values (as you clearly need) you need to set the size directly (as you are doing).

Anyway, when you zoom into a view (its size is smaller), everything is draw larger, including sprites (and includes your 'render sprite'). When sprites are drawn larger, their textures are stretched to fit. This means that the pixels on the render texture are stretched to fit the view's zoomed in size.
However, whenever you use sf::PrimitiveType of Points, it will always use the size of the actual pixel of that render target. Thus, will always be a single pixel on the window you draw it to.
As mentioned above, it is a single pixel on the render texture too but is enlarged by zooming in to the sprite that draws it.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

nathanmyersc

  • Newbie
  • *
  • Posts: 11
    • View Profile
Thanks. Thats an obscure rule.

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
I suppose, for clarity, I should say that points are always pixels on the render target.

If you would like to draw directly to a target (for example, the window) with anything different from a pixel, you can use a different primitive. For example, quads work nicely for "larger pixels".
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

nathanmyersc

  • Newbie
  • *
  • Posts: 11
    • View Profile
I eventually want to figure out how to use vertexes to group draw calls to the same sprite sheet into one call.

But i have to figure out coloring and rotation and flipping.
How do you rotate quads in a vertex aray?

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
If you are batching already transformed objects, you can just apply their transforms to the points. Something like:
sf::Vector2f firstPoint{ object.getTransform().transformPoint(object.getPoint(0u)) };
I can't remember if get point would get the global or local position. If it's local, this transformation is required. If it's global, you can just get them and the transformation will already be applied.

Each sf::Vertex has a colour attribute. Just colour each of the vertices of each primitive with the same colour. e.g. quads: all four vertices.

Flipping can be done by swapping vertices or, if it's a textured quad, swapping the texture co-ordinates.

Rotating can be done automatically as mentioned above. However, if need to do manually, you can either calculate the maths directly or use an sf::Transform.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

 

anything