Skip to content

Instantly share code, notes, and snippets.

public class Shaders {
public static final String COLOR_VERTEX_SHADER =
"uniform mat4 uMVPMatrix;\n" +
"attribute vec4 vPosition;\n" +
"void main() {\n" +
" gl_Position = uMVPMatrix * vPosition;\n" +
" gl_PointSize = 10.0;\n" +
"}";
public static final String COLOR_FRAGMENT_SHADER =
public abstract class Model3D {
private Integer mProgram;
private int mColorHandle;
private float[] mColor;
private String mVertexShader;
private String mFragmentShader;
private void setupShaders() {
public class GLHelper {
private static final String TAG = "GLHelper";
public static void checkGlError(String glOperation) {
int error;
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
Log.e(TAG, glOperation + ": glError " + error);
throw new RuntimeException(glOperation + ": glError " + error);
}
public class GLCameraOptions {
public float eyeX;
public float eyeY;
public float eyeZ;
public float centerX;
public float centerY;
public float centerZ;
public float upX;
public float upY;
public float upZ;
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ar.com.wolox.easygl.view.EasyGLView
android:id="@+id/easygl"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
public class ExampleFragment extends Fragment {
private EasyGLView mEasyGLView;
private BasicGLRenderer mBasicRenderer;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_example, container, false);
mEasyGLView = (EasyGLView) viewGroup.findViewById(R.id.easygl);
public class EasyGLView extends GLSurfaceView {
public EasyGLView(Context context) {
super(context);
init();
}
public EasyGLView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
public class BasicGLRenderer implements GLSurfaceView.Renderer {
...
private List<Model3D> mModels = new LinkedList<>();
@Override
public void onDrawFrame(GL10 gl) {
...
for(Model3D model : mModels) {
model.draw(mMVPMatrix);
public class BasicGLRenderer implements GLSurfaceView.Renderer {
private final GLCameraOptions mGLCameraOptions;
private int mBackgroundColor;
private float[] mViewMatrix = new float[16];
private float[] mMVPMatrix = new float[16];
private float[] mProjectionMatrix = new float[16];
public BasicGLRenderer(GLCameraOptions glCameraOptions) {
mGLCameraOptions = glCameraOptions;
...
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
...