0

I make my own voxel engine and when I set texture on trinagle it looks weird and not correct here my triangle render code:

vertices[0].position.x = draw_face.point0.x;
vertices[0].position.y = draw_face.point0.y;
vertices[0].tex_coord = {float(draw_face.t_ind0.x), float(draw_face.t_ind0.y)};
vertices[0].color = {
    (unsigned char)(255 - (int)(draw_face.point_shadow0)), 
    (unsigned char)(255 - (int)(draw_face.point_shadow0)), 
    (unsigned char)(255 - (int)(draw_face.point_shadow0)), 
    255
};
            

vertices[1].position.x = draw_face.point1.x;
vertices[1].position.y = draw_face.point1.y;
vertices[1].tex_coord = {float(draw_face.t_ind1.x), float(draw_face.t_ind1.y)};
vertices[1].color = {
    (unsigned char)(255 - (int)(draw_face.point_shadow1)), 
    (unsigned char)(255 - (int)(draw_face.point_shadow1)), 
    (unsigned char)(255 - (int)(draw_face.point_shadow1)), 
    255
};


vertices[2].position.x = draw_face.point2.x;
vertices[2].position.y = draw_face.point2.y;
vertices[2].tex_coord = {float(draw_face.t_ind2.x), float(draw_face.t_ind2.y)};
vertices[2].color = {
    (unsigned char)(255 - (int)(draw_face.point_shadow2)), 
    (unsigned char)(255 - (int)(draw_face.point_shadow2)), 
    (unsigned char)(255 - (int)(draw_face.point_shadow2)), 
    255
};
SDL_RenderGeometry(renderer, texture, vertices, 3, NULL, 4);

when camera angle is 0:

enter image description here

and this is the my problem when camera is rotated:

enter image description here

1 Answer 1

2

SDL interpolates the texture coordinates linearly, while you're asking for a perspective correct interpolation.

I don't think SDL_RenderGeometry() supports this. (Unless you're willing to draw each texel as a separate quad?)

Now might be a good time to learn the new rendering API shipped in SDL3, which should have no problems with this.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.