Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (604)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (654)
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  
  Masking with PNG  (Read 1375 times)
0 Members and 1 Guest are viewing this topic.
Offline psiegel

Junior Devvie

Adamant about gaming.

« Posted 2003-04-25 23:12:31 »

I've been looking at converting my app from Graphics2D to LWJGL, learning OpenGL as I go.  I've run into a problem that I was hoping there might be a quick and dirty solution to.

I've been using PNG files for my sprites, using the alpha channel for simple bit-mask transparency (a bit of overkill, I know).  So I've only used alpha values of 0 and 255.  

Now, when I try and use these same graphics as textures, I get a sort of weird transparency when two images overlap, rather than the clean bit-masking I'm used to.  I've looked through NeHe's tutorials, and his solution is to use separate 2-bit mask files. I'd really hate to have to create 2-bit masks for all my graphics, especially when they have perfectly good alpha channels.  

Is there a quick fix for this?  Some combination of arguments passed to gl.blendFunc() that I haven't tried yet?  I've been attempting gl.blendFunc(GL.SRC_ALPHA, GL.ONE) and gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA).  The former gives me the odd transparency I've mentioned, the latter no transparency whatsoever.

I hope to go grab myself a copy of the red book this weekend, as NeHe's tutorials, while good, are just not enough.  Perhaps someone has some insights to save me a bit of time though?

Paul Siegel
Adamant Games, Inc.
Offline jbanes

JGO Coder

Projects: 1

"Java Games? Incredible! Mr. Incredible, that is!"

« Reply #1 - Posted 2003-04-26 01:11:15 »

Have you tried gl.enable(GL.ALPHA_TEST)? Blending only makes an image tranlucent.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline psiegel

Junior Devvie

Adamant about gaming.

« Reply #2 - Posted 2003-04-26 03:54:33 »

Switching from BLEND to ALPHA_TEST was definately a great idea.  Thanks.  

However, when that didn't work, I continued to bang my head against it until I realized there was something very odd in my call to gl.texImage2D().  I had copied the code from an example (straight from lwjgl's cvs!) that had the third parameter of that method a hard coded 3.  I don't even know which constant 3 is, but clearly it wasn't GL.RGBA, which is what I wanted there.

Ah, not that that's fixed, I can get into the serious work of transitioning this code.  Thanks for pointer!

Paul Siegel
Adamant Games, Inc.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder

Projects: 1

"Java Games? Incredible! Mr. Incredible, that is!"

« Reply #3 - Posted 2003-04-26 05:17:27 »

Oh yeah. That one.

Oh, Cas!!! Can you guys fix that one in future revisions before any more LWJGL newbies have trouble with this? Just use GIMP to convert the images to RGBA, then change the code to use a reasonable GL.RGBA instead of the 3. Everyone thinks the 3 is some sort of hardcoded value that can't be changed. To be perfectly honest, I can't even figure out what "3" is even supposed to represent. (scratches head)  Huh

Java Game Console Project
Last Journal Entry: 12/17/04
Offline princec

« JGO Spiffy Duke »

Medals: 556
Projects: 3
Exp: 16 years

Eh? Who? What? ... Me?

« Reply #4 - Posted 2003-04-26 06:54:21 »

"3" means "RGB" in OpenGL1.0
The constants 1, 2, 3, and 4 were replaced by named constants in 1.1. Using a 4 would have worked in this case.

Cas Smiley

Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

bilznatch (21 views)
2015-08-04 11:03:17

SHC (39 views)
2015-08-01 03:58:20

Jesse (24 views)
2015-07-29 04:35:27

Riven (45 views)
2015-07-27 16:38:00

Riven (25 views)
2015-07-27 15:35:20

Riven (27 views)
2015-07-27 12:26:13

Riven (18 views)
2015-07-27 12:23:39

BurntPizza (41 views)
2015-07-25 00:14:37

BurntPizza (51 views)
2015-07-24 22:06:39

BurntPizza (33 views)
2015-07-24 06:06:53
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 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‑
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!