Author Topic: rearview mirror  (Read 16316 times)

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
rearview mirror
« Reply #15 on: December 05, 2006, 04:58:06 pm »
You may consider to get the raw pixel data from the framebuffer what represents the mirror and feed that into an implementation of an ITextureEffect that is attached to the "mirror texture". That way, you can skip the BufferedImage.

Offline athanazio

  • byte
  • *
  • Posts: 49
    • View Profile
    • http://www.athanazio.pro.br
rearview mirror
« Reply #16 on: December 06, 2006, 04:11:29 am »
I tried this way :

Code: [Select]
public class ViewPortEffect implements ITextureEffect {

private FrameBuffer fb;

public ViewPortEffect(FrameBuffer fb) {
this.fb = fb;
}

public void apply(int[] dest, int[] source) {
dest = fb.getPixels();
}

public void init(Texture arg0) {
}


}


and set the effect to the Texture object

Code: [Select]
public ViewPort(World master, int width, int height) {

this.camera = new Camera();
this.width = width;
this.height = height;
this.w = master;

fb = new FrameBuffer(width, height, FrameBuffer.SAMPLINGMODE_NORMAL);
fb.enableRenderer(IRenderer.RENDERER_SOFTWARE);

texture = TextureManager.getInstance().getDummyTexture();
texture.setEffect(new ViewPortEffect(fb));

// buffer = new BufferedImage(width, height,
// BufferedImage.TYPE_INT_RGB);
// g2 = buffer.createGraphics();

}


at my loop the render method of the viewport is called

Code: [Select]
public void render() {
Camera foo = w.getCamera();
w.setCameraTo(camera);

fb.clear();
w.renderScene(fb);
w.draw(fb);
fb.update();
texture.applyEffect();

w.setCameraTo(foo);
}


and at the creation of the objects I set the texture to the new one ...

Code: [Select]
mirror = new ViewPort(getWorld(), 256, 256);
Camera c = mirror.getCamera();
getTextureManager().replaceTexture("mirror", mirror.getTexture());

c.setPosition(80, -70, 80);
c.lookAt(SimpleVector.ORIGIN);


but I got nothing at the mirror ... any idea ? I'm missing something ?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
rearview mirror
« Reply #17 on: December 06, 2006, 08:53:25 am »
Quote from: "athanazio"

   public void apply(int[] dest, int[] source) {
      dest = fb.getPixels();
   }
This can't work, because you are just setting the reference locally. Copy the pixels from fb.getPixels() into dest[] with System.arraycopy instead.

Offline athanazio

  • byte
  • *
  • Posts: 49
    • View Profile
    • http://www.athanazio.pro.br
rearview mirror
« Reply #18 on: December 06, 2006, 02:24:34 pm »
thanks worked fine !!!

Code: [Select]
public void apply(int[] dest, int[] source) {
System.arraycopy(fb.getPixels(), 0, dest, 0, fb.getPixels().length);
}


trying to optimize the code, I'm looking for a way to remove the Graphics operations, and use the blit method, in order to draw the upper box with a blit over the main frambuffer

done this :

this the method to draw the current viewport
Code: [Select]
public void display(FrameBuffer buffer, int x, int y) {
if (buffer != null) {
buffer.blit(getTexture(), 0, 0, x, y, getTexture().getWidth(),
getTexture().getHeight(), false);
}
// fb.display(g, x, y);
}


that is called by (that its in my game class)
Code: [Select]
public void afterPaintComponent(Graphics g) {

rearview.display(getBuffer(), 30, 30);

g.setColor(Color.WHITE);
g.drawRect(30, 30, 300, 100);
g.drawString(Integer.toString(lastFPS) + "FPS", 15, 15);
}


and its called by my gamesuper class (that is a Jcomponent)
Code: [Select]
protected void paintComponent(Graphics g) {
if (buffer != null) {
buffer.display(g, leftBorderWidth, titleBarHeight);
afterPaintComponent(g);
}
}


but ... I got nothing at the white box ...

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
rearview mirror
« Reply #19 on: December 06, 2006, 03:05:47 pm »
I wonder... Since you are creating an ITextureEffect, does that mean that reflective or chromed surfaces are possible? I would love to see that~!!

Off topic: I love the Lamborghini Mucielago! Definitively can not afford one, but oh well....

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
rearview mirror
« Reply #20 on: December 06, 2006, 03:40:35 pm »
Maybe the buffer that holds the mirror view hasn't been updated!? Try to call update(); on it before making the blit and see if that helps.

Offline athanazio

  • byte
  • *
  • Posts: 49
    • View Profile
    • http://www.athanazio.pro.br
rearview mirror
« Reply #21 on: December 06, 2006, 04:28:00 pm »
I got the problem ! I was updating the framebuffer AFTER the display ... like this is harder to see something hehehehe, anyway now at least I see something ... still wrong ... probably the size of the texture or something like this ...

the FPS are increasing :) around 10 when hanging around the mirror and around 20 without the mirror


Offline athanazio

  • byte
  • *
  • Posts: 49
    • View Profile
    • http://www.athanazio.pro.br
rearview mirror
« Reply #22 on: December 06, 2006, 04:55:24 pm »
the problem was the size restrictions of the Texture, I changed the size of the viewport and averybody got happy !!! thanks !!!


Offline athanazio

  • byte
  • *
  • Posts: 49
    • View Profile
    • http://www.athanazio.pro.br
rearview mirror
« Reply #23 on: December 06, 2006, 04:58:19 pm »
Mizuki,
reflexive texture... humm is there possible to put one texture one over the other like layers ? if so we can use the technique that I used and merge the original texture, with a view of something that is around, creating the reflexive effect ... :D

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
rearview mirror
« Reply #24 on: December 06, 2006, 05:05:36 pm »
I thought that the TextureInfo class has something to do with multi-texturing... Quoting from the javadoc...

Quote
TextureInfo is jPCT's key to multi texturing. Multi texturing is supported by the OpenGL renderer only. You may still use the software renderer to render such a scene, but it will simply ignore the additional texture stages. You can use addTriangle() or setTexture() in Object3D to define a polygon or the whole object as multi textured.
You can use any combination of textures and blending modes for a polygon. jPCT will try to optimize the texture state changes when rendering the image. However, don't overuse this feature on a single object, because jPCT can only do so much.
If you are adding more layers than the hardware supports, jPCT will switch to multi pass rendering automatically. Due to the way the OpenGL pipeline is specified, this may produce different results compared to one pass multi texturing. This happens most when using transparency, fog or blending modes like MODE_ADD, when the card's internal accuracy is higher than the framebuffer's.


Atleast the class seem simple to use; the one and only function is add...

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
rearview mirror
« Reply #25 on: December 06, 2006, 06:39:43 pm »
Yes, but the software renderer ignores all texture layers but the first. Or in other words: It can do single texturing only. The hardware renderer can do more (which is what TextureInfo is mostly for), but it currently can't do, what athanazio is doing here, because it can't render to texture.
What you have in mind is cubic environment mapping with dynamic environment maps. jPCT can't do this. However, it can do spherical environment mapping with a static texture, which should be sufficient for simple, chrome like surfaces.

Offline Mizuki Takase

  • int
  • **
  • Posts: 97
    • View Profile
rearview mirror
« Reply #26 on: December 06, 2006, 08:28:26 pm »
^_^;;; Oh well... One could at least dream I guess.... Thanks for the reply on that subject matter...