Hack Forums
[Java] LWJGL glTranslatef texture question - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] LWJGL glTranslatef texture question (/showthread.php?tid=5794240)



LWJGL glTranslatef texture question - Womas - Feb 3, 2018

LWJGL question:
im now writing a code which add a texture to a quad
Code
public static void DrawQuadTex(Texture texture, float x, float y, float width, float height) {

        texture.bind();
        glBegin(GL_QUADS);
        glTexCoord2f(0,0);
        glVertex2f(x,y);
        glTexCoord2f(1,0);
        glVertex2f(x+width,y);
        glTexCoord2f(1,1);
        glVertex2f(x+width, y+height);
        glTexCoord2f(0,1);
        glVertex2f(x,y+ height);
        glEnd();
        glLoadIdentity();
    }
Other then that, I've also seen ppl doing THIS:
Code
public static void DrawQuadTex(Texture texture, float x, float y, float width, float height) {

        texture.bind();
        glTranslatef(x,y,0);
        glBegin(GL_QUADS);
        glTexCoord2f(0,0);
        glVertex2f(0,0);
        glTexCoord2f(1,0);
        glVertex2f(width,y);
        glTexCoord2f(1,1);
        glVertex2f(width, height);
        glTexCoord2f(0,1);
        glVertex2f(0,height);
        glEnd();
        glLoadIdentity();
    }

Assume i input 64,64 to the second code as x y parameters, why is the x y in glVertex2f be 0 , width and height at first? Shouldn't it be x,y, x or y + width and x or y + height?
Like normally 0xy should be the top left corner of the computer. But now it changed to the top left corner of the quad. Is that what glTranslatef does?


RE: LWJGL glTranslatef texture question - Sogomn - Feb 4, 2018

Quote:Is that what glTranslatef does?

Yes. That's why it's called "translate".

But is there any reason you're using like... OpenGL 1? It's endlessly slow and the code get super clumsy real fast.