2017-06-13 53 views
0

我嘗試學習opengl,但由於很難找到關於它的信息,所以我遇到了一些問題。我可以在屏幕上創建一個表單,但我無法更新屏幕,我嘗試了很多東西。 這裏我使用runnable,但沒有任何工作。 感謝您的幫助,這是我的surfaceView我無法用opengl刷新我的屏幕

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(); 
    } 
} 

} 
+0

請問您的視圖更新的政黨成員,當你觸摸/刷卡呢? – Reaper

回答

0

代碼看來你正在使用從Android文檔教程,對不對?

https://developer.android.com/training/graphics/opengl/touch.html#angle

爲了移動形狀,必須在觸摸屏移動你的手指。

你想要完成別的東西嗎?

+0

你說得對,但是我在MyGlRender類的ondrawfram函數中看到了一些區別。如果(i <-1.0f){i = 1.0f;} 其他{i- = 0.1f;} mSquare.draw(scratch,i,0.8f);我允許改變廣場,但形式不會發展。當我觸摸屏幕時,正方形只會移動並變形 –

+0

您的while循環中的「修改」是否曾被調用過? – Xys

+0

不確定一個可運行的GLSurfaceView是否可行。我不知道你在可運行的GLSurfaceView上調用了run(),但我希望它不在主線程中。在UI線程上一段時間(真)不是一個好主意。 – Xys

0

我找到解決辦法,當我再次readed,我放線setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); I delete the line and now the cpde working.