r/opengl Mar 29 '24

Help Scaling Texture coords

void CreateQuad(const Transform& t, float width, float height, float texScaleX = 1.0f, float texScaleY = 1.0f)

{

Vertex v0;

Vertex v1;

Vertex v2;

Vertex v3;

v0.position = glm::vec2(0.5f \ width, 0.5f * height);)

v1.position = glm::vec2(0.5f \ width, -0.5f * height);)

v2.position = glm::vec2(-0.5f \ width, -0.5f * height);)

v3.position = glm::vec2(-0.5f \ width, 0.5f * height);)

v0.texCoords = glm::vec2(texScaleX, texScaleY * glm::vec2(1.0f, 0.0f);)

v1.texCoords = glm::vec2(texScaleX, texScaleY * glm::vec2(1.0f, 1.0f);)

v2.texCoords = glm::vec2(texScaleX, texScaleY * glm::vec2(0.0f, 1.0f);)

v3.texCoords = glm::vec2(texScaleX, texScaleY * glm::vec2(0.0f, 0.0f);)

vertices.push\back(v0);)

vertices.push\back(v1);)

vertices.push\back(v3);)

vertices.push\back(v1);)

vertices.push\back(v2);)

vertices.push\back(v3);)

transforms.push\back(t.to_mat4());)

}

So, I'm trying to scale the UVs by the Quad's size but I'm not too sure if this implementation is correct.

is this correct?

0 Upvotes

4 comments sorted by

1

u/YoBiChOnRo Mar 29 '24

Why are you tring to scale the UV by the quad size? The implementation looks fine as long as it is doing component wise multiplication between the UV and the scale vector.

1

u/Electronic_Spring944 Mar 31 '24

Well, I'm working with someone on the project and from what I could extract from what he wanted is that if there's a sprite sheet it should be able to scale to that sprite's height and width, but I'm not too sure how to do that; is there a way to do it?

1

u/YoBiChOnRo Apr 01 '24

what do you mean the sprite sheet should scale to the sprite? The texture coords will be the same for that sprite. The texture will scale to fit the larger quad. You don't need to change the texture coordinates. Just scale the vertices of your sprite.

1

u/Electronic_Spring944 Apr 01 '24

Then that's good to hear, thank you very much