Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Load Images with alpha  (Read 704 times)
0 Members and 1 Guest are viewing this topic.
Offline ricardo

Senior Member


Medals: 2
Projects: 3



« Posted 2013-10-24 02:48:54 »

Hello. I am new here.
What is the best way to handle alpha in games?
Load a .png image with alpha channel or load a .jpg image with some background color and set alpha in game?
.png files are larger (most of the times), but what about performance?
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #1 - Posted 2013-10-24 02:54:01 »

Well what graphics library are you using?

Offline kingroka123

JGO Knight


Medals: 26
Projects: 4
Exp: 1 year


Gamer's Helmet


« Reply #2 - Posted 2013-10-24 02:58:10 »

I would assume that loading a .png file with alpha will be much quicker than loading a .jpg and changing the background b/c (depending on the library you are using) will take up more time than just loading it with the alpha already there.

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

Senior Member


Medals: 2
Projects: 3



« Reply #3 - Posted 2013-10-24 03:01:26 »

I'm using Graphics2D from java.awt.
Offline SHC
« Reply #4 - Posted 2013-10-24 03:11:43 »

@ricardo
This function should load images with transparency.

1  
2  
3  
4  
public Image loadImage(String name)
{
    return new ImageIcon(name).getImage();
}

Hope it helps.

Offline ricardo

Senior Member


Medals: 2
Projects: 3



« Reply #5 - Posted 2013-10-24 03:19:48 »

Thank you but I already know how to load images with / without transparency.
I just didn't know what was the best way to load alpha.

I will use .png files. Thank you all.
Offline opiop65

JGO Kernel


Medals: 153
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #6 - Posted 2013-10-24 03:24:05 »

Alpha is just another color channel in an image, there isn't a better way or a worse way.

Offline Jeremy
« Reply #7 - Posted 2013-10-24 03:42:13 »

I imagine that not having an alpha channel can reduce the size of the texture on disk and in your memory cache (if you cache textures) and I can see that having some significance for very large games or games being run on limited hardware.

You can do the transparency (with for example, a colour Magenta) at the shader level with virtually zero performance hit. Preprocessing them and giving them an alpha channel defeats the purpose.

I wouldn't worry about it and would just use your png with an alpha channel.

JevaEngine, Latest Playthrough (This demo is networked with a centralized server model)

http://www.youtube.com/watch?v=rWA8bajpVXg
Offline ricardo

Senior Member


Medals: 2
Projects: 3



« Reply #8 - Posted 2013-10-24 06:50:33 »

Thank you.
I will use .png for now, maybe if I need a little more fps I will try set alpha in-game.
Offline Abuse

JGO Coder


Medals: 11


falling into the abyss of reality


« Reply #9 - Posted 2013-10-24 11:07:54 »

You misunderstand; file format choice has zero impact upon potential frame rate.

You should choose a file format that suits your data, that is all.

Png is a good choice to start with, as it uses lossless compression, is flexible, and is widely supported by both APIs & editors.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grunnt

JGO Wizard


Medals: 64
Projects: 8
Exp: 5 years


Complex != complicated


« Reply #10 - Posted 2013-10-24 13:27:12 »

PNG being lossless is also an important thing. Using JPG images may result in compression artefacts that could make your game ugly.

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.

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

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

danieldean (29 views)
2014-07-17 23:41:23

MustardPeter (32 views)
2014-07-16 23:30:00

Cero (47 views)
2014-07-16 00:42:17

Riven (48 views)
2014-07-14 18:02:53

OpenGLShaders (38 views)
2014-07-14 16:23:47

Riven (37 views)
2014-07-14 11:51:35

quew8 (33 views)
2014-07-13 13:57:52

SHC (70 views)
2014-07-12 17:50:04
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!