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

Author Topic: Grid using vertex array  (Read 1403 times)

0 Members and 2 Guests are viewing this topic.

Thanzex

  • Newbie
  • *
  • Posts: 1
    • View Profile
Grid using vertex array
« on: January 07, 2018, 03:27:13 am »
Hi there! As an exercize I made a simple c++ game of life and to make the code simple i have an array of RectangleShapes that i draw in a loop, the only thing i change about them is the FillColor. Everything runs smoothly until i hit around 20.000 of these shapes, then it starts lagging heavily. I searched how to optimize the draw of these shapes but i only found reference to vertex arrays or sprites. I don't need textures, just a black/white box. I looked up vertex arrays but didn't understand very well how to use them.
As far as i understand the problem behind the lag is that i'm making tens of thousands of draw calls and a way of solving that would be to make a single draw of many objects( a thing for which modern gpus are well designed for), but as far as i understand i'd be doing the same for vertex arrays, creating an array of quads, giving them a color and then drawing them, just not using the RectangleShape class.
Am i missing something here? Is there a way to make a single draw call for all the "cells"?
Thanks

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Grid using vertex array
« Reply #1 on: January 07, 2018, 08:43:33 am »
You already found the solution, that is using a vertex array. You can use quads and set the vertex color to the color you need for the cell.

Check the tutorial and documentation on how to use a vertex array.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything