Đây là những gì tôi đã làm cho Emitter Hạt của tôi: Hỗ trợ một GLSurfaceView và làm nó là một phần của bố cục của tôi. Lưu ý: thực hiện các lớp "ParticleRenderer" để đạt được bất cứ điều gì thứ OpenGL bạn muốn làm
My Tuỳ chỉnh xem:
public class OpenGLView extends GLSurfaceView
{
//programmatic instantiation
public OpenGLView(Context context)
{
this(context, null);
}
//XML inflation/instantiation
public OpenGLView(Context context, AttributeSet attrs)
{
this(context, attrs, 0);
}
public OpenGLView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs);
// Tell EGL to use a ES 2.0 Context
setEGLContextClientVersion(2);
// Set the renderer
setRenderer(new ParticleRenderer(context));
}
}
và trong cách bố trí ...
<com.hello.glworld.particlesystem.OpenGLView
android:id="@+id/visualizer"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
Hạt Render thẳng về phía trước ... đối với một số mã mẫu, xem: https://code.google.com/p/opengles-book-samples/source/browse/trunk/Android/Ch13_ParticleSystem/src/com/openglesbook/particlesystem/ParticleSystemRenderer.java
public class ParticleRenderer implements GLSurfaceView.Renderer
{
public ParticleRenderer(Context context)
{
mContext = context;
}
@Override
public void onDrawFrame(GL10 gl)
{
//DO STUFF
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
//DO STUFF
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
//DO STUFF
}
}
Nguồn
2013-11-19 03:30:46
Thanx! Đọc trên SurfaceView ngay bây giờ. Nó cảm thấy như những gì tôi đang sau, nhưng tôi không thể tìm ra cách để thực sự làm điều đó. Tôi có thể thiết lập SurfaceView trong tệp xml bố cục. Và tôi có thể đặt setContentView() để sử dụng bố cục xml đó. Nhưng tôi không thể thấy cách làm cho lớp GLSurfaceView của tôi vẽ ra SurfaceView của tệp sơ đồ bố trí xml. – Espen
Ồ, GLSurfaceView là một SurfaceView, vì vậy bạn chỉ có thể sử dụng nó trong bố cục nơi bạn đang sử dụng SurfaceView. –