Login  Register

OpenGL2 Can't render points with color

Posted by FieryToken on Jan 26, 2021; 9:57am
URL: https://forum.jogamp.org/OpenGL2-Can-t-render-points-with-color-tp4040994.html

Soo I asked this question already on stackoverflow but gouessej suggested I post this here as well.

I'm currently using OpenGL2 for one of my projects and I want to render a PointCloud. I can also already display the points at the correct positions but I have a problem with the colors. Since I am using WorldWind I cant use shaders to solve the problem and it's hard to post a simple example that you can just copy and paste to see what my code does.

I can post my render method and the different attempts I tried.

Code 1

public void draw(DrawContext drawContext){

        gl.glEnable(GL2.GL_DEPTH_BUFFER_BIT);

        int stride = 0;

        gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);

        gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

        gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, VBO.get(0));

        gl.glVertexPointer(3, GL2.GL_FLOAT, stride, 0);

        gl.glColorPointer(3, GL2.GL_FLOAT, stride,vertBuf.limit()*4);

        gl.glPointSize(4);

        gl.glDrawArrays(GL_POINTS, 0, vertBuf.limit()/3);

        gl.glPointSize(1);

        gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);

        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);

        gl.glDisableClientState(GL2.GL_COLOR_ARRAY);

        gl.glDisable(GL2.GL_DEPTH_BUFFER_BIT);

    }

    // How the data is put into the VBO

    gl.glBufferData(GL_ARRAY_BUFFER,(vertBuf.limit()*4)+(colorBuffer.limit()*4),null, GL_STATIC_DRAW)
    gl.glBufferSubData(GL_ARRAY_BUFFER, 0, vertBuf.limit()*4, vertBuf);
    gl.glBufferSubData(GL_ARRAY_BUFFER, vertBuf.limit()*4, colorBuffer.limit()*4, colorBuffer);

Code 2

My next attempt was that I tried to render using InterleavedArrays as gouessej said I should try it out.

public void draw(DrawContext drawContext){

        gl.glEnable(GL2.GL_DEPTH_BUFFER_BIT);

        int stride = 0;

        gl.glEnableClientState(GL2.GL_VERTEX_ARRAY);

        gl.glEnableClientState(GL2.GL_COLOR_ARRAY);

        gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, VBO.get(0));

        gl.glInterleavedArrays(gl.GL_C3F_V3F,0,0);

        InterleavedBuf.rewind();

        gl.glPointSize(4);

        gl.glDrawArrays(GL_POINTS, 0, InterleavedBuf.limit()/6);

        InterleavedBuf.rewind();

        gl.glPointSize(1);

        gl.glBindBuffer(GL2.GL_ARRAY_BUFFER, 0);

        gl.glDisableClientState(GL2.GL_VERTEX_ARRAY);

        gl.glDisableClientState(GL2.GL_COLOR_ARRAY);

        gl.glDisable(GL2.GL_DEPTH_BUFFER_BIT);

    }
       //interleaveArrays Method just interleaves the color and vertex arrays.
       // It looks like this as example : 0.8f , 0.0f, 0.7f, <- colorValues
       //                                            0.75f, 0.3f, 0.4f <- vertexPositions
       // and so on...
       InterleavedBuf = Buffers.newDirectFloatBuffer(interleaveArrays(normalizeColors(colorValues),vertex_positions));

        InterleavedBuf.position(0);

        gl.glBufferData(GL2.GL_ARRAY_BUFFER, InterleavedBuf.limit()*Float.BYTES, InterleavedBuf,GL_STATIC_DRAW);

        InterleavedBuf.position(0);



Both of these attempts yield the same result. I can see the points at the correct position but they are just grey. And yes I also checked my color values and they are not grey :D.
I will try to render my PointCloud with color in a normal GLWindow and not in WorldWind to see if WorldWind may be causing problems later.