I'm trying to make a simple button in OpenGL/LWJGL,
I can render my 2D QUAD correctly, but when i implement the texture, only about 3/4 parts of the whole quad gets textured, like this: https://dl.dropboxusercontent.com/u/60223805/glerror1.png
and if i remove the texture coords i get this: https://dl.dropboxusercontent.com/u/60223805/glerror2.png
none.bind();
co.Enable2D_GUI();
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0, 0);
GL11.glVertex2f(co.width/2-200, co.height/2);
GL11.glTexCoord2f(1, 0);
GL11.glVertex2f(co.width/2+none.getTextureWidth(),co.height/2);
GL11.glTexCoord2f(1, 1);
GL11.glVertex2f(co.width/2+none.getTextureWidth(), co.height/2+none.getTextureHeight());
GL11.glTexCoord2f(0, 1);
GL11.glVertex2f(co.width/2-200, co.height/2+none.getTextureHeight());
GL11.glEnd();
co.Disable2D_GUI();
where none is an Texture (from slick-util library) and the functions Enable2D_GUI and Disable2D_GUI just enables and disable ortho and stuff.
What can be wrong? I'm very new to OpenGL so im sorry if my question is a bit nooby
This is my Enable2D_GUI and Disable2D_GUI functions:
public void Enable2D_GUI() {
GL11.glMatrixMode (GL11.GL_PROJECTION);
GL11.glPushMatrix();
GL11.glLoadIdentity ();
GL11.glOrtho (0, width, height, 0, 1, -1);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glMatrixMode (GL11.GL_MODELVIEW);
GL11.glPushMatrix();
GL11.glLoadIdentity();
}
public void Disable2D_GUI() {
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glPopMatrix();
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glPopMatrix();
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_DEPTH_TEST);
}
Now when I test it with a 3D QUAD it doesnt work either, same result. This is my OpenGL init code:
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glClearColor(0f, 0.0f, 0.0f, 0.0f);
GL11.glClearDepth(1.0);
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDepthFunc(GL11.GL_LEQUAL);
GL11.glViewport(0, 0, width, height);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GLU.gluPerspective(
45.0f,
(float)width/(float)height,
0.5f,
50.0f);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
You're misusing the
glPushMatrixandglPopMatrixand also not adding or performing state switches in the correct order.In you init code you need to change it to the following.
You don't have to perform state switches after the
glLoadMatrixandglLoadIdentitythough it would be better doing so. 1 The code is more readable. 2 Some things gets reset after callingglLoadIdentitythough just the stuff about and within the Matrix itself.Then you also need to fix your
Enable2D_GUIandDisable2D_GUIto the following.Enable2D_GUI
Disable2D_GUI
Aleast of what I know you can not use the
glPushMatrixandglPopMatrixin betweenglMatrixModeandglLoadIdentitycalls. I could be mistaking Then I also added theglLoadIdentitycalls instead to reset the Matrices.