Java + JOGL, how to set transparency for displaying objects in a scene instead of plain black when painting a texture?

We are writing a simple 3D game as a project in a course that we take at the university. (assignment for couples) we should use JOGL , so I have to work with this API (solutions like: switching to a higher level API like java3D will not be good for me ...) anyway, a game that we decided to implement is a kind of 3D shooter. (the code so far, which is forked from the previous assignment that we did for the same course, can be found here: http://code.google.com/p/mirzhcode/source/browse/?repo=cgex4 ) and Now I'm trying to deal with "special effects." more precisely, particles and sprites (for shooting, explosions, etc.) ...) I came across an explanation regarding sprite emitters that I want to implement: http://bit.ly/KrrPM4

I started with what seemed like the easy part. shock wave ring, consisting of one fast-growing sprite. when I try to make the image I made, I get a black background instead of the transparency I wanted. the texture image is a transparent png file (so there is an alpha channel) shockwave png file with alpha transperancy and I get from this: the enter image description here code I used to create this:

in init():

//loading textures
try {
    shockwave = TextureIO.newTexture(new File( "textures/shockwave_128X128.png" ),false);
} catch (GLException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}

gl.glShadeModel(GL.GL_SMOOTH);
gl.glClearColor(0f, 0f, 0f, 1f);
gl.glClearDepth(1.0);
gl.glEnable(GL.GL_BLEND);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE);
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);
gl.glHint(GL.GL_POINT_SMOOTH_HINT, GL.GL_NICEST);
gl.glEnable(GL.GL_TEXTURE_2D);
gl.glEnable(GL.GL_DEPTH_TEST);

//UNCOMMENT THE FOLLOWING LINE OF CODE
//FOR REALISTIC COLORS. NOTE THAT ICC
//BUTTON WON'T CHANGE THE COLORS ANYMORE.

//gl.glEnable(GL.GL_LIGHTING);

//two (soft) lights (red and blue) setup.
//each in an opposite corner of the room.
float color0[] = {1f, 0f, 0f, 0.5f};
float ambient0[] = {1.0f, 1.0f, 1.0f, 0.5f};
float position0[] = {(float) (0.95*expansionFactor), (float) (0.95*expansionFactor), (float) (0.95*expansionFactor)};

float color1[] = {0f, 0f, 1f, 0.5f};
float ambient1[] = {1.0f, 1.0f, 1.0f, 0.5f};
float position1[] = {(float) (0.95*expansionFactor), (float) (0.95*expansionFactor), (float) (0.95*expansionFactor)};

gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, ambient0,1); 
gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE,color0 , 1); 
gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, color0 , 1); 
gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, position0, 1);

gl.glLightfv(GL.GL_LIGHT1, GL.GL_AMBIENT, ambient1,1); 
gl.glLightfv(GL.GL_LIGHT1, GL.GL_DIFFUSE,color1 , 1); 
gl.glLightfv(GL.GL_LIGHT1, GL.GL_SPECULAR, color1 , 1); 
gl.glLightfv(GL.GL_LIGHT1, GL.GL_POSITION, position1, 1);

gl.glEnable(GL.GL_LIGHT0);
gl.glEnable(GL.GL_LIGHT1);

start();

as well as in the method display():

gl.glEnable(GL.GL_BLEND);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);
shockwave.bind();

gl.glColor4f(1f,1f,1f,1f);

gl.glBegin(GL.GL_QUADS);
gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3d(0.0-10, 0.2, 0.0-10);
gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3d(0.0+10, 0.2, 0.0-10);
gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3d(0.0+10, 0.2, 0.0+10);
gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3d(0.0-10, 0.2, 0.0+10);
gl.glEnd();

to summarize, my question is how to make a texture use its alpha channel, and if it’s not so easy, is there a library that you probably know I can use?

+5
source share
1 answer

, , . openGL . . , . , - , , , . , , . . after the fix

+3

All Articles