Hello Guest

Some assistance with GL_POINTS?

  • 9 Replies
  • 15432 Views
Some assistance with GL_POINTS?
« on: April 24, 2010, 12:18:06 »
Hi, I'm having some trouble getting GL_POINTS to show up.  I thought I was setting everything up correctly, but nothing seems to happen.

I've created a series of buffers with:
Code: [Select]
vertexBuffer = ByteBuffer.allocateDirect( BYTES_PER_COORDINATE * COORDINATES_PER_VERTEX * VERTICES_PER_RENDER * (_bufferCapacity + BUFFER_CAPACITY_STEP) ).order(ByteOrder.nativeOrder()).asFloatBuffer();
colourBuffer = ByteBuffer.allocateDirect( BYTES_PER_COLOUR * COLOURS_PER_VERTEX * VERTICES_PER_RENDER * (_bufferCapacity + BUFFER_CAPACITY_STEP) ).order(ByteOrder.nativeOrder()).asFloatBuffer();
indexBuffer = ByteBuffer.allocateDirect( BYTES_PER_INDEX * INDICES_PER_VERTEX * VERTICES_PER_RENDER * (_bufferCapacity + BUFFER_CAPACITY_STEP) ).order(ByteOrder.nativeOrder()).asIntBuffer();

Everytime I want to add a point, I use:
Code: [Select]
_indexBuffer.put( _renderCount - 1 );
_vertexBuffer.put( x );
_vertexBuffer.put( y );
_colourBuffer.put(colour.r);
_colourBuffer.put(colour.g);
_colourBuffer.put(colour.b);
_colourBuffer.put(colour.a);

For reference, the vertex and colour array states are always enabled, and some of my other code expects the texture coordinate array to be enabled, that's why I flip it here:
Code: [Select]
public void render( float left, float top ) {
GL11.glVertexPointer(COORDINATES_PER_VERTEX, 0, _vertexBuffer);
GL11.glColorPointer(COLOURS_PER_VERTEX, 0, _colourBuffer );
GL11.glDisableClientState( GL11.GL_TEXTURE_COORD_ARRAY );

if ((left != 0.0f) || (top != 0.0f)) {
GL11.glTranslatef(left, top, 0.0f);
GL11.glDrawElements( GL11.GL_POINTS, _indexBuffer );
GL11.glTranslatef(-left, -top, 0.0f);
} else {
GL11.glDrawElements( GL11.GL_POINTS, _indexBuffer );
}

GL11.glEnableClientState( GL11.GL_TEXTURE_COORD_ARRAY );
}

But nothing ever shows up on the display.  Now, I tried playing with the index value I was putting in _indexBuffer, and giving it bogus values did crash the app, so it does appear to be processing the data, I just never see anything on the display.

Is there anything obvious I'm doing wrong?  I'm using a very similar system to draw some textured triangles and that works just fine and this is based off of that code.

Re: Some assistance with GL_POINTS?
« Reply #1 on: April 24, 2010, 12:19:36 »
Also, I've ensured that I'm setting each vertex as opaque white, so it's not just that they're transparent.  :)
« Last Edit: April 25, 2010, 00:46:27 by Kiyote »

Re: Some assistance with GL_POINTS?
« Reply #2 on: April 24, 2010, 14:07:30 »
Everytime I want to add a point, I use:
Code: [Select]
_indexBuffer.put( _renderCount - 1 );
_vertexBuffer.put( x );
_vertexBuffer.put( y );
_colourBuffer.put(colour.r);
_colourBuffer.put(colour.g);
_colourBuffer.put(colour.b);
_colourBuffer.put(colour.a);


you must flip() your buffers after put() ends, or rewind() at least. ;)

Re: Some assistance with GL_POINTS?
« Reply #3 on: April 24, 2010, 14:19:06 »
Fair enough, I was trying not to overwhelm with code snippets.

Code: [Select]
public void begin() {
clear();
}

private void doAdd(float x, float y, Colour colour) {
_renderCount += 1;
if (_renderCount > _bufferCapacity) {
expandBuffers();
}

_indexBuffer.put( _renderCount - 1 );
_vertexBuffer.put( x );
_vertexBuffer.put( y );
_colourBuffer.put(colour.r);
_colourBuffer.put(colour.g);
_colourBuffer.put(colour.b);
_colourBuffer.put(colour.a);
}

public void end() {
_vertexBuffer.rewind();
_indexBuffer.rewind();
_colourBuffer.rewind();
}

That's actually the sequence I use.  So, I do a .begin(), repeated calls to .addVertex() (which is calling in to .doAdd()) and then call .end().

I present it with the .render() method shown earlier.

Re: Some assistance with GL_POINTS?
« Reply #4 on: April 25, 2010, 00:48:06 »
So, I've tried dropping the colour array, I've tried enabling the texture array, I've tried drawing just one point, I've filled the index buffer with 0 instead of the actual indices I want.

It's got to be something very stupid I'm missing, but I don't have a great deal of experience with OpenGL, so I'm hoping someone can help me.

Re: Some assistance with GL_POINTS?
« Reply #5 on: April 25, 2010, 18:26:29 »
Whats your transform? Perhaps you are just "looking" the wrong way. What your blend mode etc... Perhaps use triangles and see if they show up? Are you sure the alpha is non zero (not completely transparent pixels) or that change the  blend mode to effectively overwrite. Also consider Z clipping with the near/far planes.
If you want a plot read a book and leave Hollywood out of it.

Re: Some assistance with GL_POINTS?
« Reply #6 on: April 25, 2010, 21:11:29 »
So, I've tried dropping the colour array, I've tried enabling the texture array, I've tried drawing just one point, I've filled the index buffer with 0 instead of the actual indices I want.
fill'em with 1 because 0 is black color. I thought I got my whole texture rendering lost some time ago, since I realized that I was blending the texture with black color !! LOL

Re: Some assistance with GL_POINTS?
« Reply #7 on: April 25, 2010, 22:18:42 »
Sorry, the index buffer is the one that determines the colour of the points?

Re: Some assistance with GL_POINTS?
« Reply #8 on: April 26, 2010, 00:49:50 »
Oh, sorry you talk about texture blend.
rereading your sample of codes, the argument you pass to drawElements is looking into the GL currentcolor values : To enable and disable the color array, call glEnableClientState and glDisableClientState with the argument GL_COLOR_ARRAY. If enabled, the color array is used (opengl sdk doc)
then Glcolor() is more appropriate.



Re: Some assistance with GL_POINTS?
« Reply #9 on: April 26, 2010, 12:38:27 »
Have you tried to disable texturing, not just disable texture arrays? I forgot to disable it once and turned out the last texture coordinate/texture that was still enabled was to a transparent texture pixel.

Also, it doesn't look like you're doing this, but I'll put it up just in case. Make sure you disable GL_POINT_SMOOTH if you are using textures on points. That also makes points not show up (and slows it down a lot too).
Programmers will, one day, rule the world... and the world won't notice until its too late.Just testing the marquee option ;D