Mobile App Development Publication

Sharing iOS, Android and relevant Mobile App Development Technology and Learning

Follow publication

Member-only story

Learning Android Development

Playing with Android canvas drawVertices

Making triangle into 3-d art like images

If you like some simple graphic drawing in Android Canvas, drawVertices is a pretty nice API to use. It could be used as the fundamental for drawing 3D images as shown below.

Anyway, before getting into that complexity, let’s learn the fundamental of the API.

I was searching for some tutorial explaining it and can’t any one for Android. So do some experiments and learn the API to share below.

Have fun!

Prerequisite

Unlike most of the API in the Canvas, in order to drawVertices to draw something, one need to disabled the Hardware Acceleration first using

setLayerType(View.LAYER_TYPE_SOFTWARE, null)

Why? It is simply because it is one of the unsupported feature in Hardware Acceleration as per documented at the point of writing this blog.

The API

The API have 12 arguments. 😱 Wow!

public void drawVertices (
Canvas.VertexMode mode, // THIS IS NEEDED
int vertexCount, // usually verts.size
float[] verts, // THIS IS NEEDED
int vertOffset, // usually 0
float[] texs, // can be nullable
int texOffset, // usually 0
int[] colors, // can be nullable
int colorOffset, // usually 0
short[] indices, // can be nullable
int indexOffset, // usually 0
int indexCount, // can be 0
Paint paint) // can be just Paint()

Let’s break it down into 4 different grouping.

1. The vertex datas

Canvas.VertexMode mode, // THIS IS NEEDED 
int vertexCount, // usually verts.size
float[] verts, // THIS IS NEEDED
int vertOffset, //…

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Mobile App Development Publication
Mobile App Development Publication

Published in Mobile App Development Publication

Sharing iOS, Android and relevant Mobile App Development Technology and Learning

Elye - A One Eye Dev By His Grace
Elye - A One Eye Dev By His Grace

Written by Elye - A One Eye Dev By His Grace

Sharing Software Learning, Life and Faith Journey

Responses (2)

Write a response