Some assistance with GL_POINTS?

Started by Kiyote, April 24, 2010, 12:18:06

Previous topic - Next topic

Kiyote

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:
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:
_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:
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.

Kiyote

Also, I've ensured that I'm setting each vertex as opaque white, so it's not just that they're transparent.  :)

broumbroum

Quote from: Kiyote on April 24, 2010, 12:18:06
Everytime I want to add a point, I use:
_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. ;)

Kiyote

Fair enough, I was trying not to overwhelm with code snippets.

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.

Kiyote

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.

delt0r

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.

broumbroum

Quote from: Kiyote 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.
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

Kiyote

Sorry, the index buffer is the one that determines the colour of the points?

broumbroum

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.



Fool Running

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