[Solved]Has any function could set the ViewPort into the special region?

Has any function could set the ViewPort into the special region?

I try to use the ‘cam.setViewPort’ to cut the screen into two triangles (drawed as below), but I can only cut the viewport into two squares (just like what we can see in “Dynasty Warriors”, 2 players).

Could anyone teach me how to do this?

| \ Cam2 |
|            |
|             |
|            |
|Cam1 \ |

Thank you very much!!

Did you consider using stencil buffers already?

Anyone here with a better idea?

Stencil buffer is the best approach, this is exactly what it was designed for.

Mr. Momoko_Fan
Could you give me the sample or some codes to let me learn how to do this?
Thanks a lot~

Unfortunately there are no tests showing off stencil buffer functionality (as you can tell, its not commonly used these days).
You will need to go based on non jME3 tutorials, e.g. OpenGL / DirectX.

Render to texture as a workaround? (works now, test case available, lose about 50% of fps, but hey…)

Btw … what’s with the timing of two view ports or two cameras? I mean, at 10 fps - is one image 10% in the past compared to the other image? (just curious, because this whole timings question will become interesting for me soon)

I’m not sure who you are asking exactly… but you may need to rephrase the question. I read it three times and still I’m not sure what you meant. What does 10% in the past mean?

Sorry, did not want to derail this thread, but did not want to lose that thought either.

The thought is as follows:
a) render two viewports or two textures
b) have a situation where fps are low (e.g. 10)
c) 1st render is 0.1 seconds prior to the 2nd render
d) result: time gap: one image is 0.1 sec old, other image 0.2 sec old.
d) if both should be at same point in time - how to fix it?
(idea 1: stop time, render both, continue)
(idea 2: prevent low frame rates at all cost)

Well, why are you rendering them at different frames in the first place? It doesn’t make any sense.

I just did not need so much fine control until now and assumed that you can’t render into two textures in parallel at exactly the same time. Maybe I will open a new topic when my “frozen game logic” feature is about to be needed. Thanks for now, but I think I officially derailed this thread - sorry. :chimpanzee_nogood:

Could override the some functions or extends the class has reach this effects?
Thanks everyone!!!

Take a look on this code :

Its not working for me because I am using bones, but for your game using 2d it probably will work.

One idea is to use “render to texture”.
Here is an example: jme3test.post.TestRenderToTexture.java

You render to texture Texture1 with your Cam1.
You render to texture Texture2 with your Cam2.
You then make a “custom mesh” for triangle Triangle1 for Cam1.
You then make a “custom mesh” for triangle Triangle2 for Cam2.
Triangle1 uses Texture1, and Triangle2 uses Texture2.
You then attach the Triangle1 and Triangle2 to the “guiNode”.

Understand me? :chimpanzee_smile:

It is a little bit slow - you will lose some “frames per second” because you render 2 images and will not use the full image (only one half is used - triangle instead of rectangle). But it can be done.

Maybe someone can make an example. Maybe I can make an example during this week.


Thank you for your prompt reply.
I learned the documents and tried to use the following codes, but the screen is blank.
I’m not sure whether the codes is correct.

[Codes start]

Mesh mesh = new Mesh();

Vector2f[] coord = new Vector2f[ 4 ];
coord[0] = new Vector2f( 0, 0 );
coord[1] = new Vector2f( 1, 0 );
coord[2] = new Vector2f( 0, 1 );

mesh.setBuffer( Type.TexCoord, 2, BufferUtils.createFloatBuffer( coord ) );

Geometry triangle1 = new Geometry(“Triangle”, mesh );

Material mat = new Material( assetManager, “Common/MatDefs/Misc/Unshaded.j3md” );
Texture texture = assetManager.loadTexture( “Textures/Monkey.jpg” );
mat.setTexture( “texture1”, texture );
triangle1.setMaterial( mat );
guiNode.attachChild( triangle1 );

[Codes end]

Thank you very much!

Your mesh is only 1 pixel big and it has no texture coordinates.

Probably better just to use Quad since it will setup all of the mesh-related stuff properly.

(Edit: I see now that you are making a triangle… still, the rest of the stuff I said is true. You can look at Quad.java to see how to set things up for a single triangle… though from your original screen shot you actually want a trapezoid so a Quad may be a better place to start.)

I tried to fix this problem, but still has no any effects.
Could you help me check this?
Thank you very much.

[Codes start]
Mesh mesh = new Mesh();

Vector2f[] coord = new Vector2f[3];
coord[0] = new Vector2f(0,0);
coord[1] = new Vector2f(200,0);
coord[2] = new Vector2f(0,200);

mesh.setBuffer(Type.TexCoord, 2, BufferUtils.createFloatBuffer(coord));
mesh.scaleTextureCoordinates(new Vector2f(200 , 200));
[Codes end]

I fix it.

But I have some problems.
How do I do to render the scene to the mesh?

Thanks everyone~

[Codes start]
Mesh mesh = new Mesh();

Vector2f[] vertices = new Vector2f[ 3 ];
vertices[ 0 ] = new Vector2f( 0, 0 );
vertices[ 1 ] = new Vector2f( 500, 0 );
vertices[ 2 ] = new Vector2f( 0, 500 );

Vector2f[] texCoord = new Vector2f[ 3 ];
texCoord[ 0 ] = new Vector2f( 0, 0 );
texCoord[ 1 ] = new Vector2f( 1, 0 );
texCoord[ 2 ] = new Vector2f( 0, 1 );

mesh.setBuffer( Type.Position, 2, BufferUtils.createFloatBuffer( vertices ) );
mesh.setBuffer( Type.TexCoord, 2, BufferUtils.createFloatBuffer( texCoord ) );

Geometry geom = new Geometry( “TriangleMesh”, mesh );
Material mat = new Material( assetManager, “Common/MatDefs/Misc/Unshaded.j3md” );
mat.setColor( “Color”, ColorRGBA.Red );
geom.setMaterial( mat );

guiNode.attachChild( geom );
[Codes end]

You render the scene to a texture as has already been linked here and is done in the TestRenderToTexture example included with JME.

In the SDK → File → New Project → JME3 → JME3 Tests → package jme3test.post → file TestRenderToTexture.java

Why is the package jme3test.post not in this javadoc? I only found jme3test.android


I have no idea. I will make sure to dock the documentation staff’s pay. :wink: