Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (844)
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  
  Libgdx - Texutre masking  (Read 6072 times)
0 Members and 1 Guest are viewing this topic.
Offline krzysiek050

Junior Newbie

« Posted 2013-03-04 12:03:29 »


I have 2 images.

The first is my base image. It will be loaded to TextureRegion. So, lets make assumption i have it loaded for variable;
TextureReguion koala = ...;

I don't want draw entire image, but only pixel who cover black pixels in my shape.png image. But this may not be persist change. In future i want just take off the mask and draw entire picture. Format of mask is flexible. This is only example.  I can use anyone.
Can You write few line of code which can do this and draw masked texture on SpriteBatch?
Offline Cero
« Reply #1 - Posted 2013-03-04 20:17:44 »

not sure, do ask in the libgdx forum !

Offline theagentd
« Reply #2 - Posted 2013-03-04 23:36:25 »

Use a shader. Sample the first texture, sample the second texture, multiply them together. Well, since your mask texture is black where you want the other texture to be seen, I suppose you'd have to invert the value of the mask texture before doing the multiply though.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline davedes
« Reply #3 - Posted 2013-03-05 00:05:37 »

Check out my tutorial series. One of the lessons includes a very similar effect.

config.useGL20 = true;
must be set when creating the activity
must return true

If you want the masking to work on GLES10, you'll need to tinker with texture combiners and blend modes.

Offline xsvenson
« Reply #4 - Posted 2013-03-05 01:20:16 »

Uhm, this seems like a thing to do with blending, for example (find the suitable)
Unless there is some more to it.

davedes' shader tutorial is very well written though. Should read that too

“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Offline krzysiek050

Junior Newbie

« Reply #5 - Posted 2013-03-05 10:27:11 »

Shaders is pretty hard to newbe i think. But i found information this is dooable with stencil test. Unluckly any of my try to do this faild. Can you write simple example code using this method?
Offline theagentd
« Reply #6 - Posted 2013-03-05 12:03:41 »

To use the stencil test for this effect (without shaders), you'd have to render the mask texture as geometry (= a 5 vertex polygon creating a pentagon), not a rectangular textured quad with a texture of a pentagon. However, if you do that there's nothing stopping you from completely getting rid of the extra pass, since you can just directly put the koala texture on your 5 vertex polygon.

Offline cylab

JGO Kernel

Medals: 180

« Reply #7 - Posted 2013-03-05 13:06:17 »

See for a non-shader implementation.

Shaders is pretty hard to newbe i think.
Everything in OpenGL is hard for a newby, but learning how to use shaders in the first place saves you a ton of other hard stuff you won't need anyway as soon as you are capable of using shaders...

Take your time and read, at least Chapters 4,5,9 and 10, but best the whole book.

Don't whine about it being 600+ pages - the book will save you much more time than you will spend reading it.  Tongue

Mathias - I Know What [you] Did Last Summer!
Pages: [1]
  ignore  |  Print  

EgonOlsen (58 views)
2018-06-10 19:43:48

EgonOlsen (40 views)
2018-06-10 19:43:44

EgonOlsen (60 views)
2018-06-10 19:43:20

DesertCoockie (225 views)
2018-05-13 18:23:11

nelsongames (141 views)
2018-04-24 18:15:36

nelsongames (140 views)
2018-04-24 18:14:32

ivj94 (881 views)
2018-03-24 14:47:39

ivj94 (142 views)
2018-03-24 14:46:31

ivj94 (793 views)
2018-03-24 14:43:53

Solater (157 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 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!