Hello Guest

Expert answer needed about glDrawPixels...

  • 5 Replies
  • 10804 Views
Expert answer needed about glDrawPixels...
« on: February 03, 2005, 12:55:43 »
I am dynamically animating a texture, and blitting it to screen using glDrawPixels.

To keep my framerate up, while covering the whole screen, I use the glPixelZoom, which will scale up each pixel to any amount of physical on screen pixels I want.

This works perfectly, however, it would be so much nicer if the glPixelZoom would interpolate the color values using bilinear interpolation or similar, to avoid that pixelated look.

Is it possible, and in that case, how?

Thanks in advance! :)

*

Offline spasi

  • *****
  • 2172
    • WebHotelier
Expert answer needed about glDrawPixels...
« Reply #1 on: February 03, 2005, 13:12:18 »
Instead of using DrawPixels, use a texture instead. After creating the texture (use a null buffer), call glTexSubImage2D each frame to update its data and simply draw a quad at the size you want. Using GL_LINEAR will give you free interpolation.

For more speed, check out ARB/EXT_pixel_buffer_object for asynchronous texture uploads.

Expert answer needed about glDrawPixels...
« Reply #2 on: February 03, 2005, 13:14:41 »
The pixel ops of OpenGL all suck horribly for any proper useage. They end up being slow and unweildy, with not nearly as much flexibility.

Stick your image in a texture. Then stick that on a quad. You''ll end up with much more flexibility (and the filtering you're after).

aha..
« Reply #3 on: February 03, 2005, 13:30:45 »
ok, glad to hear it is another way of doing this...

But, oops, I forgot to mention I am a newbie at opengl, so if you can provide me with a small sample code I would appreciate it.  :oops:

I am using LWJGL by the way, and my code today is quite simple, like this:

Code: [Select]

        GL11.glRasterPos2i(0, 0);
        GL11.glDrawPixels(width, height,GL11.GL_RGBA, GL11.GL_UNSIGNED_BYTE,pixelsBuf);
        GL11.glPixelZoom(resolution, -resolution);


with the pixelbuffer being initialized like this:

Code: [Select]

        this.width=Global.DISPLAY_W/resolution;
        this.height=Global.DISPLAY_H/resolution;
        pixelsBuf=ByteBuffer.allocateDirect(width*height*4).order(ByteOrder.nativeOrder());
        pixels=new byte[width*height*4];


And updated like this:

Code: [Select]

        pixelsBuf.put(pixels).flip();


These snippets allow me to freely draw into the pixels array, which is what I want...

How would this look when using the method you suggest, in LWJGL?

Thanks again...

Expert answer needed about glDrawPixels...
« Reply #4 on: February 03, 2005, 14:25:04 »
The Space Invaders demo/example that comes with lwjgl should show simple textured quads, that should cover the basics. Also, grab yourself a copy of the OpenGL Red book:

http://www.gamedev.net/download/redbook.pdf

Expert answer needed about glDrawPixels...
« Reply #5 on: February 03, 2005, 15:22:05 »
Quote from: "Orangy Tang"
The Space Invaders demo/example that comes with lwjgl should show simple textured quads, that should cover the basics. Also, grab yourself a copy of the OpenGL Red book:

http://www.gamedev.net/download/redbook.pdf


Thanks, I figured it out now, looks much nicer and probably is faster too ... :)