我无法使用 opengl 刷新屏幕
I can't refresh my screen with opengl
我尝试学习 opengl,但我遇到了一些问题,因为很难找到关于它的信息。
我可以在我的屏幕上创建一个表单,但我不能更新屏幕,我尝试了很多东西。
这里我用的是runnable,但是没有效果。
感谢您的帮助,这是我的 surfaceView 代码
public class MyGLSurfaceView extends GLSurfaceView implements Runnable{
int x1=1440,y1=2560,pub,i=1;
private final MyGLRenderer mRenderer;
public MyGLSurfaceView(Context context) {
super(context);
// Create an OpenGL ES 2.0 context.
setEGLContextClientVersion(2);
//fix for error No Config chosen, but I don't know what this does.
super.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
// Set the Renderer for drawing on the GLSurfaceView
mRenderer = new MyGLRenderer();
setRenderer(mRenderer);
// Render the view only when there is a change in the drawing data
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
private final float TOUCH_SCALE_FACTOR = 180.0f / 320;
private float mPreviousX;
private float mPreviousY;
public void modif(){
requestRender();
try{Thread.sleep(20);}
catch(Exception e){}}
@Override
public boolean onTouchEvent(MotionEvent e) {
// MotionEvent reports input details from the touch screen
// and other input controls. In this case, you are only
// interested in events where the touch position changed.
float x = e.getX();
float y = e.getY();
switch (e.getAction()) {
case MotionEvent.ACTION_MOVE:
float dx = x - mPreviousX;
float dy = y - mPreviousY;
// reverse direction of rotation above the mid-line
if (y > getHeight() / 2) {
dx = dx * -1 ;
}
// reverse direction of rotation to left of the mid-line
if (x < getWidth() / 2) {
dy = dy * -1 ;
}
mRenderer.setAngle(
mRenderer.getAngle() +
((dx + dy) * TOUCH_SCALE_FACTOR)); // = 180.0f / 320
requestRender();
case MotionEvent.ACTION_DOWN:
modif();
}
mPreviousX = x;
mPreviousY = y;
return true;
}
public void run(){
while(true){
modif();
}
}
}
您似乎正在使用 Android 文档中的教程,对吗?
https://developer.android.com/training/graphics/opengl/touch.html#angle
要移动形状,您必须在触摸屏幕的同时移动手指。
您是否正在尝试完成其他事情?
当我再次阅读 tuto 时,我找到了解决方案,我把行 setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
I delete the line and now the cpde working.
我尝试学习 opengl,但我遇到了一些问题,因为很难找到关于它的信息。
我可以在我的屏幕上创建一个表单,但我不能更新屏幕,我尝试了很多东西。
这里我用的是runnable,但是没有效果。
感谢您的帮助,这是我的 surfaceView 代码
public class MyGLSurfaceView extends GLSurfaceView implements Runnable{
int x1=1440,y1=2560,pub,i=1;
private final MyGLRenderer mRenderer;
public MyGLSurfaceView(Context context) {
super(context);
// Create an OpenGL ES 2.0 context.
setEGLContextClientVersion(2);
//fix for error No Config chosen, but I don't know what this does.
super.setEGLConfigChooser(8 , 8, 8, 8, 16, 0);
// Set the Renderer for drawing on the GLSurfaceView
mRenderer = new MyGLRenderer();
setRenderer(mRenderer);
// Render the view only when there is a change in the drawing data
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
private final float TOUCH_SCALE_FACTOR = 180.0f / 320;
private float mPreviousX;
private float mPreviousY;
public void modif(){
requestRender();
try{Thread.sleep(20);}
catch(Exception e){}}
@Override
public boolean onTouchEvent(MotionEvent e) {
// MotionEvent reports input details from the touch screen
// and other input controls. In this case, you are only
// interested in events where the touch position changed.
float x = e.getX();
float y = e.getY();
switch (e.getAction()) {
case MotionEvent.ACTION_MOVE:
float dx = x - mPreviousX;
float dy = y - mPreviousY;
// reverse direction of rotation above the mid-line
if (y > getHeight() / 2) {
dx = dx * -1 ;
}
// reverse direction of rotation to left of the mid-line
if (x < getWidth() / 2) {
dy = dy * -1 ;
}
mRenderer.setAngle(
mRenderer.getAngle() +
((dx + dy) * TOUCH_SCALE_FACTOR)); // = 180.0f / 320
requestRender();
case MotionEvent.ACTION_DOWN:
modif();
}
mPreviousX = x;
mPreviousY = y;
return true;
}
public void run(){
while(true){
modif();
}
}
}
您似乎正在使用 Android 文档中的教程,对吗?
https://developer.android.com/training/graphics/opengl/touch.html#angle
要移动形状,您必须在触摸屏幕的同时移动手指。
您是否正在尝试完成其他事情?
当我再次阅读 tuto 时,我找到了解决方案,我把行 setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
I delete the line and now the cpde working.