int [] draw functions.

Can any1 point me in the direction of an api that implements the common draw functions on an argb int []? (primitve rendering, image drawing etc etc)

The sort that would be used with tinyPTC.

I had a glance at OpenPTC, but it didn’t appear immediately obvious if that was the intended use of the API.

Oh, 1.1 pls :wink: (I know… I know… i don’t need the ‘supporting dead APIs’ lecture ::))

You can create an image out of an array and render to it using Graphics (using MemoryImageSource, for example). Or is this not what you’re looking for?

You can do that?!

I can’t :-/


import java.awt.*;
import java.awt.image.*;
class Tests
{
   public static void main(String args[])
   {
      MemoryImageSource mis = new MemoryImageSource(640, 480, new int[640*480], 0, 640);
      Image img = Toolkit.getDefaultToolkit().createImage(mis);
      Graphics g= img.getGraphics();
   }
}

Exception in thread "main" java.lang.IllegalAccessError: getGraphics() only valid for images created with createImage(w, h)
        at sun.awt.windows.WImage.getGraphics(WImage.java:27)
        at Tests.main(Tests.java:25)

With java.awt.image.PixelGrabber you can grab the pixels of an java.awt.Image.

So I guess you could:

  1. create an Image with createImage(w, h)
  2. grab the Graphics object of the image and draw on it
  3. use PixelGrabber to get the data of the image

Haven’t tested this though.

[quote]With java.awt.image.PixelGrabber you can grab the pixels of an java.awt.Image.

So I guess you could:

  1. create an Image with createImage(w, h)
  2. grab the Graphics object of the image and draw on it
  3. use PixelGrabber to get the data of the image

Haven’t tested this though.
[/quote]
I’m talkin realtime :wink:

Resorting to pre-rendering primitives to an image, and blitting the image is just silly.

Without rewriting every single function in the Graphics class, i don’t believe it is possible with the 1.1 core api.

Some1 must have already rewritten all the Graphics functions so they operate on an int [], and put it in a nice neat pixel [] based API? ???

[quote]Some1 must have already rewritten all the Graphics functions so they operate on an int [], and put it in a nice neat pixel [] based API
[/quote]
This is sort of what we did at my last job. We made applet games, and we had our own library. We had a Pixels class with functions like drawImage, crop, fillRect etc. The drawImage functions supported add, sub, alphablending, scaling etc. We also had a Surface class that extended Pixels, with polygon rendering functions. Quite a nice lib actually. Unfortunatly the code is not mine to give away :frowning:

yeah, I figured a library like that would have some commercial value :frowning:

I guess there are similar libraries floating around for C; an int [] is an int [] - right :wink:

Oh, its possible; for more info - explore this link;

http://www.cfxweb.net/modules.php?name=Forums&file=viewtopic&t=51

you can find the cfxweb JACC (java applet coding contest) pages and some of them have the source code to the applets; there is some amazing stuff in there; including this snippet


// this is from Bloid's code

public MemoryImageSurface( int w, int h, Component parent )
  {
    this.parent = parent ;
    width = w ;
    height = h ;
    buffer = new int[ w * h ] ;
    source= new MemoryImageSource(w, h, model,buffer,0,w);
    source.setAnimated(true);
    image=parent.createImage(source);
     
  }

public Image getImage()  {
    source.newPixels();
    return image;
}

I have a mode7 applet on my site using something like the above;

www.geocities.com/nonnus29/mode7/mode7.htm

[quote] Some1 must have already rewritten all the Graphics functions so they operate on an int [], and put it in a nice neat pixel [] based API?
[/quote]
I actually started doing this recently using some of the JACC code; Bloids code already had blending and transparent blits and I added rotation, scaling and a mode7 function. I want to add solid filled triangles and perspective correct tri’s (I dont’ care about n-gons). It would all be open source of course; I basically just copy, paste, and modify other peoples code; the scaling, rotating and mode7 was origionally in C.

Can’t you just draw to a BufferedImage?
Then access the WriteableRaster…


BufferedImage bi = new BufferedImage(320,240, BufferedImage.TYPE_INT_RGB);
WriteableRaster rast = bi.getRaster();
DataBuffer buf = rast.getDataBuffer();
assert buf.getDataType() == DataBuffer.TYPE_INT;
DataBufferInt bufi = (DataBufferInt) buf;
int [] pixelData = bufi.getData();

1.1 :wink:

/me resists urge to lecture… (and promises himself to read more carefully next time :wink: )

I can. I just change the jdk code, recompile and voila =)

Sorry, forgot that you can’t render to toolkit images…

[quote] I want to add solid filled triangles and perspective correct tri’s (I dont’ care about n-gons). It would all be open source of course; I basically just copy, paste, and modify other peoples code; the scaling, rotating and mode7 was origionally in C.
[/quote]
I’ve been researching alot more about 3d software rendering; specifically clipping polygons to the view frustrum. All of a sudden I care very DEEPLY about n-gons; they make clipping polys so much nicer.