Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (494)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  LWJGL Problem Transparent Textures in 3D  (Read 1320 times)
0 Members and 1 Guest are viewing this topic.
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Posted 2013-10-08 15:36:49 »

Hey, as the Title says i'm using Textures in 3D and some of them have Transparent pixels.
Here my init Code:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
GL11.glMatrixMode(GL11.GL_PROJECTION);
      GL11.glLoadIdentity();
      GLU.gluPerspective(60, Display.getWidth()/Display.getHeight(), 0.001f, 64);
      GL11.glMatrixMode(GL11.GL_MODELVIEW);
      GL11.glLoadIdentity();
      // Depth Test
     GL11.glDepthFunc(GL11.GL_LEQUAL);
      GL11.glEnable(GL11.GL_DEPTH_TEST);
      // Texture
     GL11.glEnable(GL11.GL_TEXTURE_2D);
      // Transparent Faces
     GL11.glEnable(GL11.GL_BLEND);
      GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
      // Transparent Textures
     GL11.glEnable(GL11.GL_ALPHA_TEST);
      GL11.glAlphaFunc(GL11.GL_GREATER, 0);
      // Enable Cull Face
     GL11.glEnable(GL11.GL_CULL_FACE);
      GL11.glCullFace(GL11.GL_BACK);
      GL11.glClearColor(0.2f, 0.5f, 0.8f, 1.0f);


However, I got like a Cube and want to put a name above it, Using an Image which contains all Letters. The text itself works fine, The Cube itself works fine too but The Text has the problem that the transparent faces aren't really transparent, they just get coloured as my Clear Color ( In this case 0.2, 0.5, 0.8 ) Which isn't really what i wanted as you might guess. So when there's like a world behind that name there isn't just the Text, it's the text with a border in the clearcolor as if the texture wasn't transparent and contained the Color which it doesn't. however in 2D it's working fine where i got exactly the same init code for the Textures.
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #1 - Posted 2013-10-08 15:42:31 »

transparency just cutting through the cube (Or Lots of Cubes cause it's actually 9x15x9 Cubes which will later be represented by a character)

It Looks like this:
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #2 - Posted 2013-10-08 15:57:14 »

Oh, right okay, when i change
1  
      GL11.glAlphaFunc(GL11.GL_GREATER, 0);
to
1  
      GL11.glAlphaFunc(GL11.GL_GREATER, 0.1f);
it works haha thanks man Cheesy
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #3 - Posted 2013-10-08 16:00:12 »

But this works only if the alpha value of those are 0, any chance i can get this work for all alpha values?
looks better but there is still some Blue lines arround it Cheesy
Offline Mac70
« Reply #4 - Posted 2013-10-08 16:04:40 »

You can sort your scene (draw non-transparent objects first) and set glAlphaFunc to very low value (like 0.000001f).

Check out my Devblog! Smiley
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #5 - Posted 2013-10-08 16:10:05 »

Allright, if I draw the non Transparent Faces first and the Transparent stuff after that it works perfect Smiley even with
1  
      GL11.glAlphaFunc(GL11.GL_GREATER, 0);
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #6 - Posted 2013-10-08 16:21:43 »

And that's just for the name of the Character so that's totally ok Cheesy
Offline Mac70
« Reply #7 - Posted 2013-10-08 16:24:08 »

glAlphaFunc completely "hide" parts of mesh with alpha smaller than threshold (at least in your case, because this depends on first argument). Even if you don't sort your scene you shouldn't see any artifacts. I recommend setting it to GL_NOTEQUAL and set the value to 0, then everything with 0 alpha (invisible) will be hidden.

When you use glBlendFunc, you must sort your scene, because rendering order IS important. Think about this like about taking pictures: when you make picture of empty table and then place mug on it, the mug will not appear in the picture because picture is already made.

Check out my Devblog! Smiley
Offline Seiya02

JGO Coder


Medals: 3
Projects: 4
Exp: 5 years


No Text Here :x


« Reply #8 - Posted 2013-10-08 17:42:07 »

I'm not using any glBlendFunc things atm and i think i will remove this from the initcode because my Voxel Modellloader+creator (Made them by myself  Grin ) doesn't support them and it looks good like it is without transparent cubes there Cheesy
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 (19 views)
2014-09-12 09:08:26

Norakomi (54 views)
2014-09-10 13:57:51

TehJavaDev (63 views)
2014-09-10 06:39:09

Tekkerue (31 views)
2014-09-09 02:24:56

mitcheeb (53 views)
2014-09-08 06:06:29

BurntPizza (37 views)
2014-09-07 01:13:42

Longarmx (23 views)
2014-09-07 01:12:14

Longarmx (27 views)
2014-09-07 01:11:22

Longarmx (26 views)
2014-09-07 01:10:19

mitcheeb (34 views)
2014-09-04 23:08:59
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!