Hi !
Featured games (87)
games approved by the League of Dukes
Games in Showcase (672)
Games in Android Showcase (194)
games submitted by our members
Games in WIP (727)
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  
  trying to make anaglyph - how to composite  (Read 3165 times)
0 Members and 1 Guest are viewing this topic.
Offline 2playgames

Junior Devvie

« Posted 2008-03-18 20:37:59 »

I'm trying to give my game an anaglyph render mode. I've created two buffers (one left one right, both as Image) and drawn different things on them, but I can't find out how to composite them onto a single graphics objects.

I need to draw only the red channel of the left buffer, then draw the blue and green channels of the right buffer on top of that. I've searched and searched, but I can only find compositing with AlphaComposite, which doesn't work per-channel.

Who can help me with my original rendering?  Roll Eyes

Offline 2playgames

Junior Devvie

« Reply #1 - Posted 2008-03-19 00:48:47 »

so i've found a solution, but it's what you could call "manual work" and slow as ***

                    final BufferedImage leftImg = bufferLeft.getImage();
                    final BufferedImage rightImg = bufferRight.getImage();
                    final BufferedImage comboImg = bufferCombo.getImage();

                    final int[] pxLeft = leftImg.getRGB(0, 0, getWidth(), getHeight(), null, 0, getWidth());
                    final int[] pxRight = rightImg.getRGB(0, 0, getWidth(), getHeight(), null, 0, getWidth());
                    final int[] combo = new int[pxLeft.length];

                    for (int p = 0; p < getWidth() * getHeight(); p++) {
                        combo[p] = (pxLeft[p] & 0xFFFF0000) | (pxRight[p] & 0xFF00FFFF);

                    comboImg.setRGB(0, 0, getWidth(), getHeight(), combo, 0, getWidth());
                    graphics.drawImage(bufferCombo, new Point(0, 0));

it also doesn't quite work, i can see bits of the right image with my left eye, but that's probably because of my bad 3d glasses

Offline Abuse

JGO Ninja

Medals: 48

falling into the abyss of reality

« Reply #2 - Posted 2008-03-19 01:51:05 »

I believe the intended way of doing this would be to define your own Composite.


You then perform the pixel composition though the Raster & WritableRaster instances passed to you.

It might be faster than your above implementation, but it certainly won't be fast.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja

Medals: 16
Projects: 4
Exp: 14 years


« Reply #3 - Posted 2008-03-19 10:42:41 »

If you want a lightning fast and simple solution, use OpenGL (using glColorMask).

Offline 2playgames

Junior Devvie

« Reply #4 - Posted 2008-03-19 14:59:58 »

an interesting note, i've done some benchmarking and most time is swallowed by getRGB and secondly by setRGB

anyway, i'll try those options

Offline dishmoth
« Reply #5 - Posted 2008-03-19 16:57:24 »

an interesting note, i've done some benchmarking and most time is swallowed by getRGB and secondly by setRGB

It may be faster to access the pixels directly using something like the following.
BufferedImage image = ...;
WritableRaster raster = image.getRaster();
int pixels[] = ((DataBufferInt)(raster.getDataBuffer())).getData();
// now modify the pixels

The array of pixels should be in a similar format to what you've got in your example code (but the exact format may depend on how the BufferedImage was created, so be warned!).

Once you've modified an image in this way, it won't be hardware accelerated (unless you copy it to a fresh BufferedImage).  I don't know whether the Composite approach (as Abuse suggests) has the same drawback.


Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

IanParcs (45 views)
2016-04-18 14:18:53

KaiHH (45 views)
2016-04-18 08:35:41

KaiHH (75 views)
2016-04-15 12:43:58

theagentd (76 views)
2016-04-14 02:16:17

theagentd (90 views)
2016-04-14 02:15:43

IanParcs (104 views)
2016-04-12 03:51:16

IanParcs (47 views)
2016-04-12 03:50:03

IanParcs (43 views)
2016-04-12 03:49:54

IanParcs (38 views)
2016-04-12 03:49:52

IanParcs (48 views)
2016-04-12 03:49:52
Website offering 3D Models specifically for games for free
by vusman
2016-04-29 12:56:17

List of Learning Resources
by SilverTiger
2016-02-05 09:39:47

List of Learning Resources
by SilverTiger
2016-02-05 09:38:38

List of Learning Resources
by SilverTiger
2016-02-05 09:35:50

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 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!