OpenGL2 Can't render points with color

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

OpenGL2 Can't render points with color

FieryToken
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.
 
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

FieryToken
Ok so I tried out the 2nd Code example in a normal GLCanvas and it has color. So the problem has to be somewhere in WorldWind. I'm gonna post some OpenGL Code later that WorldWind uses maybe someone knows what's wrong ^^. Gonna try out some stuff myself first.
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

FieryToken
Hmm I couldn't find anything yet and I guess this is quite specific to WorldWind. Sad thing is the WorldWindJava Forum is pretty much dead and I couldn't find any posts related to my problem yet. I guess I have to keep searching for a solution ^^;.
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

gouessej
Administrator
Have you tried to make it work without Worldwind first? Is it what you meant when you wrote about a normal GLCanvas?
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

FieryToken
Yes, that's what I meant. Sorry if that was unclear ^^. Your code works when I am NOT using WorldWind.
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

gouessej
Administrator
In my humble opinion, you should look for the differences between the plain GLCanvas and Worldwind's equivalent even though it's cumbersome. I'm out of options :(
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

FieryToken
I found a solution yesterday. I made my own Layer and only implemented the doRender method from the AbstractLayer it extends. Then I removed the begin- & endStandardlighting calls in my render method(In the WorldWind CustomRenderable tutorial it says that you need this) and it works now :). I finally have color :D. Thank you for your help I really appreciate it.
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

gouessej
Administrator
Please can you post some source code so that it's crystal clear for someone else if this problem occurs again?

I assume that you removed the calls to DrawContext.beginStandardLighting() and DrawContext.endStandardLighting().
Julien Gouesse | Personal blog | Website
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

FieryToken
Yes so as you said i removed these two parts:

        if(!drawContext.isPickingMode()){
            drawContext.beginStandardLighting();          //<---- Evil (`Д´*)
        }

        if(!drawContext.isPickingMode()){
            drawContext.endStandardLighting();          
        }

And then i also made my own Layer like this:

public class PCloud3DTilesLayer extends AbstractLayer {

    PCloud3DTiles pointCloud;

    PCloud3DTilesLayer(PCloud3DTiles pointCloud){
        this.pointCloud = pointCloud;
    }

    protected void doRender(DrawContext drawContext) {
        if(pointCloud != null){
            pointCloud.render(drawContext);
        }
    }
}

My PCloud3DTiles basically looks kind of like this: https://worldwind.arc.nasa.gov/java/tutorials/build-a-custom-renderable/

Event though you dont need to implement the Renderable Interface anymore if you use your own Layer.
And thats pretty much what fixed it for me :)
Reply | Threaded
Open this post in threaded view
|

Re: OpenGL2 Can't render points with color

gouessej
Administrator
Thank you very much, your explanation is valuable and will help other users :)
Julien Gouesse | Personal blog | Website