Hello Guest

drawing pixels

  • 4 Replies
  • 6580 Views
drawing pixels
« on: January 02, 2004, 19:21:47 »
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
Code: [Select]

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.
Code: [Select]

 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

drawing pixels
« Reply #1 on: January 22, 2005, 22:07:47 »
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

drawing pixels
« Reply #2 on: January 22, 2005, 22:17:21 »
Oh well, even writing 1600x1200 static pixels to the screen won't get you over 10fps

*

Offline Chman

  • ***
  • 100
    • http://www.shakebox.org
drawing pixels
« Reply #3 on: January 23, 2005, 01:04:34 »
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

*

Offline princec

  • *****
  • 1898
    • Puppygames
drawing pixels
« Reply #4 on: January 23, 2005, 12:19:12 »
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 :)