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! :)
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.
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).
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:
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:
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:
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...
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
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 ... :)