Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (526)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (593)
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  
  LWJGL pixel manipulation ?  (Read 3065 times)
0 Members and 1 Guest are viewing this topic.
Offline PixelDeBurner

Junior Devvie


Medals: 1



« Posted 2012-09-12 17:17:06 »

Hi.

In java2D I used BufferedImage and array of pixels to modify it and then render it on the screen. Is there something similar to this in lwjgl ?
Offline davedes
« Reply #1 - Posted 2012-09-12 17:56:14 »

You can modify the bytes and re-upload them to the GPU with glTexImage2D or glTexSubImage2D. Usually this is fast enough (i.e. if you are doing it at initialization, or even a couple times per frame) but for better performance and asynchronous transfers you can use a Pixel Buffer Object.

Depending on the situation (i.e. inverting the colours of an image and other post-processing effects), you might be better off just using fragment (i.e. "pixel") shaders.

You can also use "render to texture" techniques (e.g. Frame Buffer Objects) depending on how you are trying to manipulate a texture.

So the real question is: what are you trying to accomplish?

Offline PixelDeBurner

Junior Devvie


Medals: 1



« Reply #2 - Posted 2012-09-12 18:45:22 »

Damn, that's a load of informations Smiley

I'm trying to do simple stuff like multypling image by color, or change pixels of i.e. pink color to red... or stuff like that. I would like to learn those fragment shaders stuff too.

Do you know what's the best technique to use ?
Also do you have a link on some good fragment shaders tutorials ?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #3 - Posted 2012-09-12 19:59:29 »

Definitely do that kind of stuff with a fragment shader. You should know that you can multiply a texture by a color easily by just setting glColor() to whatever you want it multiplied by, right?

Myomyomyo.
Offline PixelDeBurner

Junior Devvie


Medals: 1



« Reply #4 - Posted 2012-09-12 20:36:02 »

Didn't know that LOL Smiley

But I still wanna learn fragment shaders Smiley
Offline davedes
« Reply #5 - Posted 2012-09-12 23:04:39 »

Vertex coloring is the easiest way to modify an image like that, but it's a bit limited.

Regarding shaders:

What are you using for image decoding / texture loading? If it's SlickUtil, I'd recommend pulling the latest Slick code and using the ShaderProgram utility. LibGDX also has a ShaderProgram utility, or you can write your own very easily.

Then I'd recommend browsing some tutorials like this or reading some OpenGL books like this (see ra4king's Java ports) to learn the theory behind it. There is also more info at the following websites:
http://open.gl/
http://duriansoftware.com/joe/An-intro-to-modern-OpenGL.-Table-of-Contents.html

I'd also recommend "learning by example" -- see here for some Slick-specific examples.

Offline PixelDeBurner

Junior Devvie


Medals: 1



« Reply #6 - Posted 2012-09-15 19:41:12 »

I'm having trouble.

Can someone show me some simple stuff with explanation, doesn't matter is it shader or anything else. What I want to do is take color ( purple ) fom texture and replace it with anoder color ( pink ).

How would you perform this ?
Offline davedes
« Reply #7 - Posted 2012-09-15 20:23:32 »

Are you doing this at initialization? Or do you need to be doing it in real-time, e.g. every frame?

If the former:

Grab the pixels into a ByteBuffer (either through something like PNGDecoder, or glGetTexImage). Create a new buffer with the same size. Loop through the returned pixels putting each into the new buffer -- however, if any are equal to "purple" then you substitute it with "pink." Upload the new buffer into the old texture with glTexImage2D.

Offline PixelDeBurner

Junior Devvie


Medals: 1



« Reply #8 - Posted 2012-09-15 20:32:36 »

I need it in real time. The ByteBuffer thing is I don't know how to use. That's what I need explained.
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #9 - Posted 2012-09-15 21:21:49 »

I'd make the texture black-and-white. By doing that, you can just set the color of the white/gray parts using glColor(), since the color from glColor() is multiplied per pixel with the texture sample color.


White texture color * red glColor() color = (1, 1, 1) * (1, 0, 0) = (1, 0, 0) = red
Gray texture color * green glColor() color = (0.5, 0.5, 0.5) * (0, 1, 0) = (0, 0.5, 0) = somewhat dark green
etc...

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

Junior Devvie


Medals: 1



« Reply #10 - Posted 2012-09-15 22:26:43 »

I'd make the texture black-and-white. By doing that, you can just set the color of the white/gray parts using glColor(), since the color from glColor() is multiplied per pixel with the texture sample color.


White texture color * red glColor() color = (1, 1, 1) * (1, 0, 0) = (1, 0, 0) = red
Gray texture color * green glColor() color = (0.5, 0.5, 0.5) * (0, 1, 0) = (0, 0.5, 0) = somewhat dark green
etc...

I know that but I still want to learn different techniques ( I hope I spelled last word correctly ).
Offline theagentd

« JGO Bitwise Duke »


Medals: 361
Projects: 2
Exp: 8 years



« Reply #11 - Posted 2012-09-15 22:34:01 »

I'd make the texture black-and-white. By doing that, you can just set the color of the white/gray parts using glColor(), since the color from glColor() is multiplied per pixel with the texture sample color.


White texture color * red glColor() color = (1, 1, 1) * (1, 0, 0) = (1, 0, 0) = red
Gray texture color * green glColor() color = (0.5, 0.5, 0.5) * (0, 1, 0) = (0, 0.5, 0) = somewhat dark green
etc...

I know that but I still want to learn different techniques ( I hope I spelled last word correctly ).
Like?

Myomyomyo.
Offline PixelDeBurner

Junior Devvie


Medals: 1



« Reply #12 - Posted 2012-09-16 08:47:45 »

The ones davedes mentioned.
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.

toopeicgaming1999 (71 views)
2014-11-26 15:22:04

toopeicgaming1999 (60 views)
2014-11-26 15:20:36

toopeicgaming1999 (14 views)
2014-11-26 15:20:08

SHC (27 views)
2014-11-25 12:00:59

SHC (25 views)
2014-11-25 11:53:45

Norakomi (31 views)
2014-11-25 11:26:43

Gibbo3771 (25 views)
2014-11-24 19:59:16

trollwarrior1 (38 views)
2014-11-22 12:13:56

xFryIx (77 views)
2014-11-13 12:34:49

digdugdiggy (55 views)
2014-11-12 21:11:50
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!