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.