# Creating a cube in SDL

**URL:** <https://discourse.libsdl.org/t/creating-a-cube-in-sdl/40341>\
**Category:** SDL Development\
**Created:** [November 18, 2022, 6:40pm UTC](https://discourse.libsdl.org/t/creating-a-cube-in-sdl/40341 "2022-11-18T18:40:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![LedLoaf](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@LedLoaf](https://discourse.libsdl.org/u/LedLoaf)\
**Post date:** [November 18, 2022, 6:40pm UTC](https://discourse.libsdl.org/t/creating-a-cube-in-sdl/40341/1 "2022-11-18T18:40:04Z")

</div>

Hello,

So I’m trying to switch this cool SFML project to SDL and I’m not exactly sure if it’s possible. [https://github.com/xSnapi/Isometric-Terrain](https://github.com/xSnapi/Isometric-Terrain)

All I’m trying to do at the moment is just make an isometric cube. I thought I could do it using SDL\_Vertex and SDL\_RenderGeometry, but I’m not sure if I can do it without OpenGL.

Here is where I started.

```auto
void AddCube(Vector2f position, float size, SDL_Color color, Vector2f texCoords) {
    size /= 2.0f;

   SDL_Vertex v[6] =
    {
     { SDL_FPoint{-size, 0.0f} + position, color, SDL_FPoint(texCoords.x, texCoords.y) },
     { SDL_FPoint{size, 0.0f} + position, color, SDL_FPoint(texCoords.x, texCoords.y) },
     { SDL_FPoint{size, size * 2.0f} + position, color, SDL_FPoint(texCoords.x, texCoords.y) },
                                         
     { SDL_FPoint{-size, 0.0f} + position, color, SDL_FPoint(texCoords.x, texCoords.y) },
     { SDL_FPoint{-size, size * 2.0f} + position, color, SDL_FPoint(texCoords.x, texCoords.y) },
     { SDL_FPoint{size, size * 2.0f} + position, color, SDL_FPoint(texCoords.x, texCoords.y) },
    };

   for (uint32_t i = 0; i < 6; i++) {
       m_Vertices.push_back(v[i]);
   }
}

...
   SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
        SDL_RenderClear(renderer);

    
        SDL_RenderGeometry(renderer, nullptr, m_Vertices.data(), m_Vertices.size(), nullptr, 0);
        SDL_RenderPresent(renderer);

```

PS: All I get is a red square.

---

<div class="post-metadata">

**Author:** ![uselessguy](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/u/c2a13f/32.png) [@uselessguy](https://discourse.libsdl.org/u/uselessguy)\
**Post date:** [June 18, 2023, 11:31pm UTC](https://discourse.libsdl.org/t/creating-a-cube-in-sdl/40341/3 "2023-06-18T23:31:06Z")

</div>

I watched viedo about this project, and despite this function is called “AddCube” it actuall creates square, author of this project explained that he created squares with texture of isometric cube on them, so it is cheaper for GPU to render
