Android 我能';不要用opengl刷新我的屏幕
我试图学习opengl,但我有一些问题,因为很难找到有关它的信息 我可以在我的屏幕上创建一个表单,但我不能更新屏幕,我尝试了很多事情 在这里,我使用runnable,但不工作 谢谢你的帮助,这是我的surfaceView代码Android 我能';不要用opengl刷新我的屏幕,android,opengl-es,updates,runnable,Android,Opengl Es,Updates,Runnable,我试图学习opengl,但我有一些问题,因为很难找到有关它的信息 我可以在我的屏幕上创建一个表单,但我不能更新屏幕,我尝试了很多事情 在这里,我使用runnable,但不工作 谢谢你的帮助,这是我的surfaceView代码 public class MyGLSurfaceView extends GLSurfaceView implements Runnable{ int x1=1440,y1=2560,pub,i=1; private final MyGLRenderer mRendere
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();
}
}
}
公共类MyGLSurfaceView扩展了GLSurfaceView实现可运行{
int x1=1440,y1=2560,pub,i=1;
私人终审法院;
公共MyGLSurfaceView(上下文){
超级(上下文);
//创建OpenGL ES 2.0上下文。
setEGLContextClientVersion(2);
//修复错误没有选择配置,但我不知道这是做什么的。
super.setEGLConfigChooser(8,8,8,8,16,0);
//设置用于在GLSURFACHEVIEW上绘制的渲染器
mrender=新的MyGLRenderer();
setRenderer(mRenderer);
//仅当图形数据发生更改时渲染视图
setRenderMode(GLSurfaceView.RENDERMODE_脏时);
}
私人最终浮动接触比例系数=180.0f/320;
私人浮动MPX;
私家车;
公共无效modif(){
requestRender();
试试{Thread.sleep(20);}
捕获(异常e){}
@凌驾
公共事件(运动事件e){
//MotionEvent从触摸屏报告输入详细信息
//和其他输入控件。在这种情况下,您仅
//对触摸位置改变的事件感兴趣。
float x=e.getX();
float y=e.getY();
开关(如getAction()){
case MotionEvent.ACTION\u移动:
浮点数dx=x—mPreviousX;
浮动dy=y-mPreviousY;
//中线以上的反向旋转方向
如果(y>getHeight()/2){
dx=dx*-1;
}
//旋转方向与中线左侧相反
if(x
您似乎正在使用Android文档中的教程,对吗
要移动形状,必须在触摸屏幕时移动手指
你还想做点别的吗?当我再次读这首芭蕾舞曲时,我找到了解决办法,我把这行代码放在setRenderMode(GLSurfaceView.RENDERMODE_when_DIRTY)上;
我删除了该行,现在cpde工作。当您触摸/滑动它时,视图是否会更新?您说得对,但我在MyGlRender类的ondrawfram函数中有一些内容,可以查看差异。如果(iIs)调用了while循环中的“modif”?不确定是否应该使用可运行的GLSurfaceView。我不知道在可运行的GLSurfaceView上调用run()的位置,但我希望它不在主线程上。一段时间(true)在UI线程上不是一个好主意。我在每个可能的位置尝试不同的循环,但不起作用,当我放置循环时,屏幕是白色的,没有正方形。