Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

LWJGL glTranslatef texture question

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?
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.
Hey I have a signature.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C#] by Hogtalare1Mar 16, 2017 11:51 AM 3 193 Mar 16, 2017 11:51 AM
Last Post: Hogtalare1
[.NET] by Hogtalare1Mar 14, 2017 03:10 AM 2 171 Mar 14, 2017 03:10 AM
Last Post: stratex
[Java] by aRuHZoNaDec 5, 2016 06:48 AM 4 256 Dec 5, 2016 06:48 AM
Last Post: CAFEEFAC