pythonc++copenglpyopengl

Export OpenGL model as .OBJ


I'm writing a simple PyOpenGL code, with the display part as:

glBegin(GL_LINE_LOOP)
glVertex2f(0,0)
glVertex2f(0,1)
glVertex2f(1,1)
glVertex2f(1,0)
glEnd()

I want to export this model as a .OBJ file. How can I do this?

I searched for a while, but could only get resources to open a .OBJ model in OpenGL, not vice-versa.


Solution

  • The Wavefront (.obj) file format is a pretty simple, text based format. It's relatively easy to read/write. For details, read this Page on Wikipedia

    Your example in Wavefront would be

    v 0.0 0.0 0.0
    v 0.0 1.0 0.0
    v 1.0 1.0 0.0
    v 1.0 0.0 0.0
    f 1 2 3 4