Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  [Solved] Alpha blending problem  (Read 940 times)
0 Members and 1 Guest are viewing this topic.
Offline iamtommo

Senior Newbie





« Posted 2011-11-26 20:46:25 »

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_Game
I 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:

Offline theagentd
« Reply #1 - Posted 2011-11-26 20:56:34 »

Are you sure you have an alpha channel in your texture?

Myomyomyo.
Offline iamtommo

Senior Newbie





« Reply #2 - Posted 2011-11-26 21:03:11 »

yes, positive, i even loaded 2 textures just to check if that was the problem.

EDIT: I checked if the image had an alpha channel in the texture loader and it says it doesn't, however photoshop/gimp/image viewser all say it does.

EDIT2: Problem solved, textureloader loads the image as an image icon due to 'signed code' and then paints it onto a bufferedimage which has a predefined rgb not argb color space.
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (85 views)
2013-05-17 21:29:12

alaslipknot (93 views)
2013-05-16 21:24:48

gouessej (125 views)
2013-05-16 00:53:38

gouessej (118 views)
2013-05-16 00:17:58

theagentd (128 views)
2013-05-15 15:01:13

theagentd (115 views)
2013-05-15 15:00:54

StreetDoggy (159 views)
2013-05-14 15:56:26

kutucuk (181 views)
2013-05-12 17:10:36

kutucuk (181 views)
2013-05-12 15:36:09

UnluckyDevil (188 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.13 seconds with 20 queries.