Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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 2127 times)
0 Members and 1 Guest are viewing this topic.
Offline 2playgames

Junior Member





« Posted 2008-03-18 21: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 Member





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

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

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
                    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 Coder


Medals: 2


falling into the abyss of reality


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

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

/docs/api/java/awt/Composite.html

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.

Make Elite IV:Dangerous happen! Pledge your backing at KICKSTARTER here!
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline erikd

JGO Knight


Medals: 3
Projects: 3


Maximumisness


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

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

Offline 2playgames

Junior Member





« Reply #4 - Posted 2008-03-19 15: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 17: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.
1  
2  
3  
4  
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.

Simon

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

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.122 seconds with 20 queries.