公共类MainActivity扩展ActionBarActivity实现Drawer {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GLSurfaceView surface = new GLSurfaceView(this);
setContentView(surface);
int[] id = new int[]{R.drawable.panorama};
surface.setRenderer(new SpriteBatcher(this, id, this));
}
@Override
public void onDrawFrame(GL10 gl, SpriteBatcher sb) {
sb.drawLine(R.drawable.panorama,new Rect(0,0,400,400),10,10,200,200,10);
}
}
我有一种情况,我想在屏幕上部分绘制,而不是使用opengl使用整个屏幕。目前我编写的代码在glSurfaceView上呈现图像,但它占用了整个屏幕。我发现gl.glScissor()可以用来实现我想要实现的目标,但我不知道如何使用它,因为我特别熟悉android和OpenGL。谢谢。
答案 0 :(得分:0)
我已经弄明白了,这是我的代码,
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GLSurfaceView surface = (GLSurfaceView)findViewById(R.id.glSurfaceViewID);
int[] id = new int[]{R.drawable.panorama};
surface.setEGLConfigChooser(true);
surface.setRenderer(new SpriteBatcher(this, id, this));
surface.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
@Override
public void onDrawFrame(GL10 gl, SpriteBatcher sb) {
sb.drawLine(R.drawable.panorama,new Rect(0,0,400,400),10,10,200,200,10);
}
这是我的布局activity_main,
<LinearLayout
android:id="@+id/fragment2"
android:orientation="vertical"
android:divider="#000000"
android:layout_width="500dp"
android:layout_height="match_parent">
<android.opengl.GLSurfaceView
android:id="@+id/glSurfaceViewID"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.opengl.GLSurfaceView>
</LinearLayout>
我使用了名为android-sprite-batcher的库 - https://github.com/twicecircled/Android-Sprite-Batcher