how would you implement this?

http://www.student.kun.nl/c.goedegebure/cataclysm/downloads/cdaynight.avi

The above is a movie link to a small game being developed called Cataclysm. The game sprites are all out of Zelda. The movie is a demo of theur day and night cycle. I was wonering how could this in theory be implemented using java? Is it a trancparent layer? or are all the pixels being grabbed and tweeked with? I dont plan oin doing this myself but was curious.

If you were using palettized textures, then you could achieve that effect simply by manipulating the pallete.

If you were using a direct color model of some kind, you’d have to alter the pixel values of the tiles.
Or add a filter in the rendering process.

Java2D can’t do any of those efficiently, go for LWJGL.

I have heard of this pallette stuff on these forums before but never understood what it ment exactly. As far as I can guess, you have a color pallete and all the images get their colors from that pallete. Changing a color on the pallette changes the color on the image that uses that pallette and that specific color. I think thats what it is but am not sure. Also how is that implemented? Some source code or a link would be really cool.

  1. You said add a filter during the rendering. Is that like laying a translucent color layer over everything else?

Yes. Pallette-manipulation is usually the way to go (because it’s fast). I did a lot of that stuff back in my TurboC/DOS days (you cant imagine how happy I was the day I found a 256 color bgi-driver ;))

How do I set up and do pallette manipulation. Can someone explain it to me please?

[quote]How do I set up and do pallette manipulation. Can someone explain it to me please?
[/quote]
In Java2D I don’t believe palette manipulation is possible. (yeah, core Java realy is crap for gfx :P)

you can do it in LWJGL easily enough. (Though don’t ask me how :P)

[quote]How do I set up and do pallette manipulation. Can someone explain it to me please?
[/quote]
This is how I have done simultaneous pixel manipulation + palette manipulation in Java 1.1 using MemoryImageSource and IndexColorModel

  1. Manipulate your palette / create new IndexColorModel
  2. Manipulate your pixels (if you want)
  3. Draw the new pixels with new palette to the screen using MemoryImageSource’s newPixel method which accepts a ColorModel as a parameter
  4. Goto step 1

[quote](yeah, core Java realy is crap for gfx :P)
[/quote]
No, 256 colours - THAT is crap for gfx :wink:

[quote]No, 256 colours - THAT is crap for gfx
[/quote]
Depends on the palette you can choose them from. There are millions of GIF users who are happy with 256 colors or less :wink:

I personally like the look of pixelated games better. They have more style. Theres just an art to the old CGA/256 color games that is just lost in 3d games nowadays. Everything is VERY bland.

Though I daresay pixelation lives on in the hearts and minds of people like myself. :slight_smile:

http://pixelation.swoo.net/

I think you’ll find that unless you’re using a proper palettised display (ie, DOS 13h or similar, not a display present in windows) then palettes are pretty much worthless. The final image needs to be converted from your palettised version into a true colour 16bit or 32bit image to actually be displayed, and the actual conversion is going to remove all possible speed ups.

The other option would be a full colour canvas, and paletted tiles, but then you get the same result, but the conversion happens earlier on drawing to your canvas. Plus you’re going to keep thrashing memory back and forth over the AGP bus if you want to keep changing the palette, making things worse for you.

Best way would be to create a load of different images at load time with the different colours, then switch between images at runtime. This way you can let the LRU image cache in vRAM do its thing and get no nasty performance eating colour conversions :slight_smile:

Or switch to lwjgl, where you can do all these funky image manipulations and more at full speed with multi-texture/multipass rendering ;D

Oh, and bedelf you should have a look at GBA programming, then you’re pretty much forced into using neat palette tricks to squeeze the most out of the limited colours (One 256 colour palette for sprites, one 256 (or 16 16-colour) palettes for tiles)

I probably would enjoy the games on the GBA graphically and gameplay wise, except i’ve never been able to stomach handhelds. :confused:

You tell that to Chaz, bedelf, and see which orifice of yours he sticks the 3dsmax manuals into :slight_smile:

Cas :slight_smile:

Here is example code how to do palette manipulation without touching the pixels with Java1.1:


import java.awt.*;
import java.awt.image.*;


public class paletteManipulation extends java.applet.Applet implements Runnable {
      private final static int width  = 640;
      private final static int height = 480;
      private final static int speed  = 2;

      Thread tr;
      public MemoryImageSource mis;
      private static Image image;
      Graphics screen;
      int[] jpgPixels = new int[width*height];
      byte[] pixels = new byte[width*height];

    public void run() {
            byte[] R = new byte[256];
            byte[] G = new byte[256];
            byte[] B = new byte[256];

              for(int i = 0; i < 256; i++) {
                  R[i] = (byte) i;
                  G[i] = (byte) i;
                  B[i] = (byte) i;
            }

            try {
                  MediaTracker track = new MediaTracker (this);
                  image = getImage(getDocumentBase(), "test.jpg");
                  track.addImage(image,666);
                  track.waitForAll();
                PixelGrabber ap = new PixelGrabber (image, 0, 0, width, height, jpgPixels, 0, width);
                while (ap.grabPixels() && ((ap.status() & ImageObserver.ALLBITS) == 0)) { }
            }
            catch (Exception e) {
                  e.printStackTrace ();
            }
            for(int i = 0; i < width*height; i++) {
                  pixels[i] = (byte) (jpgPixels[i] & 0xff);
            }

        screen  = getGraphics();
            mis = new MemoryImageSource (width, height, new IndexColorModel(8, 256, R, G, B), pixels, 0, width, null);
            mis.setAnimated(true);
          mis.setFullBufferUpdates(true);
          image = createImage(mis);

            boolean reset = false;
            while(true) {
                  if((R[0] & 0xff) == 0xff) {
                        reset = true;
                  }
                  else {
                        reset = false;
                  }

                  for(int i = 0; i < 256; i++) {
                        int color = (R[i] & 0xff);
                        if(reset == true) {
                              color  = i;
                        }
                        else {
                              color += speed;
                        }
                        if(color > 255) {
                              color = 255;
                        }
                        R[i] = (byte) (color & 0xff);
                        G[i] = (byte) (color & 0xff);
                        B[i] = (byte) (color & 0xff);
                  }
                  mis.newPixels(pixels, new IndexColorModel(8, 256, R, G, B), 0, width);
                    screen.drawImage(image, 0, 0, null);
            }
    }

      public void start() {
        if (tr == null) {
            tr = new Thread(this);
            tr.start();
        }
    }

    public void stop() {
          if (tr != null) {
            tr.stop();
            tr = null;
        }
    }
}

The code loads a grayscale jpg picture and then fades the palette until the picture is all white and then resets the palette and starts from the beginning. Basically you can do exactly the same “effect” as in the video with code similar to this one.

If you are working with large palettes (such as 24bit palette), realtime manipulation of the palette might be too slow. In this case, you can simply precalculate couple of palettes, such as “night palette” and “day palette” and then switch the palette very fast when needed without touching the pixels. Of course if you need a nice fading effect, you would need to precalculate a lot of palettes…

[quote]You tell that to Chaz, bedelf, and see which orifice of yours he sticks the 3dsmax manuals into :slight_smile:
[/quote]
ROFL. I imagine those books are quite large.

Anything smaller than a 17’ screen and I get headaches. Kinda sucks, I looked at some GBA screenshots a few months ago and I was like… I wish they made games like that for the PC still.

edit: acually, lately i’ve gotten a headache everytime i’ve played my xbox too :-/

You could take the long route around and buy a Gamecube and the GBA player for it, then you’d be able to play GBA games full screen on your tv ;D Not a cheap option though :-/

Ya I’m kinda lucky I even have an xbox to play on, all the games I’ve bought i’ve picked up for 10$.

So, ew. :slight_smile: