Results 1 to 3 of 3

Thread: Draw texture quad with origin in center

  1. #1
    Newbie Newbie
    Join Date
    Feb 2017
    Posts
    3

    Draw texture quad with origin in center

    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?
    Code :
    {
    	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();

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,651
    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.

  3. #3
    Newbie Newbie
    Join Date
    Feb 2017
    Posts
    3

    Fixed

    Quote Originally Posted by Dark Photon View Post
    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.

Similar Threads

  1. Origin at the center.. how ?
    By manasij7479 in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-19-2011, 03:39 PM
  2. draw texture quad into texture ?
    By lesni_bleble in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 02-21-2004, 03:58 AM
  3. GLDrawPixels doesn't draw if the origin is offscreen
    By halo in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 01-28-2004, 03:35 AM
  4. How to draw a cross hairs in the center of the screen?
    By kouwww in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-19-2002, 01:56 PM
  5. Draw an origin image
    By Suvcon in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-16-2002, 11:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean