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

Author Topic: Text vertices getter and new update method for Texture  (Read 4113 times)

0 Members and 1 Guest are viewing this topic.

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Text vertices getter and new update method for Texture
« on: September 14, 2015, 03:27:36 am »
1. Add a way to get sf::Text vertices. It seems to me like a good thing to have to allow caching Text vertices. I have a bunch of quasi-gui code that basically uses only colored Triangles and colored Text that is always same size, style and font. If I could get vertices from sf::Text I could draw it all with a single call.
2. Since 32 bit int is now alternative color representation (kinda, via the Color constructor) for SFML I think there should also be a complementary method to update a texture from an array of unsigned (casting the pointer to unsigned char will not work because it might swap channels).
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Text vertices getter and new update method for Texture
« Reply #1 on: September 14, 2015, 09:01:10 am »
Quote
1. Add a way to get sf::Text vertices.
sf::Text only? If we do that, it should be done for all drawable entities. But I'm not a big fan of exposing internal stuff, especially pointers to stuff that may change at any time.

Quote
2. Since 32 bit int is now alternative color representation (kinda, via the Color constructor) for SFML I think there should also be a complementary method to update a texture from an array of unsigned
That may be really slow, so I'm not sure we should explicitly support it.
Laurent Gomila - SFML developer

Mario

  • SFML Team
  • Hero Member
  • *****
  • Posts: 879
    • View Profile
Re: Text vertices getter and new update method for Texture
« Reply #2 on: September 14, 2015, 10:34:04 am »
Hm... I'd actually consider it rather interesting being able to construct a sf::VertexArray from other sf::Drawables. Sure, there's still the danger of the internal representation changing between versions (like strategy used to draw a quad), but overall I could imagine some interesting ways to extract/combine multiple things.

I could even imagine some way to combine multiple drawables, although that might be something for later (SFML3?).

For example, rather than building a tile map from a sf::VertexArray, someone could just set a sf::Sprite to the correct texture rectangle and position, then add it to a sf::VertexArray, which acts as a buffer.

Something like this (let's ignore optimization like clipping for now):

sf::VertexArray tileMap;
for (int y = 0; y < height; ++y) {
  for (int x = 0; x < width; ++x) {
    sf::Sprite tile;
    // set texture, texture rect, etc.
    tile.setPosition(x * tilewidth, y * tileheight);
    tileMap += tile; // vertices are copied into the vertex buffer
  }
}

// later on:
window.draw(tileMap); // draws the whole tile map in one batch
 

However, I don't think setters should be added, especially considering the basic shapes aren't defined by their vertices and there's no simple way to solve odd cases, like assigning an irregular shape to a circle or something like that.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Text vertices getter and new update method for Texture
« Reply #3 on: September 14, 2015, 10:44:52 am »
If we talk about getting a copy of the vertices, then yes that's already much better.

But here we are already discussing a possible solution to a more general problem: batching. I think we should discuss this feature, which will possibly yields solutions other than giving public access to drawables' vertices. There are already batching classes available on the wiki, they could serve as a starting point.
Laurent Gomila - SFML developer

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: Text vertices getter and new update method for Texture
« Reply #4 on: September 14, 2015, 05:56:34 pm »
Quote
sf::Text only? If we do that, it should be done for all drawable entities. But I'm not a big fan of exposing internal stuff, especially pointers to stuff that may change at any time.
Only Text because it's so complex to construct its' vertices (100-150 lines of code). Making rectangles, circles or sprites out of vertices is easy enough already.
Back to C++ gamedev with SFML in May 2023

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Text vertices getter and new update method for Texture
« Reply #5 on: September 14, 2015, 05:57:54 pm »
Quote
Only Text because it's so complex to construct its' vertices (100-150 lines of code). Making rectangles, circles or sprites out of vertices is easy enough already.
I know, but if we provide this feature there's no reason to do it only for one class.
Laurent Gomila - SFML developer

 

anything