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

Recent Posts

Pages: 1 ... 6 7 [8] 9 10
71
Instead of completely reloading the font from file, you could make a copy of the sf::Font instance before rendering characters, and use it to reset your working sf::Font instance from time to time by assigning to it. This will reuse the same underlying FreeType objects under the hood but start with new empty textures.
72
I am making a program using SFML on an old laptop, and its task is to print all Unicode characters, just like in this video:

However, after running for a while, the program will show the error:
"Failed to add a new character to the font: the maximum texture size has been reached."
I noticed that Text::setString() caches the textures of the characters rendered in the text into memory to speed up the next use of those textures, but my program clearly does not need this feature.

My current solution is:

Text::setString(character);
if (character % 500 == 0) {
    mainFont.loadFromFile(currentFont);
}

This is clumsy and wastes performance and memory.

Is there a solution?
One idea I had was to use FreeType to render the characters directly, but I feel like this would waste SFML's potential.

73
General / Why~400 FPS difference between these two methods of building a vertex array
« Last post by IGD on November 21, 2024, 12:17:42 am »
When I build my vertex array using this code, I get like 2-350 FPS:
                sf::Vertex v0(sf::Vector2f(position.x * size.x, position.y * size.y), sf::Vector2f((tu * size.x)+5, (tv * size.y)+5));
                sf::Vertex v1(sf::Vector2f((position.x + 1) * size.x, position.y * size.y), sf::Vector2f(((tu + 1) * size.x)-5, (tv * size.y)+5));
                sf::Vertex v2(sf::Vector2f(position.x * size.x, (position.y + 1) * size.y), sf::Vector2f((tu * size.x)+5, ((tv + 1) * size.y)-5));
                sf::Vertex v3(sf::Vector2f(position.x * size.x, (position.y + 1) * size.y), sf::Vector2f((tu * size.x)+5, ((tv + 1) * size.y)-5));
                sf::Vertex v4(sf::Vector2f((position.x + 1) * size.x, position.y * size.y), sf::Vector2f(((tu + 1) * size.x)-5, (tv * size.y)+5));
                sf::Vertex v5(sf::Vector2f((position.x + 1) * size.x, (position.y + 1) * size.y), sf::Vector2f(((tu + 1) * size.x)-5, ((tv + 1) * size.y)-5));


                m_vertices.append(v0);
                m_vertices.append(v1);
                m_vertices.append(v2);
                m_vertices.append(v3);
                m_vertices.append(v4);
                m_vertices.append(v5);
 

BUT when I build that same vertex array with this code, I get 4-800 FPS:
sf::Vertex* triangles = &m_vertices[(i + j * width) * 6];

                // define the 6 corners of the two triangles
                triangles[0].position = sf::Vector2f(i * tileSize.x, j * tileSize.y);
                triangles[1].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                triangles[2].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
                triangles[3].position = sf::Vector2f(i * tileSize.x, (j + 1) * tileSize.y);
                triangles[4].position = sf::Vector2f((i + 1) * tileSize.x, j * tileSize.y);
                triangles[5].position = sf::Vector2f((i + 1) * tileSize.x, (j + 1) * tileSize.y);

                // define the 6 matching texture coordinates
                triangles[0].texCoords = sf::Vector2f(tu * tileSize.x+5, tv * tileSize.y+5);
                triangles[1].texCoords = sf::Vector2f((tu + 1) * tileSize.x-5, tv * tileSize.y+5);
                triangles[2].texCoords = sf::Vector2f(tu * tileSize.x+5, (tv + 1) * tileSize.y-5);
                triangles[3].texCoords = sf::Vector2f(tu * tileSize.x+5, (tv + 1) * tileSize.y-5);
                triangles[4].texCoords = sf::Vector2f((tu + 1) * tileSize.x-5, tv * tileSize.y+5);
                triangles[5].texCoords = sf::Vector2f((tu + 1) * tileSize.x-5, (tv + 1) * tileSize.y-5);
 

I would understand the FPS difference if the function was called each loop, but it is only called once when initializing. Why in the world is the FPS so different???
74
Graphics / Re: Drawing a subset of a vertex array?
« Last post by smurf on November 20, 2024, 03:04:29 pm »
Thanks!

But I'm using SFML.Net and it doesn't seem to have that in C# :(
75
Graphics / Re: Drawing a subset of a vertex array?
« Last post by fallahn on November 20, 2024, 10:52:17 am »
You can use the [] operator of VertexArray

window.draw(&vertices[offset], count, sf::Triangles);
 
76
Graphics / Drawing a subset of a vertex array?
« Last post by smurf on November 19, 2024, 04:40:51 pm »
I have a particle system where sparks burn out over time.
Instead of creating a brand new VertexArray every frame with the burnt-out particles removed, I wanted to re-use the same VertexArray and just shift things around so that the burnt-out ones are on the end, and then not draw them by passing a count parameter to the Draw function. The idea is by not creating a new VertexArray every frame this should be much more performant.

But it seems the window.Draw function does not quite give me the overload I need.

renderWindow.Draw(vertexArray, 0, vertexCount, vertexArray.PrimitiveType);

This is invalid code because the first parameter needs to be an array of vertices instead of a vertexArray  ::)

but the VertexArray class does not expose its internal array of vertices. So any way I can do this?
77
Graphics / Re: Colour individual triangles in a sf::TriangleStrip
« Last post by eXpl0it3r on November 19, 2024, 01:41:07 pm »
It's not possible with normal vertex coloring.

Not sure if there's some way with a shader, but that is usually the answer to anything you want to achieve graphics-wise.
In theory you could also use some texturing, mapping the triangle to a single color pixel. Not sure if that performs and won't cause some fun texture bleeding.
78
DotNet / How to generate SFML.Net documentation
« Last post by johnnywz00 on November 17, 2024, 05:35:36 am »
Never mind... I finally got AI to teach me how to generate it. I sure lost some hair in the process, though. Here is what I did. Happy are those who already knew how to generate documentation.

Download source for Doxygen (1.12.0 at the time of posting)
Build with CMake. Oh, wait... your version of "bison" isn't good enough for Doxygen? Download bison 2.7. (On Mac I used the Terminal command `brew install bison@2.7`). What, CMake still thinks your version of "bison" isn't good enough? Click on CMake's "Environment" button (GUI CMake), and where you see PATH, enter the full path to where bison 2.7 is located, and then a colon, BEFORE the paths that are currently typed there. If you used `brew install`, this path is likely to be something like `/opt/homebrew/Cellar/bison@2.7/2.7.1_1/bin`.
Now CMake should configure correctly and generate a Makefile.
In Terminal navigate to the Doxygen/build folder and enter `make`.
If you want you can install the `doxygen` binary somewhere in your PATH like /usr/local/bin. Or you can use it right where it sits and include its full path to invoke it.
You should have the source code download for SFML.Net. In Terminal, navigate to the `src` folder within that folder. Once there, enter:
`/path/to/doxygen -g Doxyfile.sfml.net`
Then open that file with a text editor. The AI recommended that I fill out the following fields: there may be more that you'll want, but this should at least give you something. The default generated Doxyfile is large, so just use the Find command to look for these keywords:

PROJECT_NAME = "SFML.Net"
PROJECT_BRIEF = "Simple and Fast Multimedia Library for .NET"
INPUT = /path/to/sfml.net/source/code   (if the Doxyfile is located in .../SFML.Net.x.x.x/src/ this can be blank)
FILE_PATTERNS = *.cs
RECURSIVE = YES
OUTPUT_DIRECTORY = ./docs
GENERATE_HTML = YES
HTML_OUTPUT = html
EXTRACT_ALL = YES
EXTRACT_PRIVATE = YES
EXTRACT_PACKAGE = YES
EXTRACT_STATIC = YES
GENERATE_LATEX = NO
HAVE_DOT = NO

Save and close the Doxyfile.
In Terminal type:
`/path/to/doxygen Doxyfile.sfml.net`
There should now be a "docs" folder located within "src". Go inside "docs", make an alias/symlink of "index.html", and put that alias somewhere easy to access.
You've finally got C# SFML Docs, and a lot less hair.
79
DotNet / .NET documentation help
« Last post by johnnywz00 on November 16, 2024, 03:52:30 pm »
I am trying to learn C# for a potential job opportunity in the future. I have played around with C++ SFML for several years and I'd really like to just get my feet wet by more or less translating some of my existing projects to C#/SFML.Net.
Could anyone send me/point me to the C# API docs *in HTML form*? Or give me clear step by step instructions how to produce them? All that I see docwise that came with the .Net download are four .xml files corresponding to each of the main four SFML libraries. I have wasted an entire free evening trying to figure out how to generate or get a hold of a simple doc system where I click on index.html and from there everything is linked and displayed properly in a browser. Can the C# development environment display them somehow? I tried downloading Doxygen source but first it talked about some obscure command line program that was out of date even though I have just updated my new Mac to the latest Sequoia. After some tedious wading and arcane online research, I got CMake to recognize a newer version of bison rather than the old one, and got Doxygen built. And then I was lost again, generating a default Doxyfile from the Doxygen binary, and seeing that its contents were as long as an encyclopedia and I was meant to fill it out.
80
General discussions / Re: about the 2.x syntax and the document
« Last post by eXpl0it3r on November 15, 2024, 10:24:03 am »
Updating of the tutorial and documentation for SFML 3 is under way.

As SFML 3 hasn't been released yet, the website hasn't been updated for it.
The new tutorials are already live, but not linked to, you can find them here: https://www.sfml-dev.org/tutorials/3.0/
Pages: 1 ... 6 7 [8] 9 10