Hi there!
My goal is to render some quads to simulate an isometric cube, let's take Minecraft icon as reference:
So, I'm loading this 32w16h texture without issues:
And creating and drawing
sf::VertexArray like this in the
window.isOpen() loop:
sf::Texture grass;
if (!grass.loadFromFile("grass.png"))
return 0;
...
...
window.clear();
sf::VertexArray cube(sf::Quads);
const sf::Vector2f position{ 100.f, 100.f };
constexpr float size = 50.f;
cube.append({ position - (vertex[5] * size), {}, { 0.f, 0.f} });
cube.append({ position, {}, {16.f, 0.f} });
cube.append({ position - (vertex[3] * size), {}, {16.f, 16.f} });
cube.append({ position - (vertex[4] * size), {}, {0.f, 16.f} });
cube.append({ position - (vertex[5] * size), {}, {16.f, 0.f} });
cube.append({ position - (vertex[0] * size), {}, {32.f, 0.f} });
cube.append({ position - (vertex[1] * size), {}, {32.f, 16.f} });
cube.append({ position, {}, {16.f, 16.f} });
cube.append({ position, {}, { 0.f, 0.f} });
cube.append({ position - (vertex[1] * size), {}, {16.f, 0.f} });
cube.append({ position - (vertex[2] * size), {}, {16.f, 16.f} });
cube.append({ position - (vertex[3] * size), {}, {0.f, 16.f} });
window.draw(cube, &grass);
window.display();
This results in a black screen (except for the imgui controls I've added). The
vertex static array that I'm multiplying values with is defined like this:
template <auto degrees>
constexpr auto radians = degrees * std::numbers::pi_v<decltype(degrees)> / 180;
/*
0 0 _______ 1 60
/ y /|
5 300 /______/ |
| |x| 2 120
| z | /
|______|/
4 240 3 180
*/
const static sf::Vector2f vertex[]
{
{std::sin(radians< 0.f>), std::cos(radians< 0.f>)},
{std::sin(radians< 60.f>), std::cos(radians< 60.f>)},
{std::sin(radians<120.f>), std::cos(radians<120.f>)},
{std::sin(radians<180.f>), std::cos(radians<180.f>)},
{std::sin(radians<240.f>), std::cos(radians<240.f>)},
{std::sin(radians<300.f>), std::cos(radians<300.f>)},
};
It just contains the vertex possitions of an exagon, nothing special here.
If instead of rendering using a texture I just render using vertex color, there's no problem displaying the cube:
window.clear();
sf::VertexArray cube(sf::Quads);
const sf::Vector2f position{ 100.f, 100.f };
constexpr float size = 50.f;
cube.append({ position - (vertex[5] * size), sf::Color::Red });
cube.append({ position, sf::Color::Red });
cube.append({ position - (vertex[3] * size), sf::Color::Red });
cube.append({ position - (vertex[4] * size), sf::Color::Red });
cube.append({ position - (vertex[5] * size), sf::Color::Green });
cube.append({ position - (vertex[0] * size), sf::Color::Green });
cube.append({ position - (vertex[1] * size), sf::Color::Green });
cube.append({ position, sf::Color::Green });
cube.append({ position, sf::Color::Blue });
cube.append({ position - (vertex[1] * size), sf::Color::Blue });
cube.append({ position - (vertex[2] * size), sf::Color::Blue });
cube.append({ position - (vertex[3] * size), sf::Color::Blue });
window.draw(cube, &grass);
[code=cpp]
Result:
[img]https://i.stack.imgur.com/UDdgy.png[/img]
If I don't pass the texture to the [tt]draw[/tt] function the plain colors look brighter:
[img]https://i.stack.imgur.com/uxkTz.png[/img]
Which makes me think that it might have something to do with the lack of light on the scene? I don't know, I'm pretty lost here.
Any guidance would be appreciated. Thank you very much.