LWJGL Forum

Programming => OpenGL => Topic started by: BlackBrick89 on September 10, 2016, 20:25:44

Title: [solved] Migration from immediate mode to VBO.
Post by: BlackBrick89 on September 10, 2016, 20:25:44
Hi guys,

I started to develop a very complex CAD program with LWJGL (and SWT) for the LDraw (http://ldraw.org/) community a few years ago.
The program has now over 100.000 lines of code and is called LDPartEditor (https://sourceforge.net/projects/partcreator/?source=directory).
I decided to use the old legacy API since the common user wont have a highend machine like I do.

Now, I want to implement a second render path with OpenGL 3.
I do not need realtime graphics and therefore I am not interested in aggressive micro optimization.


edit: Sorry! I was able to do the migration by myself.


The program is able to manipulate primitives (triangles, quads, lines, vertices) and submodels (groups of primitives).
There is also a manipulator tool similar to the tool which Blender uses.
It has build-in CSG features and it supports object picking.
Additionally, there is a text editor to edit the sourcecode of the 3D model and you will see the result immediately in the 3D editor (and vice versa).

Currently, I have objects which are able to draw themselves, e.g. a triangle class which has a draw method.


    @Override
    public void drawGL20(Composite3D c3d) {
        if (!visible)
            return;
        if (a < 1f && c3d.isDrawingSolidMaterials() || !c3d.isDrawingSolidMaterials() && a == 1f)
            return;
        if (!isTriangle) {
            // This triangle can be a protractor, too.
            drawProtractor(c3d, X1, Y1, Z1, X2, Y2, Z2, X3, Y3, Z3);
            return;
        }
        GL11.glBegin(GL11.GL_TRIANGLES);
        if (GData.globalNegativeDeterminant) {
            GL11.glColor4f(r, g, b, a);
            GL11.glNormal3f(xn, yn, zn);
            GL11.glVertex3f(x1, y1, z1);
            GL11.glVertex3f(x3, y3, z3);
            GL11.glVertex3f(x2, y2, z2);
            GL11.glNormal3f(-xn, -yn, -zn);
            GL11.glVertex3f(x1, y1, z1);
            GL11.glVertex3f(x2, y2, z2);
            GL11.glVertex3f(x3, y3, z3);
        } else {
            GL11.glColor4f(r, g, b, a);
            GL11.glNormal3f(xn, yn, zn);
            GL11.glVertex3f(x1, y1, z1);
            GL11.glVertex3f(x2, y2, z2);
            GL11.glVertex3f(x3, y3, z3);
            GL11.glNormal3f(-xn, -yn, -zn);
            GL11.glVertex3f(x1, y1, z1);
            GL11.glVertex3f(x3, y3, z3);
            GL11.glVertex3f(x2, y2, z2);
        }
        GL11.glEnd();
    }

To get the output, the renderer iterates all objects like a linked list and you'll see the model on the screen.
This approach is simple and very close to the LDraw File Format (http://ldraw.org/article/218.html) standard (its 100% compliant).

The current implementation of the render engine is modular.
I don't want to delete the old immediate mode render engine and I am able to write a new render class from scratch by just implementing the following methods:


    @Override
    public void init() {
        // Init goes here...
    }

    @Override
    public void drawScene() {
       
        // Render loop

        final GLCanvas canvas = c3d.getCanvas();
       
        if (!canvas.isCurrent()) {
            canvas.setCurrent();
            GL.setCapabilities(c3d.getCapabilities());
            // These capabilities are forward compatible!
        }
       
        // FIXME Render the 3D model, grid, GUI elements, etc. ...
       
       
        canvas.swapBuffers();
               
    }
   
    @Override
    public void dispose() {
        // TODO Dispose resources here...
    }



I can access the following data:

There are surfaces which have no textures, one texture or more than one texture.
A model can have many textures.
There are transparent and opaque surfaces, too.

At the moment, I don't know what to do... :(

How should I start the migration?
Should I design a shader first?
Should I focus on the creation of the VBOs?
How do I group the VBOs?
How can I expand my horizons to learn something about VBOs with very dynamic data?

Leg godt

Nils


A screenshot from an earlier version with texture mapping:
(https://lh3.googleusercontent.com/7vGEstiPMXQ-oUyzH2fouCHQSqmGuJKLkSdA_EOgaFg2BfSwAXz9IbGa1U_yZGuJytGzKhJPPg=w1920-h1080-no)

Impressions from the latest stable release (https://lh3.googleusercontent.com/Zt4Bk2TlG8aglbVpRnUZ9rVxD65GpUmrZaa--XJA-UuUtN85u5FCfuxCfENEeueVWpIr5_FOxA=w1920-h1080-no)

Thanks guys, for creating LWJGL!  ;)