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

Author Topic: The way to draw a Isometric square the fastest  (Read 8591 times)

0 Members and 1 Guest are viewing this topic.

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
The way to draw a Isometric square the fastest
« on: March 21, 2013, 07:26:48 pm »
I want to draw a 2D isometric square the fastest, the bottom two corners will always be empty, the top two might be filled (on buildings, for example, which have height above the size of the tile)

Speed is my largest concern, I don't care how messy/hard it is

I'm wanting to make an Age Of Empires II like game, if that gives you a better idea of possibilities
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: The way to draw a Isometric square the fastest
« Reply #1 on: March 21, 2013, 08:09:31 pm »
Try sprites, they are good enough for many cases.

If there is a performance problem, use vertex arrays and draw squares with the same texture together (as many as possible).
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #2 on: March 21, 2013, 10:02:26 pm »
then I have a 50% efficiency problem, since I'm basically drawing twice the pixels of the map, since an isometric square is only filling 50% of the rectangle

explain "draw squares with the same texture together"
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #3 on: March 21, 2013, 10:32:29 pm »
explain "draw squares with the same texture together"
He means that you have one texture with all the different squares on it and tell the vertices where they are located on the texture. With that you can pack all the vertices into one vertex array and thus getting the best performance possible. You just have to make sure, that the texture size works with your GPU.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: The way to draw a Isometric square the fastest
« Reply #4 on: March 21, 2013, 10:35:09 pm »
then I have a 50% efficiency problem, since I'm basically drawing twice the pixels of the map, since an isometric square is only filling 50% of the rectangle
Do you draw the same pixels twice, or why is a square filling 50%? Can't you draw everything once, from back to front?

explain "draw squares with the same texture together"
Take a look at how sf::VertexArray works. You can draw multiple geometric objects in one call, using one texture. The less vertex arrays you draw, the better.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #5 on: March 21, 2013, 10:41:17 pm »
Do you draw the same pixels twice, or why is a square filling 50%? Can't you draw everything once, from back to front?
I was first also confused, but if you take a look at the following image, you'll notice, that the black areas are as big as the red areas. And since he only needs the red area, the black part is kinda wasted, though I'm not sure if OpenGL simply ignores alpha=0 pixels... ;)

Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: The way to draw a Isometric square the fastest
« Reply #6 on: March 21, 2013, 11:22:36 pm »
That is true, but I still don't see what has to be drawn twice. Maybe I just misunderstood him...

By the way, it's really nice you always take the effort to draw and upload images to explain things! Thank you!
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #7 on: March 21, 2013, 11:32:25 pm »
not that I have to draw an image twice, but that twice the amount of pixels are being drawn, my square looks exactly like exploit3r's, but its scaled on the Y axis by 0.5 Relative, but the case is still the same, and could you confirm that OpenGL/Nvidia/AMD skips Alpha of 0? it sounds logical, but maybe not true
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #8 on: March 22, 2013, 12:30:23 am »
By the way, it's really nice you always take the effort to draw and upload images to explain things! Thank you!
I don't do it always, but as the saying goes: A picture is worth a thousand words. ;)

and could you confirm that OpenGL/Nvidia/AMD skips Alpha of 0? it sounds logical, but maybe not true
I can't, it was just a logical assumption/wish of mine. ;D

Btw. do you run into performance issues or is this once more a "premature" optimization problem?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #9 on: March 22, 2013, 03:35:13 am »
Well, neither, Lol, I haven't written a single line of code yet, so idk if there are any performance issues, and I don't think this counts a "premature" optimization.. maybe more of a "preinfant" optimization ;D

I've only began making ideas, and crappy programmer art so far, since I figure I'll have only two problems that will hog system resources(pathfinding, and rendering), it would be a good idea to find out the right way of doing them before I dive into making a couple hundred/thousand lines of code based on a guess.
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

Weeve

  • Jr. Member
  • **
  • Posts: 87
  • C++ Programmer (Intermediate), 3D Artist (Skilled)
    • View Profile
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #10 on: March 22, 2013, 10:21:13 pm »
Assuming that the answer is just to draw it with a sprite, and let the GPU do any optimizations

Oh, and another question, I want to cut an isometric tile out of a spritesheet, how could I cut it diagonally? does SFML support masks that I can draw, then have it cut out that shap, or do I just iterate over a pixel list and have it remove the onces in the list
Long live rapid project development! -- Kestrel3D Game-Engine nearing completion

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #11 on: March 22, 2013, 11:01:36 pm »
Oh, and another question, I want to cut an isometric tile out of a spritesheet, how could I cut it diagonally?
SFML doesn't provide such a feature. You either just use a bigger texture or use a (possibly slow) algorithm of your own to extract the data. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #12 on: March 22, 2013, 11:05:22 pm »
What about vertex arrays? If they're square wouldn't they work without distorting the image?
Back to C++ gamedev with SFML in May 2023

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #13 on: March 22, 2013, 11:13:35 pm »
What about vertex arrays? If they're square wouldn't they work without distorting the image?
Hmmm... Well he said they are "scaled on the Y axis by 0.5 Relative", not sure if it's still a quad, but if so, then it could work. Although I'm not sure how OpenGL will decide which pixel belong to the selection and which not on a diagonal. I guess it's worth a try. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

FRex

  • Hero Member
  • *****
  • Posts: 1848
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: The way to draw a Isometric square the fastest
« Reply #14 on: March 22, 2013, 11:32:32 pm »
Maybe if they're square but scaled for real(like in .setScale(1.f,0.5f)) it'd not stretch them.
Back to C++ gamedev with SFML in May 2023