Search code examples
androidopengl-es3dvertex-buffer

How to draw a lines in opengl android


I've to draw squre using a lines, which will look like as following url.

http://www.thinkingwriting.qmul.ac.uk/wishees/tutorials/square.gif

Could you please tell me how to draw it in android using opengls GL_LINES or GL_LINES_STRIP


Solution

  • This is fairly simple, assuming you already have a working OpenGL context:

    • Set up an orthogonal projection
    • Build a vertex buffer containing the vertices of your square
    • When it comes time to render, set line rendering attributes (e.g. glLineWidth)
    • Render the vertex buffer using GL_LINE_LOOP or GL_LINES (depending how you set up your vertices)

    Take a look at this introduction to vertex buffers to get an idea of where to start. There are some much simpler tutorials but this one offers more background than most.