1

I'm beginning in OpenGL ES on Android (Java); I'm following this tutorial : http://developer.android.com/training/graphics/opengl/projection.html

Things basically go well, except that I have some trouble with matrix-multiplication that I didn't have on desktop OpenGL (where I used GLM instead of java/android framework) My projection+view matrix does'nt work correctly when I do projection * view * vec4(..coords..) The only way for my geometry to be shown is to multiply by right : vec4(...) * MVP, where MVP is Projection*View. It shouldn't work (as far as I'm concerned) but... it does. At least a little bit. I get massive clipping problems by using this way, but it's still better than nothing :D

My problem is kinda similar to this (and same tutorial, but it looks like it got updated) : Android OpenGL weirdness with the setLookAtM method

But it looks like I have the opposite problem now. And I've tried every combination I've imagined to solve this (transpose MVP in GLSL, multiply view by projection and not the other way around, etc.)

Here's my code

 //GLSL :
 gl_Position =  vec4(vPosition, 1.0) * MVP;

Where MVP is mMVPMatrix, which is defined as ...

 Matrix.setLookAtM(mCameraMatrix, 0, 8, 8, -8, 0f, 0f, 0f, 0.0f, 1.0f, 0.0f);
 Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mCameraMatrix, 0);

And projection is

float ratio = (float) width / height;

android.opengl.Matrix.frustumM(mProjectionMatrix, 0, -ratio, ratio, -1, 1, 3, 7);

Any idea ?

Community
  • 1
  • 1
bisthebis
  • 523
  • 2
  • 10
  • Does'nt look to work (well, with multiplication as you tell me AND multiplication vec4 * MVP, I get an hideous result instead of an almost correct result, and with MVP * vec4, I get nothing...) BTW, what doc says looks like it's in OpenGL : If you do this : Projection * View * vec4, projection gets applied last, but is LHS. That's how I undesrtood it – bisthebis Mar 01 '16 at 17:59
  • Maybe you're right. Still, it doesn't solve my problem. How strange – bisthebis Mar 01 '16 at 18:03
  • 1
    Forget all I said, you were right... I downloaded a sample from Android SDK and they use as you used it. – Gusman Mar 01 '16 at 18:07
  • Suggestion: http://www.learnopengles.com/android-lesson-one-getting-started/ – fadden Mar 01 '16 at 18:27
  • Nice resource indeed, but AFAIK, the steps I've followed are almost exactly the same... I can't find what I did different – bisthebis Mar 01 '16 at 18:47

1 Answers1

0

Problem solved : I just had to set my MVP Matrix to Identity before computing it, and this, every frame

bisthebis
  • 523
  • 2
  • 10