Log in or register to post comments

vbvertice on Virtual Button sample

December 18, 2012 - 11:11am #1

I wonder how the virtual button rendered on the screen?

why there's 96 vertices just to render 4 virtual button? 

yeah this particular code is really confuse me 


 // We add the vertices to a common array in order to have one single 
            // draw call. This is more efficient than having multiple glDrawArray calls
            vbVertices[vbCounter   ]=vbRectangle->getLeftTopX();
            vbVertices[vbCounter+ 1]=vbRectangle->getLeftTopY();
            vbVertices[vbCounter+ 2]=0.0f;
            vbVertices[vbCounter+ 3]=vbRectangle->getRightBottomX();
            vbVertices[vbCounter+ 4]=vbRectangle->getLeftTopY();
            vbVertices[vbCounter+ 5]=0.0f;
            vbVertices[vbCounter+ 6]=vbRectangle->getRightBottomX();
            vbVertices[vbCounter+ 7]=vbRectangle->getLeftTopY();
            vbVertices[vbCounter+ 8]=0.0f;
            vbVertices[vbCounter+ 9]=vbRectangle->getRightBottomX();
So I want to create my own virtual button from a trackables, but I don't know how to create and render it on screen just by looking at the sample. so If there's any clear step by step tutorial of how to create virtual button that would really help a lot. 

You're welcome.

December 20, 2012 - 6:25am #6

You're welcome.

okay , I am finally able to

December 20, 2012 - 6:21am #5

okay , I am finally able to draw virtual button correctly . thanks!


Exactly, you got it right, a

December 20, 2012 - 3:33am #4

Exactly, you got it right, a vertex array of 9 elements would look like the "vertices[9]" example that you wrote.

About rendering order, there are two possibilities:

- if using indexed vertex arrays (i.e. a vertex array + an array of indices), then the order in which the vertices are "consumed" to build the lines or triangles is specified by the indices in the index array; in this case you would use the glDrawElements() function (like in the ImageTargets sample)

- if using "plain" vertex arrays (i.e. without index array), then the order in which the vertices are picked up to build the lines (or the triangles) will be the same order as the vertices appear in the array.

You may also want to have a look at the OpenGL developer guide to learn more about this subject, or to the Android / OpenGL dev guide:


I hope this helps.


*sigh Is this site have no

December 19, 2012 - 8:23pm #3

*sigh Is this site have no cookies? I have to login everytime I open this site* *ignore that*

anyway what I get from your answer is that the array contain x,y, and z in just a single dimensional array, right?

so it would looks like this -> 

vertices[9] =

{ x1,y1,z1,




 and about the drawing order? oh yeah is this array rendered as a line or a triangles?

I am sorry if my question is silly. thanks :)

Hi, the vertex array

December 19, 2012 - 8:11am #2

Hi, the vertex array "vbVertices" contains the coordinates of the end-points of the line segments that make up the buttons;

every coordinate in the vbVertices is one of the three X,Y,Z of a vertex (and as you can see, every three cordinates you have a "0.0f" value, which is the Z component of each point)


- in total we have 4 buttons in the VB sample

- each button is represented by a rectangle, consisting of 4 line segments (the 4 sides of the rectangle);

- each line segment is defined by two points

- each point is defined by 3 coordinates (X, Y and Z);


So, here is the math:   4 buttons  X  4 segments  X  2 points per segment  X 3 coords per point  = 4 x 4 x 2 x 3 = 96 elements


In general, dealing with OpenGL vertex array can be tricky / difficult; it usually requires some extensive practice and familiarity with OpenGL programming.

I hope this helps.

Log in or register to post comments