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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Hapax

Pages: 1 ... 4 5 [6] 7 8 ... 225
76
General / Re: Zooming in and out makes line flicker
« on: January 02, 2024, 09:38:56 pm »
Good to hear that your problem has been fixed. :)

Not sure if it's "fixed" as such though. If you're drawing lines, they will always be there and never flicker. The quads are being "hidden" by those lines and 'may' be exposed on other occasions where the lines are on the edge of a pixel.

I'm not sure I under what you mean by drawing the quads because you want them to be clickable. You can, of course, just test the rectangle area for mouse positions. And, if you mean that you need it to display something when it's clicked (or hovered over), you can simply draw those cells that need to have something. This means you can not draw the others. You can do this by resizing the vertex array after calculating how many cells will be displayed and then just adding those ones.

Since your grid is so strict and even, it should be simple enough to calculate if one of those is outside of the window. Indeed, you can use rectangle collision to check this (SFML's FloatRects can do this; it's called intersects). Check the cell's rectangle against the window's rectangle (actually the view's rectangle).
Then, combining with the things I mentioned in the previous paragraph, you can only draw to the cells in range (by resizing and only adding the ones that are in range).


As an aside, if you would like to use a tile map that can do this automatically, you could try:
https://github.com/Hapaxia/CheeseMap/wiki
(https://en.sfml-dev.org/forums/index.php?topic=29172.0)
You could use Cheese Map to display your map and then draw the lines around it.
It automatically "culls" cells outside of the view. You can also have de-activated cells that aren't displayed if you'd like.

77
General / Re: window.display() is very slow with vertex array
« on: January 02, 2024, 09:27:15 pm »
Aw, nice to see that that fixed it. :)

Not sure why but maybe your particular driver is not happy with all of those quads sharing so many vertices and gets confused when trying to decide which one it should be ???

78
General / Re: window.display() is very slow with vertex array
« on: January 02, 2024, 07:45:48 pm »
I tested it as-is and only experienced time output (to console) of zero, sorry.

Oh, but I did notice that I don't think your squares are what you think they are.
Remember to multiply every component with CELL_SIZE. ;)
It shouldn't affect what display is doing but it should make what you see an actual grid of squares.
If you change the first vertex to this line, the error is a little more obvious:
va.append({ sf::Vector2f((float)j * CELL_SIZE, (float)i * CELL_SIZE), sf::Color::Red });

79
General / Re: I can't use sfml library with Cmake
« on: January 02, 2024, 07:31:19 pm »
If you want to avoid using CMake, you'll need to prepare it for yourself and there are tutorials here for that too.

You've mentioned your OS is Windows 10 (in one of your other separate posts) so, presuming you're using Visual Studio, you can follow this tutorial:
https://www.sfml-dev.org/tutorials/2.6/start-vc.php

The SFML download you'll need is "Visual C++ 17 (2022) - 64-bit" from here:
https://www.sfml-dev.org/download/sfml/2.6.1/

80
General / Re: Zooming in and out makes line flicker
« on: January 02, 2024, 07:21:44 pm »
A vertex array allows you to draw many triangles at once rather than a couple (or so) at a time (like for a rectangle shape) so improves performance. It doesn't, however, change the way those triangles are calculated so vertex arrays don't automatically solve floating point ambiguities.

You would still need to apply a method (one or more I mentioned above or maybe something else you can find or think of!) to overcome those issues.

81
SFML development / Font/Text Direction
« on: December 30, 2023, 05:59:46 pm »
Spending a bit of time around the SFML text rendering recently, I have noticed that it's locked in to a horizontal direction.
After checking, it looks like FreeType does provide a 2-dimensional (vector) advance but SFML only uses the x component - even in Font/Glyph i.e. it's not just Text ignoring it, it's not available from Font so even a custom text renderer would not be able to use it. This makes Font useless for any non-horizontal direction text renderer.

My suggestion is - at least at first - expose the 2D advance in Font/Glyph allowing separate renderers to use all of the font.
(by simply changing advance to Vector2f instead of float)



Following that, Text could be expanded to also be able to handle it properly. This isn't required but is an option. However, exposing the 2D advance is required before that can even be considered. Of course, exposing it means that Text would need to adjusted to focus on just the one component but it's (obviously) as simple as making a reference, for example. Later, the 2D vector could be used, likely without much disruption to the legibility of the code.
e.g.
position += advance (both floats representing xs)
position += advance (both representing Vector2fs)

82
Feature-wise, unless you require 3D, SFML is a pretty solid choice for almost anything. You mention "beat-em-ups" and I think SFML is more than capable of helping with those. It's one style I've wanted to try but, not really being much of a fan, never got around to making one.


Currently SDL has better joystick support, mostly thanks to the community run SDL_GameControllerDB. We kind of want to amend this at some point, but if gamepad support is a central point of your games, then you could consider SDL.
I don't think this is really the point you made but I should mention that I made a "helper" for joystick/controller support. It simplifies reduction of axes, allows ease of controller customisation, allows cross-joining of axes to mix two axes for a 2D plane, and also allows calibration (to reduce noise etc.).
It's not finished by any means but could you have a look and let me know what you think about it? (I don't use a controller very often so I don't have the experience with them to know if I'm covering what might be required).
https://github.com/Hapaxia/JoystickController

83
General / Re: Slight differences with Text object position
« on: December 30, 2023, 04:52:12 pm »
Is it possible to know in advance, just based on my setPosition() and characterSize, the bounds of a rectangle that would contain the Text object?
In advance here would be before drawing (or entering the loop), I presume, so you can set up the text and then get its bounds before setting its origin and position. Remember that the string needs to be set too so that it knows which characters will be displayed and how big - and whereabouts - they are.
For aligning to the top-left, for a simple common character set, I'd probably set the string to something with a large capital (like "X") and position it for that and then change the string however I like afterwards.

One thing you can do with top-left alignment is to set the "origin" to its top-left (local) bounds. This allows you to place the text's position to wherever you want the top-left of the text to be and then just update the origin whenever the string changes (if it does).
You can do similar things with alignments to other corners too but be aware that updating the origin from a string change may make the text appear to "move" when characters change (e.g. when you add a "y" to the bottom line when previously it was only capitals and you're aligning to its bottom).

84
General / Re: What is a good way to draw a really long list of text?
« on: December 24, 2023, 08:49:42 pm »
Multi-line does allow fewer draw calls and that can help with performance.

My point about cells was that you can implement it as if it was a table of cells regardless of the width of each text/item. This means that you would consider it "hovering" an item if its within that "cell" rectangle even if it isn't over the actual text itself.
If you think of it as a table of cells that is wide enough to contain all of the text lengths and each of the smaller ones would just be inside a wider cell.

With the render texture idea, you would need to track which the rectangles when drawing them.
The process for render texture, by the way, would be to draw them all to the render texture once. Then, use that texture to draw a quad/rectangle that displays it (and all those texts). You can draw that simple rectangle every frame but you shouldn't need to update the texts in the render texture at all if they don't change (so don't draw them every frame).

With multi-line, again you could keep a separate track of rectangles. Or, you could divide its entire height by its "line spacing". That should give you a decent approximation of where lines are.
Or, you could also try this:
https://github.com/SFML/SFML/wiki/Source%3A-Get-Character-At-Coord
(it tells you which character in a text is at a specific position) but the longer the text, the longer it might take to search (if further in the text). It shouldn't be too significant a delay but you can try it and see if it's what you might be looking for.

85
General / Re: What is a good way to draw a really long list of text?
« on: December 24, 2023, 06:16:23 pm »
As soon as you have hundreds of texts, you should be considering options to reduce this number.

If you have static texts (that don't change the content very often), consider pre-rendering to a render texture. You can still move them around but they will move together.

Aside from that, and more specifically to your scenario, the first thing I would suggest is to work out which texts are not on screen. You can use this for two significant improvements:
1) you can only check those ones for "collision" with visible user interface points (such as a mouse position)
2) you can draw only those ones. this can significantly decrease frame time (improve frame rate) if you have so many draw calls.

I suspect you are still using a single text object per line due to the fact that you seem to be centring them and you cannot do this to a multi-line block in SFML. (not yet, anyway, but I have proposed an implementation of this already ;) )

So, if you have a long list of things, draw them all (or in groups) to a render texture (maybe a few) and then move and draw just the render texture(s) once.

In addition, to check if your mouse is over a specific text, you could consider approximate rectangles. These would be around the text but not "pixel-exact". This might even be prefered for usability due to the ease of being able to select something without having to exactly on it. You could, for example, break up the list into rectangles that are about the height of the difference in y positions (basically this means that you would always be over one of the texts) and equal widths. Equal widths are often used in these sorts of scenarios. Consider thinking about it like a table of cells. Then, you can simply check if the mouse is inside the cell rather than deal with the text graphic itself.

86
General / Re: What is a good way to draw a really long list of text?
« on: December 24, 2023, 03:24:09 pm »
Every character can have a wildly separate width, that's true. It's mainly dependent on the font but should be considered in code for any font.

You "clip" a text to a specific size, you can set its string and see how wide it is without drawing it.
You can then remove a character one at a time until its width becomes within range.

That's the simplest method. However, you can use sf::Text's findCharacterPos method to see how far along the x axis each character is and then just cut the string to match the result.

One you've cut all the lines to how you want them, don't forget you can have a text with multiple lines by adding the newline character ('\n') between them.
You can even specify the distant between the lines to help aid with layout using setLineSpacing.

87
Graphics / Re: 2 questions about VertexArray / VertexBuffer
« on: December 21, 2023, 04:58:58 pm »
1) No, I don't think SFML provides an interface for indexed vertices. You can, however, use raw OpenGL directly alongside your SFML if you really need indexing.

2) No. The primitive is set per draw call so the only ways to do that is to draw multiple (separate) triangle fans or to convert the triangle fans into triangles first.

Actually, thinking about that answer to part 2, I've just remembered that I've created an automatic function to do just that and it's on the SFML wiki here:
https://github.com/SFML/SFML/wiki/Source%3A-Triangles-Extractor

There's some extra information on an SFML thread post about it here too:
https://en.sfml-dev.org/forums/index.php?topic=29292

88
General / Re: Is drawing to sf::Texture a good idea?
« on: December 20, 2023, 10:10:10 pm »
I presume you mean an sf::RenderTexture that you can draw to. This allows you to draw to it and then use it as a texture, then allowing you to draw that texture (such as on each separate window perhaps). However, drawing that texture would still require a draw call but it would be potentially fewer vertices (only need 6 vertices for 1 quad/2 triangles).

If it's very many vertices, it may be worthwhile to render to a texture and then duplicating from the texture but there is some (significant) overhead with a render texture so if drawing the vertices separately doesn't cause any issues, you could consider keeping with that.

In addition, if you are making many draw calls then drawing to a render texture can reduce the number of duplicated draw calls. However, it might be first better to consider ways to reduce draw calls on the original output. If there are a lot already, maybe this is already too many.

89
System / Re: what do I need to fully use the library of SFML?
« on: December 16, 2023, 04:09:45 pm »
console still had some errors, for example MSB6006 on line 1074 that i dont even have. i only have 38 lines
Line 1074 of which file? If you don't have that many lines, it won't be yours but it will tell you which one.

HINT: also make sure you're running in debug mode and check the call stack as well.

90
Graphics / Re: Image doesn't save but gives no error report.
« on: December 14, 2023, 05:07:03 am »
This is a problem that I am also experiencing. How am I supposed to go about fixing it? I was able to locate it in your comment.
You would need to provide more information about your own issue to allow others to help you with it.

Pages: 1 ... 4 5 [6] 7 8 ... 225