Using SDL2 built from main on 6/10/21 to test out the new SDL_RenderGeometry. Am I doing something wrong? I’m trying to render a quad with a texture. If I render a rectangle as below, everything works as I expect:
SDL_Color col{ 0xff,0xff,0xff,0xff };
std::vector<SDL_Vertex> verticies{
{{300.0f,200.0f}, col, {0.0f,0.0f}},
{{800.0f,200.0f}, col, {1.0f,0.0f}},
{{300.0f,700.0f}, col, {0.0f,1.0f}},
{{800.0f,700.0f}, col, {1.0f,1.0f}},
};
std::array<int, 6> indexList = { 0,1,2,2,1,3 };
SDL_RenderGeometry(mRenderer, texture, verticies.data(), (int)verticies.size(), indexList.data(), (int)indexList.size());
This gives me the following output:
But if I change the verticies to draw a trapezium instead, like this:
SDL_Color col{ 0xff,0xff,0xff,0xff };
std::vector<SDL_Vertex> verticies{
{{500.0f,200.0f}, col, {0.0f,0.0f}},
{{700.0f,200.0f}, col, {1.0f,0.0f}},
{{300.0f,700.0f}, col, {0.0f,1.0f}},
{{800.0f,700.0f}, col, {1.0f,1.0f}},
};
std::array<int, 6> indexList = { 0,1,2,2,1,3 };
SDL_RenderGeometry(mRenderer, texture, verticies.data(), (int)verticies.size(), indexList.data(), (int)indexList.size());
Then the result is not what I expect. You can clearly see the two triangles being drawn with textures that don’t make sense together.
I’m totally new to this sort of api, so my question is: Is this output correct (I assume it is)?. If so, is there a way to use the api in a way that will map the texture onto the quad, rather than seperately onto two triangles? I would expect (perhaps incorrectly) to end up with something like this:
If something like this isn’t possible, what is possible using textures and RenderGeometry?Perhaps I have a fundamental misunderstanding of the api.