Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (603)
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  
  Implementing SNES's "Mode 7" effect?  (Read 4396 times)
0 Members and 1 Guest are viewing this topic.
Offline BoBear2681

JGO Coder


Medals: 19



« Posted 2010-07-01 22:12:40 »

Does anybody have an example of applying the old "Mode 7" pseudo-3D effect to 2D graphics rendered by Java2D?  Just thought I'd ask before blowing the dust off my old math books to refresh my memory on affine transformations.  Smiley
Offline ShannonSmith
« Reply #1 - Posted 2010-07-01 23:53:37 »

You won't easily be able to do it with Java2D as perspective projection is not an Affine Transform. The SNES was able to do it with it's affine transform  because it could be modified per-scanline something you can't really do with Java2D.

Offline Roquen
« Reply #2 - Posted 2010-07-02 04:13:14 »

You need to give more details.  Mode-7 alone is simply a point sampled bitmap that can be rotated.  As noted all other effects come from changing hardware parameters at desired scanlines.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline BoBear2681

JGO Coder


Medals: 19



« Reply #3 - Posted 2010-07-02 18:39:40 »

Thanks guys.  I'm just trying to simulate the pseudo-perspective effect that the overworld map has in Final Fantasy 3/6.  Nostalgia goggles help me overlook the fact that it looks quite horrid.

Some quick googling turned up this implementation in C.  I ported it to Java (it's all of maybe 20 lines), although I'm having a tough time figuring out the optimal values for the parameters for the look I want.

In my first-pass Java version, I pass it an input BufferedImage (the background, painted normally) and an output BufferedImage.  I'm currently basically doing this:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
static int[] inRGB = new int[w * h];
static int[] outRGB = new int[w * h];

public static void getMode7(BufferedImage in, BufferedImage out, ...) {

   in.getRGB(0,0, w,h, inRGB,0, w);

   for (int y=0; y<h; y++) {
      ... stuff ...
      for (int x=0; x<w; x++) {
         ... stuff ...
      }
   }

   out.setRGB(0, 0, w,h, outRGB,0, w);
   out.flush();

}


Unfortunately, this is unusably slow, taking about ~0.05 seconds per call to getMode7() for a 512x512 image.  My naive timing of sections of this method seem to show that the getRGB() and setRGB() calls are the bottleneck.  Not to mention that there's no chance of my "out" image being accelerated.  Is there a better way do do this sort of thing?
Offline ShannonSmith
« Reply #4 - Posted 2010-07-02 19:12:39 »

Don't use setRGB/getRGB they are slow, just grab the underlying buffers and modify directly:
1  
int[] inRGB = ((DataBufferInt)in.getRaster().getDataBuffer()).getData();

Offline DzzD
« Reply #5 - Posted 2010-07-02 19:13:41 »

once again dont use setRGB / get RGB

rather use

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
int pixelsInput[]=((DataBufferInt)(in.getRaster().getDataBuffer())).getData(); 

int pixelsOutput[]=((DataBufferInt)(out.getRaster().getDataBuffer())).getData();

int ofs=0;
for(int y=0;y<height;y++)
{
 int ofsY=y*width;
 for(int x=0;x<width;x++)
 {
   int ofs=x+ofsY;
   int pixel=pixelsInput[ofs];
   ...
    perform per pixel operation here
   ...
   pixelsOutput[ofs]=pixel;
 }
}


EDIT: I am 1 minute late !

Offline BoBear2681

JGO Coder


Medals: 19



« Reply #6 - Posted 2010-07-02 19:16:59 »

Yes, I just found the solution myself in an older post by Riven.  Seems more than fast enough now.

Cheers guys!
Offline provenza24

Senior Newbie


Projects: 1



« Reply #7 - Posted 2010-10-17 22:42:47 »

hi all,

i'm very interested in Mode 7, do
you have a sample of code, or a demo to show/give please please ?

thanx
Offline Cero
« Reply #8 - Posted 2010-11-21 17:59:27 »

I would be pretty interested in results too.

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.

rwatson462 (31 views)
2014-12-15 09:26:44

Mr.CodeIt (23 views)
2014-12-14 19:50:38

BurntPizza (50 views)
2014-12-09 22:41:13

BurntPizza (84 views)
2014-12-08 04:46:31

JscottyBieshaar (45 views)
2014-12-05 12:39:02

SHC (59 views)
2014-12-03 16:27:13

CopyableCougar4 (57 views)
2014-11-29 21:32:03

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

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

toopeicgaming1999 (32 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

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