rearview mirror

Started by athanazio, December 02, 2006, 03:45:08 AM

Previous topic - Next topic

EgonOlsen

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.

athanazio

I tried this way :

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

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

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

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 ?

EgonOlsen

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.

athanazio

thanks worked fine !!!

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
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)
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)
protected void paintComponent(Graphics g) {
if (buffer != null) {
buffer.display(g, leftBorderWidth, titleBarHeight);
afterPaintComponent(g);
}
}


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

Mizuki Takase

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

EgonOlsen

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.

athanazio

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


athanazio

the problem was the size restrictions of the Texture, I changed the size of the viewport and averybody got happy !!! thanks !!!


athanazio

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

Mizuki Takase

I thought that the TextureInfo class has something to do with multi-texturing... Quoting from the javadoc...

QuoteTextureInfo 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...

EgonOlsen

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.

Mizuki Takase

^_^;;; Oh well... One could at least dream I guess.... Thanks for the reply on that subject matter...