Hi !
Featured games (85)
games approved by the League of Dukes
Games in Showcase (636)
Games in Android Showcase (178)
games submitted by our members
Games in WIP (687)
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 1400 times)
0 Members and 1 Guest are viewing this topic.
Offline ricardo

Senior Devvie

Medals: 2
Projects: 3

« Posted 2013-10-24 00: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 Opiop
« Reply #1 - Posted 2013-10-24 00:54:01 »

Well what graphics library are you using?
Offline kingroka123

JGO Wizard

Medals: 78
Projects: 9
Exp: 2 years

Gamer's Helmet

« Reply #2 - Posted 2013-10-24 00: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 Devvie

Medals: 2
Projects: 3

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

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

This function should load images with transparency.

public Image loadImage(String name)
    return new ImageIcon(name).getImage();

Hope it helps.

Offline ricardo

Senior Devvie

Medals: 2
Projects: 3

« Reply #5 - Posted 2013-10-24 01: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 Opiop
« Reply #6 - Posted 2013-10-24 01: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 01: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)
Offline ricardo

Senior Devvie

Medals: 2
Projects: 3

« Reply #8 - Posted 2013-10-24 04: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 Ninja

Medals: 42

falling into the abyss of reality

« Reply #9 - Posted 2013-10-24 09: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!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Grunnt

JGO Kernel

Medals: 95
Projects: 8
Exp: 5 years

Complex != complicated

« Reply #10 - Posted 2013-10-24 11: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.

Dwinin (71 views)
2015-11-07 13:29:08

Rems19 (80 views)
2015-10-31 01:36:56

Rems19 (74 views)
2015-10-31 01:32:37

williamwoles (106 views)
2015-10-23 10:42:59

williamwoles (92 views)
2015-10-23 10:42:45

Jervac_ (106 views)
2015-10-18 23:29:12

DarkCart (134 views)
2015-10-16 00:58:11

KaiHH (116 views)
2015-10-11 14:10:14

KaiHH (156 views)
2015-10-11 13:26:18

BurntPizza (171 views)
2015-10-08 03:11:46
Rendering resources
by Roquen
2015-11-13 14:37:59

Rendering resources
by Roquen
2015-11-13 14:36:58

Math: Resources
by Roquen
2015-10-22 07:46:10

Networking Resources
by Roquen
2015-10-16 07:12:30

Rendering resources
by Roquen
2015-10-15 07:40:48

Math: Inequality properties
by Roquen
2015-10-01 13:30:46

Math: Inequality properties
by Roquen
2015-09-30 16:06:05

HotSpot Options
by Roquen
2015-08-29 11:33:11 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!