#1625 Extending of gfx

go4 Sat 27 Aug 2011

I try to enhance the fwt graphics. The API like this:

Path:

//path test
path := Path().moveTo(20f, 20f).lineTo(20f, 30f).
  quadTo(25f, 25f, 30f, 15f).cubicTo(40f, 30f, 50f, 40f, 60f, 70f).close

g.brush = Color.green
g.fillPath(path)
g.brush = Color.black
g.drawPath(path)

echo(path.contains(21f, 25f))
echo(path.contains(20f, 40f))

Transfom:

//transform
trans := Transform2D().scale(0f, 0f, 3f, 3f).translate(10f, 40f).rotate(10f, 10f, 0.5f)
g.setTransform(trans)

Image:

//image filter
for (i:=0; i < p.size.w; ++i)
{
  for (j:=0; j < p.size.h; ++j)
  {
    c := p.getPixel(i,j)
    nc := Color.makeArgb(c.a, c.r, 0, 0)
    p.setPixel(i, j, nc)
  }
}

//get Graphics context from image
Graphics2 g := p.graphics

//save image
Void save(OutStream out, MimeType format := MimeType.forExt("png"))

There is more example code

brian Mon 29 Aug 2011

I think full SVG like pathing and transforms are definitely something we should add at some point. I was originally going to add them, but its actually quite a bit of work to do them properly and you can do an awful lot of nice graphics without them. The problem is that a proper implementation should be mostly contained to gfx, but in reality we would probably want to call out to SWT/JS for some of the more complicated geometry aspects (or end up rewriting some complicated code).

Saving images to file is something we actually have a backdoor hook for in JS, not sure it is supported in SWT (if you know how please post).

go4 Tue 30 Aug 2011

The new Graphics is called gfx2.The OpenGL binding is called fogl. Although they in one repository, fogl is no something to do with gfx2.

fan3d

The fan3d contains the following pod:

  • gfx2: extending of gfx
  • gfx2Imp: implementation of gfx2
  • fogl: direct openGL/WebGL binding.
  • lib: LWJGE is a java openGL port.
  • array: primary number array
  • math: math lib for 2d/3d transformation. This is pure fantom implementation.
  • jsTest: examples for test.

Status

gfx2 works both SWT and JS, but need some more test.

fogl all most at here. Most OpenGL/WebGL API mapped to Fantom.

Runing

There are lots of example code in jsTest/fan/jsFan/.

setting LWJGE:

  1. copy all .jar to fanHome/lib/java/ext/
  2. modify fanHome/ect/sys/congif.proops: java.options=-Xmx512M -Djava.library.path=yourPath/lib/lwjgl-2.7.1/native/windows

If you want to run on the WebGl, need get a new browser.

@Brian

I don't know how to Save the Image in Js. But it is simple in SWT:

public void save(OutStream out, MimeType format)
{
  ImageLoader loader = new ImageLoader();
  loader.data = new ImageData[] { imageData };
  OutputStream jout = Interop.toJava(out);

  int swtFormat = SWT.IMAGE_PNG;
  String subType = format.subType();
  if (subType.equals("png")) swtFormat = SWT.IMAGE_PNG;
  else if (subType.equals("gif")) swtFormat = SWT.IMAGE_GIF;
  else if (subType.equals("jpeg")) swtFormat = SWT.IMAGE_JPEG;
  else if (subType.equals("jpg")) swtFormat = SWT.IMAGE_JPEG;
  else if (subType.equals("bmp")) swtFormat = SWT.IMAGE_BMP;
  else if (subType.equals("tiff")) swtFormat = SWT.IMAGE_TIFF;
  else if (subType.equals("ico")) swtFormat = SWT.IMAGE_ICO;
  else throw UnsupportedErr.make("unsupported image type: "+subType);

  loader.save(jout, swtFormat);
}

brian Fri 2 Sep 2011

This is really gread @go4. Thanks for posting that SWT code. We already have a backdoor hook for JS image saves, so with that we can probably get that API working. I will put it on my todo list (have a couple things like this I wanted to get into 1.0.60, but just ran out of time before our US holiday and wanted to get the build posted).

go4 Sat 24 Sep 2011

I get the gfx2 API working in AWT(Java2d) and Android(Skia). I think the AWT is good at service-side(multi-thread enviroment) than SWT.

But, there is a bit issue when change the paint engine. Fwt.java,line 59:

Actor.locals().add("gfx.env", FwtEnv.make());

I change it to:

Actor.locals().set("gfx.env", FwtEnv.make());

And it works well.

brian Sat 24 Sep 2011

I pushed that that

go4 Mon 26 Sep 2011

Thanks

tompalmer Thu 29 Sep 2011

Happened to stop by again. The whole WebGL/LWJGL and Canvas/Java2D/SWT/Skia thing is very compelling.

Login or Signup to reply.