Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
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 1334 times)
0 Members and 1 Guest are viewing this topic.
Offline krzysiek050

Junior Newbie





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

Hello.

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;
1  
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 21:17:44 »

not sure, do ask in the libgdx forum !

http://www.badlogicgames.com/forum/

Offline theagentd
« Reply #2 - Posted 2013-03-05 00: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.

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

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

https://github.com/mattdesl/lwjgl-basics/wiki/Shaders

config.useGL20 = true;
must be set when creating the activity
isGL20Available()
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 02:20:16 »

Uhm, this seems like a thing to do with blending, for example (find the suitable)
http://zanir.wz.cz/programming/opengl/img/011_blending.jpg
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 11: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 13: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.

Myomyomyo.
Offline cylab

JGO Ninja


Medals: 38



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

See http://nehe.gamedev.net/tutorial/masking/15006/ 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 http://wiki.labomedia.org/images/1/10/Orange_Book_-_OpenGL_Shading_Language_2nd_Edition.pdf, 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  
 
 
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.

Riven (12 views)
2014-07-29 18:09:19

Riven (8 views)
2014-07-29 18:08:52

Dwinin (9 views)
2014-07-29 10:59:34

E.R. Fleming (26 views)
2014-07-29 03:07:13

E.R. Fleming (10 views)
2014-07-29 03:06:25

pw (39 views)
2014-07-24 01:59:36

Riven (39 views)
2014-07-23 21:16:32

Riven (27 views)
2014-07-23 21:07:15

Riven (28 views)
2014-07-23 20:56:16

ctomni231 (59 views)
2014-07-18 06:55:21
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!