Rendering SVG with OpenGL (and OpenGL ES)

前端 未结 6 539
情歌与酒
情歌与酒 2021-01-29 22:37

I am currently investigating the possibility of rendering vector graphics from an SVG file using OpenGL and OpenGL ES. I intend to target Windows and Android. My ideal solution

6条回答
  •  死守一世寂寞
    2021-01-29 23:24

    From http://shivavg.svn.sourceforge.net/viewvc/shivavg/trunk/src/shPipeline.c?revision=14&view=markup :

    static void shDrawVertices(SHPath *p, GLenum mode)
    {
    int start = 0;
    int size = 0;
    
    /* We separate vertex arrays by contours to properly
    handle the fill modes */
    glEnableClientState(GL_VERTEX_ARRAY);
    glVertexPointer(2, GL_FLOAT, sizeof(SHVertex), p->vertices.items);
    
    while (start < p->vertices.size) {
    size = p->vertices.items[start].flags;
    glDrawArrays(mode, start, size);
    start += size;
    }
    
    glDisableClientState(GL_VERTEX_ARRAY);
    }
    

    So it does use a VBO. So I'd suggest making your own SVG parser / use a pre-made one, and forward the calls to ShivaVG.

    You still have the problem that ShivaVG is in C (and not in Java) and creates an opengl context (and not opengles, if I read the code correctly). So even if you compile it using Android's NDK, you'll have to modify the code ( for instance, I've seen a few glVertex3f around, but they don't seem to be much needed... hope for the best). The other option, of course, it to port the code from C to Java. Maybe not as painful as you could imagine.

    Good luck !

提交回复
热议问题