1
General / Re: Zooming in and out makes line flicker
« on: January 03, 2024, 06:39:43 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.
I'm afraid I don't fully understand what you're saying in the 3rd and 4th paragraphs.
I have a huge grid (so that it "looks" infinite), which is clickable (you click on a cell and it changes color), and I have a view. I only draw what is in view.
Currently I simply hold a set of "clicked" cells (sparse matrix, if you will), and each frame I simply iterate over all cells in view, and check for each one if it is "clicked" - if yes, I draw it in color. If not - I leave it blank.
I am able to this since I'm holding an unordered_set (hash map), but vertexArray is just...an array. So for every cell (in view) I need to check the entire array from start to finish. Not very efficient.
Also, you said "you can simply draw those cells", did you mean drawing with quads?
I can't see a way to implement a clickable grid with just lines
Thanks in advance