Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (577)
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 2469 times)
0 Members and 1 Guest are viewing this topic.
Offline 2playgames

Junior Duke





« 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 Duke





« 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 ***

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 Knight


Medals: 13


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.

/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! https://dl.dropbox.com/u/54785909/EliteIVsmaller.png
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


Maximumisness


« 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 Duke





« 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.
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.

 

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

The first screenshot will be displayed as a thumbnail.

Longarmx (49 views)
2014-10-17 03:59:02

Norakomi (38 views)
2014-10-16 15:22:06

Norakomi (31 views)
2014-10-16 15:20:20

lcass (34 views)
2014-10-15 16:18:58

TehJavaDev (65 views)
2014-10-14 00:39:48

TehJavaDev (65 views)
2014-10-14 00:35:47

TehJavaDev (54 views)
2014-10-14 00:32:37

BurntPizza (72 views)
2014-10-11 23:24:42

BurntPizza (43 views)
2014-10-11 23:10:45

BurntPizza (84 views)
2014-10-11 22:30:10
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!