Main Menu

drawing pixels

Started by ZoowieZ, January 02, 2004, 19:21:47

Previous topic - Next topic

ZoowieZ

What's the best (fastest) way to draw pixels on the screen with OpenGL.  I tried using the glDrawPixels function but it was extremely slow.  Is there any way to use textures to do it?

Here's what I did:

I initialized a byte buffer like this to use it as a buffer of ints
private static void init() throws Exception {

buffer = ByteBuffer.allocateDirect(1920000*8);
     	buffer.order(ByteOrder.nativeOrder());

     	for(int i = 0; i < 1920000*4; i += 4)
	{
		buffer.put(i,(byte)0x00);    // red component
		buffer.put(i+1,(byte)0x00);  // green component
		buffer.put(i+2,(byte)0x00);  // blue component
		buffer.put(i+3,(byte)0x00);  // alpha component
	}

Then I wrote whatever data into the buffer with the same put() method to add pixels wherever I wanted.

Lastly I called glDrawPixels in the game loop like this.
private static void render()
     {

       GL.glClear(GL.GL_COLOR_BUFFER_BIT);
	   mesh.draw(); // this just adds stuff into the buffer
       GL.glDrawPixels(1600,1200,GL.GL_RGBA, GL.GL_UNSIGNED_INT_8_8_8_8_REV, buffer.asIntBuffer());
     }


This didn't work to well when I tried to animate things.  It's really slow.  There must be a better way.  Please help me out.

Anonymous

java.nio.*Buffer.put(...) on direct buffers is quite slow. It's actually much faster to use a normal array to change values, and put() that array to the Buffer

Anonymous

Oh well, even writing 1600x1200 static pixels to the screen won't get you over 10fps

Chman

Why would you want to do a such thing ???

Anyway, you could look into fragment shaders... Don't think it would exactly do what you would like to but...

OpenGL has not been designed to plot pixels on screen so...

Chman

princec

You should use a textured quad, not glDrawPixels. Or, you can allocate the buffer used by drawpixels in video or AGP RAM using various proprietry extensions.

Cas :)