PDA

View Full Version : Draw texture quad with origin in center



NFMynster
02-20-2017, 09:28 AM
Hello people!
I could not seem to find any information about how this is done, but how exactly are you supposed to draw a textured quad with the origin in it's center?
I'm using SOIL for the textures. So this code is meant to draw a texture on a quad, where the texture decides the quads size. But the origin is still in the left corner.
Anybody able to give a hand?


{
glPushMatrix();

glTranslatef(GetGameObject()->Transform->Position->X, GetGameObject()->Transform->Position->Y, GetGameObject()->Transform->Position->Z);
glBindTexture(GL_TEXTURE_2D, this->texture);
//Render textured quad
glBegin(GL_QUADS);
glTexCoord2d(0.0, 0.0); glVertex2d(0.0, 0.0);
glTexCoord2d(1.0, 0.0); glVertex2d(1 * scale->X , 0.0);
glTexCoord2d(1.0, 1.0); glVertex2d(1 * scale->X, (height / width) * scale->Y);
glTexCoord2d(0.0, 1.0); glVertex2d(0.0, (height / width) * scale->Y);
glEnd();

glPopMatrix();

Dark Photon
02-20-2017, 04:56 PM
I think you might be mixing up positions and texture coordinates.

Positions determine where your quad is rendered in space. Texture coordinates determine how each point on that quad is textured.

NFMynster
02-21-2017, 02:22 AM
I think you might be mixing up positions and texture coordinates.

Positions determine where your quad is rendered in space. Texture coordinates determine how each point on that quad is textured.

Oh yes, thank you, I ended up fixing it by using the width and the height of the texture.
Also, for future references, don't manually apply scale, use Scale3f instead.