geo
geo

Reputation: 455

Reordering OpenGL Texture vertices to flip image rows

I am a complete OpenGL beginner and I inherited a codebase. I want OpenGL to flip a texture in vertical direction, meaning the top row goes to the bottom and so on. I am only doing 2D processing, if that is relevant.

My texture vertices are currently this:

const float texture_vertices[] = {
    0.0, 1.0,
    0.0, 0.0,
    1.0, 0.0,
    0.0, 1.0,
    1.0, 0.0,
    1.0, 1.0,
};

I tried changing the directions of the triangles and reordering them from going clockwise to counter clockwise. I know this is caused by my lack of awareness of how the very basics of OpenGL work, but I would appreciate all help (especially a short explanation of why something is the right way to reorder them).

Maybe I am going about this all wrong and the texture coordinates are not what I am interested in?

Upvotes: 1

Views: 246

Answers (1)

Rabbid76
Rabbid76

Reputation: 210877

You need to flip the 2nd component of the texture coordinates (swap 0 and 1):

const float texture_vertices[] = {
    0.0, 0.0,
    0.0, 1.0,
    1.0, 1.0,
    0.0, 0.0,
    1.0, 1.0,
    1.0, 0.0,
};

Upvotes: 1

Related Questions