Load a SVG file as a plan in a 3D scene

Hello !

I’m a novice in OpenGL but theoretically what I want to do does not seem that complicated.
Basically, I have a svg file describing a grid with possibly some use of opacity, text, gradient, etc, and I would like to open this SVG as the plan z=0 in my 3D scene, and built on it with positive z shapes.
(An example of application if you need to picture a result could be to import a svg description of a city map, and add building with their relative size using OpenGL).

One way to do it would be to create a rectangle and apply a texture on it, this texture being extracted from an image. (As described in this tutorial).
However, as the content of the SVG file is not an array of color, it is not handled by library as SOIL. Converting my .svg in an other format imply the loss/degradation of one or several among the opacity, text or gradient features.

An other lead is to find a library to simply render a SVG file in the openGL environment.
I worked with glsvg :
https://pypi.org/project/glsvg/#description
https://github.com/fathat/glsvg
It does not handle the text tags, but I can live with it !
My current problem is to handle the rotation along the x and/or y axis when a drag with the right button is detected.

Here is my current implementation :

    def on_mouse_drag(self, x, y, dx, dy, buttons, modifiers):
        if buttons & mouse.RIGHT:
            self.ax += dy # if I move my mouse vertically, the object rotates around the x axis
            self.ay += dx # if I move my mouse horizontally, the object rotates around the y axis
    def on_draw(self):
        glClearColor(1, 1, 1, 1)
        self.clear()
        glPushMatrix()

        # set projection matrix to have top-left be (0,0), as
        # SVGs are defined in that way
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(0.0, self.width, self.height, 0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
        glDisable(GL_TEXTURE_2D)
        glTranslatef(-self.offset_x, -self.offset_y, 0)

        glRotatef(self.ax,1,0,0)
        glRotatef(self.ay,0,1,0)

        self.svg.draw(self.draw_x, self.draw_y, scale=self.zoom, angle=self.angle)

        glPopMatrix()
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL)

        # reverse y projection for pyglet stats drawing
        # (because pyglet expects (0,0) to be bottom left
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluOrtho2D(0.0, self.width, 0, self.height)
        glMatrixMode(GL_MODELVIEW)

The behavior is not exactly the expected one as the svg projection does not follow the rotated plan. Am I rotating in the wrong matrix mode ?

Finally, if you have an other idea for a simpler way to do what I described at the beginning, your insights are welcome !

Thank you :wink:

PS : I attached a zip with the whole glsvg project if needed. Look at the ‘my_visualizer.py’ file