Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (535)
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 1465 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.

 

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

The first screenshot will be displayed as a thumbnail.

Dwinin (6 views)
2014-07-29 10:59:34

E.R. Fleming (20 views)
2014-07-29 03:07:13

E.R. Fleming (8 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (26 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21

Zero Volt (50 views)
2014-07-17 23:47:54

danieldean (42 views)
2014-07-17 23:41:23
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!