Hey, i'm quite new to lwjgl/opengl however i've been writing games in java2d for quite awhile now. So anyways, this is my problem:
I've been trying to get alpha blending to work for the past 2 days, i've searched endlessly and tried a million different solutions, and i have a weird feeling it's a very stupid mistake on my behalf, the texture i'm rendering are simply black where it should be transparent.
NOTE: To load and store texture data i'm using the texture class and loader used here:
http://lwjgl.org/wiki/index.php?title=Space_Invaders_Example_GameI have checked the textureloader class and it does load textures with RGBA. Also i tried setting the blend mode to (gl_one, gl_one) and i can see that it does infact blend with that mode.
Here is my gl init code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| public void initGL() { Engine.debug("Initialising OpenGL"); GL11.glMatrixMode(GL11.GL_PROJECTION); GL11.glLoadIdentity(); GL11.glOrtho(0, WIDTH, HEIGHT, 0, -1, 1); GL11.glMatrixMode(GL11.GL_MODELVIEW); GL11.glLoadIdentity(); GL11.glViewport(0, 0, WIDTH, HEIGHT); GL11.glDisable(GL11.GL_DEPTH_TEST); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); GL11.glEnable(GL11.GL_BLEND); Engine.debug("OpenGL Initialised!"); } |
and here is my rendering code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| public void drawTexture(Texture texture, int x, int y, int width, int height) { GL11.glPushMatrix(); texture.bind(); GL11.glTranslatef(x, y, 0); GL11.glBegin(GL11.GL_QUADS); GL11.glTexCoord2f(0, 0); GL11.glVertex2f(0, 0); GL11.glTexCoord2f(0, texture.getHeight()); GL11.glVertex2f(0, height); GL11.glTexCoord2f(texture.getWidth(), texture.getHeight()); GL11.glVertex2f(width, height); GL11.glTexCoord2f(texture.getWidth(), 0); GL11.glVertex2f(width, 0); GL11.glEnd(); GL11.glPopMatrix(); } |
And finally, here is a screenshot of how it looks:
