[COMMITTED] Viewports and ORTHO queue Patch

hey guys (and girls?).



as seen on this thread http://www.jmonkeyengine.com/jmeforum/index.php?topic=8692.0



nothing was done there so far i guess and since i stumbled upon the same bug, i applied the changes and created a patch.



I will of course ask the original author if he wants to commit  :wink:



Index: src/com/jme/renderer/lwjgl/LWJGLRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (revision 4087)
+++ src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (working copy)
@@ -552,7 +552,9 @@
         matRecord.switchMode(GL11.GL_PROJECTION);
         GL11.glPushMatrix();
         GL11.glLoadIdentity();
-        GLU.gluOrtho2D(0, width, 0, height);
+        float viewportWidth = width * (camera.getViewPortRight() - camera.getViewPortLeft());
+        float viewportHeight = height * (camera.getViewPortTop() - camera.getViewPortBottom());
+        GLU.gluOrtho2D(0, viewportWidth, 0, viewportHeight);
         matRecord.switchMode(GL11.GL_MODELVIEW);
         GL11.glPushMatrix();
         GL11.glLoadIdentity();
Index: src/com/jme/renderer/AbstractCamera.java
===================================================================
--- src/com/jme/renderer/AbstractCamera.java   (revision 4087)
+++ src/com/jme/renderer/AbstractCamera.java   (working copy)
@@ -1047,8 +1047,8 @@
         tmp_quat.set( worldPosition.x, worldPosition.y, worldPosition.z, 1 );
         modelViewProjection.mult( tmp_quat, tmp_quat );
         tmp_quat.multLocal( 1.0f / tmp_quat.w );
-        store.x = ( ( tmp_quat.x + 1 ) * ( viewPortRight - viewPortLeft ) / 2 + viewPortLeft ) * getWidth();
-        store.y = ( ( tmp_quat.y + 1 ) * ( viewPortTop - viewPortBottom ) / 2 + viewPortBottom ) * getHeight();
+        store.x = ( ( tmp_quat.x + 1 ) * ( viewPortRight - viewPortLeft ) / 2 ) * getWidth();
+        store.y = ( ( tmp_quat.y + 1 ) * ( viewPortTop - viewPortBottom ) / 2 ) * getHeight();
         store.z = ( tmp_quat.z + 1 ) / 2;
 
         return store;



Andy

Has the issue of the changes effect on the stats graph (and maybe other side effects) been addressed?

I believe that was one of the 'loose ends' left around by the old guys (XD),  maybe its something that's important enough to get on the 2.0 list…

nymon said:

Has the issue of the changes effect on the stats graph (and maybe other side effects) been addressed?


damn, i forgot that, I'll check as soon as i can and get back to you.

well, i tested the StatGraph with the TestCloth testcase and I cannot see any difference with the applied Patch I posted above.



Can someone confirm that?

I get:


Parsing of patch file failed: Invalid unified diff range: @@ -552,7 +552,9 @@



Maybe you need to recreate the patch w/ the newest source...

so, heres the newly created patch. The root directory of the diff is the project root directory. I think thats ok?



Index: src/com/jme/renderer/lwjgl/LWJGLRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (revision 4093)
+++ src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (working copy)
@@ -553,7 +553,9 @@
         matRecord.switchMode(GL11.GL_PROJECTION);
         GL11.glPushMatrix();
         GL11.glLoadIdentity();
-        GLU.gluOrtho2D(0, width, 0, height);
+        float viewportWidth = width * (camera.getViewPortRight() - camera.getViewPortLeft());
+        float viewportHeight = height * (camera.getViewPortTop() - camera.getViewPortBottom());
+        GLU.gluOrtho2D(0, viewportWidth, 0, viewportHeight);
         matRecord.switchMode(GL11.GL_MODELVIEW);
         GL11.glPushMatrix();
         GL11.glLoadIdentity();
Index: src/com/jme/renderer/AbstractCamera.java
===================================================================
--- src/com/jme/renderer/AbstractCamera.java   (revision 4093)
+++ src/com/jme/renderer/AbstractCamera.java   (working copy)
@@ -1047,8 +1047,8 @@
         tmp_quat.set( worldPosition.x, worldPosition.y, worldPosition.z, 1 );
         modelViewProjection.mult( tmp_quat, tmp_quat );
         tmp_quat.multLocal( 1.0f / tmp_quat.w );
-        store.x = ( ( tmp_quat.x + 1 ) * ( viewPortRight - viewPortLeft ) / 2 + viewPortLeft ) * getWidth();
-        store.y = ( ( tmp_quat.y + 1 ) * ( viewPortTop - viewPortBottom ) / 2 + viewPortBottom ) * getHeight();
+        store.x = ( ( tmp_quat.x + 1 ) * ( viewPortRight - viewPortLeft ) / 2 ) * getWidth();
+        store.y = ( ( tmp_quat.y + 1 ) * ( viewPortTop - viewPortBottom ) / 2 ) * getHeight();
         store.z = ( tmp_quat.z + 1 ) / 2;
 
         return store;



can someone confirm (see last post)?

Looks good here, although doesn't the JOGL renderer need the same changes?





(never could get patch to apply, same error; had to 'install' by hand…)

i have no clue as to why the patch wouldn't work. In Eclipse there are thress possible patch root directories (Workspace, Project and Selection), whereas Selection should be the same as project when you selected the project  :expressionless:



Here a new patch with the changes to the JOGLRenderer:



Index: src/com/jme/renderer/jogl/JOGLRenderer.java
===================================================================
--- src/com/jme/renderer/jogl/JOGLRenderer.java   (revision 4093)
+++ src/com/jme/renderer/jogl/JOGLRenderer.java   (working copy)
@@ -569,7 +569,9 @@
         matRecord.switchMode(GL.GL_PROJECTION);
         gl.glPushMatrix();
         gl.glLoadIdentity();
-        glu.gluOrtho2D(0, width, 0, height);
+        float viewportWidth = width * (camera.getViewPortRight() - camera.getViewPortLeft());
+        float viewportHeight = height * (camera.getViewPortTop() - camera.getViewPortBottom());
+        glu.gluOrtho2D(0, viewportWidth, 0, viewportHeight);
         matRecord.switchMode(GL.GL_MODELVIEW);
         gl.glPushMatrix();
         gl.glLoadIdentity();
Index: src/com/jme/renderer/lwjgl/LWJGLRenderer.java
===================================================================
--- src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (revision 4093)
+++ src/com/jme/renderer/lwjgl/LWJGLRenderer.java   (working copy)
@@ -553,7 +553,9 @@
         matRecord.switchMode(GL11.GL_PROJECTION);
         GL11.glPushMatrix();
         GL11.glLoadIdentity();
-        GLU.gluOrtho2D(0, width, 0, height);
+        float viewportWidth = width * (camera.getViewPortRight() - camera.getViewPortLeft());
+        float viewportHeight = height * (camera.getViewPortTop() - camera.getViewPortBottom());
+        GLU.gluOrtho2D(0, viewportWidth, 0, viewportHeight);
         matRecord.switchMode(GL11.GL_MODELVIEW);
         GL11.glPushMatrix();
         GL11.glLoadIdentity();
Index: src/com/jme/renderer/AbstractCamera.java
===================================================================
--- src/com/jme/renderer/AbstractCamera.java   (revision 4093)
+++ src/com/jme/renderer/AbstractCamera.java   (working copy)
@@ -1047,8 +1047,8 @@
         tmp_quat.set( worldPosition.x, worldPosition.y, worldPosition.z, 1 );
         modelViewProjection.mult( tmp_quat, tmp_quat );
         tmp_quat.multLocal( 1.0f / tmp_quat.w );
-        store.x = ( ( tmp_quat.x + 1 ) * ( viewPortRight - viewPortLeft ) / 2 + viewPortLeft ) * getWidth();
-        store.y = ( ( tmp_quat.y + 1 ) * ( viewPortTop - viewPortBottom ) / 2 + viewPortBottom ) * getHeight();
+        store.x = ( ( tmp_quat.x + 1 ) * ( viewPortRight - viewPortLeft ) / 2 ) * getWidth();
+        store.y = ( ( tmp_quat.y + 1 ) * ( viewPortTop - viewPortBottom ) / 2 ) * getHeight();
         store.z = ( tmp_quat.z + 1 ) / 2;
 
         return store;



Tested the JOGLRenderer with TestCloth. works.

I guess NB doesn't like Eclipse's patches (can't we all just get along hehe)



Changes look good here though.  Tested JOGL and LWJGL with box color (ussed status ofc) as well as TestText…

coolio  :smiley:



well, in case someone is working with two screens and rendering ORTHO stuff to them, he/she must have used workarounds for this bug in the past (doubling width). Commiting this bug will force them to remove their workarounds.



I will wait 2 days from now on and then commit.



so long,

Andy

dhdd said:

well, in case someone is working with two screens and rendering ORTHO stuff to them, he/she must have used workarounds for this bug in the past (doubling width).


Your assumption is correct, thanks for fixing :)

the fix is in on the trunk, however not on the development branch. Shall I commit to the branch too?

Give me just a minute and I will merge the 2 branches…

thx basixs



EDIT: although the minutes is more than up and it seems its not merged yet?  :wink:

Sorry, I got sidetracked yesterday; merging now…

done