开发者

LWJGL 2D texture mapping offscreen

I am trying to map a 2D image to a quad as a background image. The image is drawn at the center of the screen so it ends up only covering the top right quater with the rest going offscreen. Is there开发者_运维技巧 anyway I can translate or change the TexCoord so it wil draw from the bottom left? Below is the code I am using.

        background.bind();          
        GL11.glBegin(GL11.GL_QUADS);
             GL11.glTexCoord2f(1,1);
             GL11.glVertex2i(0,0);
             GL11.glTexCoord2f(1,0);
             GL11.glVertex2i(0,600);
             GL11.glTexCoord2f(0,0);
             GL11.glVertex2i(800,600);
             GL11.glTexCoord2f(0,1);
             GL11.glVertex2i(800,0);
        GL11.glEnd();


This has nothing to do with textures; if you took your texture away, it would render exactly the same as it does now.

OpenGL does not naturally take vertices in window coordinates. In order to allow it to do so, you generally need to set up an orthographic projection matrix of some form, typically with glOrtho. This would look something like:

glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, width, 0, height, -1.0, 1.0);

glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

//Render stuff in window coordinates here.

glPopMatrix();

glMatrixMode(GL_PROJECTION);
glPopMatrix();

The matrix pushing and popping ensures that the prior matrix is preserved.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜