russell's picture

Moving screen picture

I'm novice in OpenGL. And I try to move screen picture to the left by some pixels. I don't want to redraw full screen and move camera. How can I do it? Can I use ReadPixels and DrawPixels functions? Can anybody show me some examples?


Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

Redrawing the whole scene will be faster than any pixel operation (*significantly* faster in most cases). The correct approach would be to use a framebuffer object but that's even more complex than redrawing the whole scene.

In any case, you might be able to achieve a screen-to-screen copy using RasterPos (to set the offset) and CopyPixels. Frankly, I have no idea whether this is hardware accelerated in modern GPUs and whether this can be used on double-buffered contexts. The code would look something like this:

GL.Finish(); // Ensure rendering is complete
 
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(0, Width, Height, 0, -1, 1);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
 
GL.RasterPos(-5, 0);
GL.CopyPixels(rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, PixelCopyType.Color);

Note that RasterPos is affected by your current modelview and projection matrix, so make sure both are setup correctly. Moreover, rectangle should not be larger than your current viewport.

Anyway, I'd strongly suggest moving the camera and redrawing the whole scene but give this a try if you feel it's worth it.

zahirtezcan's picture

The fastest way i know of is including framebuffer with BlitFramebuffer function. But, as Fiddler said it's rather complicated. Just to point out, moving picture some pixels is not same with moving the camera if you are using perspective projection.