Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
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  
  Alpha doesnt work  (Read 2008 times)
0 Members and 1 Guest are viewing this topic.
Offline .exe

Senior Newbie





« Posted 2012-08-30 16:02:03 »

Using JOGL, and problem is - there is no alpha. I have a PNG file that shows transparency in photoshop.

Loading texture:

1  
2  
3  
4  
5  
6  
7  
8  
   public void LoadTextureFromResource(String res,String type) throws IOException
   {
     
        InputStream stream = getClass().getResourceAsStream(res);
        TextureData data = TextureIO.newTextureData(GLProfile.getDefault(),stream,GL2.GL_RGBA,GL2.GL_RGBA, false, type);
        this.texture = TextureIO.newTexture(data);
        this.loaded = true;
   }


OpenGL init:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
        GLCapabilities capabilities = new GLCapabilities(GLProfile.getDefault());
        capabilities.setHardwareAccelerated(true);
        capabilities.setNumSamples(0);
        capabilities.setAlphaBits(8);
        capabilities.setSampleBuffers(true);

        ......
       
        gl.glDisable(GL2.GL_LIGHTING);
   gl.glBlendFunc(GL.GL_SRC_ALPHA, GL.GL_ONE_MINUS_SRC_ALPHA);  // <--
   gl.glEnable (GL2.GL_BLEND);
        gl.glShadeModel(GLLightingFunc.GL_SMOOTH);
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        gl.glClearDepth(1.0f);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glHint(GL2ES1.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);


Tried changing blend func, some modes make everything transparent, this one renders fine but without alpha.
And ofcourse, im rendering object with that texture last.

Help??
Offline loom_weaver

JGO Coder


Medals: 17



« Reply #1 - Posted 2012-08-30 16:18:53 »

Don't know if this will help but here is what I needed to do to get alpha textures in lwjgl.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
    glEnable(GL_BLEND)
    glDisable(GL_DITHER)
    glDisable(GL_FOG)
    glDisable(GL_LIGHTING)
    glEnable(GL_LINE_SMOOTH)
    glDisable(GL_TEXTURE_1D)
    glEnable(GL_TEXTURE_2D)

    //glShadeModel(GL_FLAT)
    glShadeModel(GL_SMOOTH)

    //glPolygonMode(GL_FRONT, GL_LINE)
    glPolygonMode(GL_FRONT, GL_FILL)

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    glEnableClientState(GL_VERTEX_ARRAY)
    glEnableClientState(GL_TEXTURE_COORD_ARRAY)
    glEnableClientState(GL_COLOR_ARRAY)
Offline .exe

Senior Newbie





« Reply #2 - Posted 2012-08-30 16:34:29 »

Almost everything i have  Huh  Undecided

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline sproingie

JGO Kernel


Medals: 202



« Reply #3 - Posted 2012-08-30 16:59:36 »

You have depth testing enabled, which will defeat blending.  You need to disable it.
Offline .exe

Senior Newbie





« Reply #4 - Posted 2012-08-30 17:45:21 »

still doesn't work, and i see poligons thru walls.
Offline .exe

Senior Newbie





« Reply #5 - Posted 2012-08-30 18:02:48 »

ok made a progress, removed default color from objects, only texture now.

now on areas where should be transparent, i have red color? Cheesy

EDIT: its not the background, background is blue
Offline .exe

Senior Newbie





« Reply #6 - Posted 2012-08-30 18:20:40 »

ok, found a problem: gl.glTexEnvi (GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_DECAL);

after removing* that transparency works, but everything is red... its red becouse of font rendering.

is there a way to reset opengl color after calling glColor?? and another way to use only texture color no lights?
Offline jonjava
« Reply #7 - Posted 2012-08-30 19:02:44 »

Seems like R and A are in the wrong place (GL2.GL_RGBA).

Is there an GL_ARGB version?

Offline .exe

Senior Newbie





« Reply #8 - Posted 2012-08-31 13:00:33 »

setting glColor to white, fixes the problem... but the scene is a little brighter.

The following code was causing alpha to fail:
1  
gl.glTexEnvi (GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_DECAL);
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.

trollwarrior1 (31 views)
2014-11-22 12:13:56

xFryIx (72 views)
2014-11-13 12:34:49

digdugdiggy (51 views)
2014-11-12 21:11:50

digdugdiggy (45 views)
2014-11-12 21:10:15

digdugdiggy (39 views)
2014-11-12 21:09:33

kovacsa (63 views)
2014-11-07 19:57:14

TehJavaDev (68 views)
2014-11-03 22:04:50

BurntPizza (66 views)
2014-11-03 18:54:52

moogie (81 views)
2014-11-03 06:22:04

CopyableCougar4 (81 views)
2014-11-01 23:36:41
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!