开发者

Multiple GLSurfaceView moving at the same time

开发者 https://www.devze.com 2023-03-29 13:30 出处:网络
I am facing an strange issue not sure why this is happening. I have a Java based Activity which has a LinearLayout. This LinearLayout consists of two GLSurfaceView. All the associated methods of GLSu

I am facing an strange issue not sure why this is happening.

I have a Java based Activity which has a LinearLayout. This LinearLayout consists of two GLSurfaceView. All the associated methods of GLSurfaceView like OnDraw, SurfaceChanged etc are moving call down to JNI layer. Inside the JNI layer I am drawing a cube using OpenGLES. I have also created a touch listener and have associated it with first GLSurfaceView. Once I get a touch event I move the call to JNI layer and randomly rotate the first cube.

Problem is when I rotate my first cube both the cubes rotates at exactly same angle. I have debugged this issue for last four hours and I am pretty sure there is nothing wrong in my logic. But for some unknown reason when I make change in one GLSurfaceView other cube changes automatically.

Any ideas? Similar issues? Guess?

Update

I am using same context i.e. my activity for both GLSurfaceView. Basically I have a class inside C++ which draws cube through opengles. Now I am successfully creating two cubes and displaying them simultaneously. Both cubes have different texture on them which I am passing via Java layer. My c++ class has a method which randomly rotates the cube. Problem is if I call method of one cube to rotate it other automatically开发者_StackOverflow中文版 rotates at same angle no make what I do.


Without your code, I'd guess you are initializing your GLSurfaceView's using the same context. When sharing a context changing one will change the other because they will share the same GL10 instance in the Renderer. I don't program in android, but in general you'd use multiple "viewports" to display different things.


Say that your first GLSurfaceView is on the first left side of your screen, and the second is on the second right half. One idea is to check what side the coordinates x, y of the motionEvent belongs to. And then pass rotation and translation accordingly.


Issue solved there was one logical mistake in my code

Sorry for inconvenience

0

精彩评论

暂无评论...
验证码 换一张
取 消