Pixel Alteration Question

Started by
7 comments, last by Kalidor 16 years, 7 months ago
Hello, I have been scouring the internet for an answer to this question for quite a while, but I have been unsuccessful as of now. I am attempted, with Visual C++ 6.0, to be able to edit individual pixels in a timely manner of an opengl window, or even a standard window. However, the only functions I can find that will do that are SetPixel/SetPixelV and glDrawPixels. The problem is that both are extremely slow. SetPixel is slow since I do not believe that it runs off of the graphics card. glDrawPixels is even slower, because, as I have read, it runs through the entire graphics pipeline before being placed instead of simply directly editing the pixel on screen. Obviously, drawing a pixel on screen is extremely fast, since clearing the entire screen is next to instantaneous. I couldn't find the OpenGL source code, so I have no idea how to draw a single pixel as fast as possible. Does anyone know how to do this? My apologies if this is unclear. Thank you.
Advertisement
You may do it in the old fashion way. That is, updating rectangle on demand by using InvalidateRect(). However, it is really a step backward.

Besides, if you are using OpenGL correctly, glDrawPixels() should be still in an acceptable range for manual editing purpose. Have you double check your source code for pitfall?
Thanks for the quick answer. However, as I am dealing with many many pixel alterations (800x600 in fact), calling glDrawPixels that many times is slow, as is SetPixel. However, even using glDrawPixels once with an 800 height and 600 width is just as slow. I require the method with which glClearBuffer writes to the framebuffer so quickly. Thanks.
I you really need to modify each pixel, you should do that to a buffer, upload it as a texture and draw a quad covering the entire screen.
I tried that, but unfortunately that slowed things down about as much, given the fact that I was using a texture of that resolution(800x600). Thanks though.

Is OpenGL open source, and if so, where can I find it?
1) Why do you need to draw individual pixels? Any hardware accelerated graphics API is going to be completely usless at drawing pixels.
2) Don't use VC6. Seriously. It's a decade old (That's from the last millenium), is NOT a C++ compiler, jsut a C compiler with classes, it generates substandard code, and in some cases it can actually generate broken code. VC2005 Express is free and can do everything VC6 can do, with a few minor exceptions, and is a far more standards compliant compiler.
Quote:Original post by rrr_r
I tried that, but unfortunately that slowed things down about as much, given the fact that I was using a texture of that resolution(800x600). Thanks though.

Is OpenGL open source, and if so, where can I find it?


It is a specification. The specification is Open.
http://www.opengl.org/documentation/specs/

There is the mesa project www.mesa3d.org which is a software implementation. I don't think it's useful for you.

You need to find out why rendering a quad is slow. Is it your code or GL. Most likely your code or you are misusing GL.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Alright, after a little experimentation, I have found that it is not the rendering of a quad that is slow, it is in fact the building of a texture (glTexImage2D) that is 800x600 that is slowing things down so much, since I am having to call it every frame. This is a problem which I doubt I will be able to get around.

I am thinking of finding a 2d software renderer, but unfortunately I can't find any. Mesa3d doesn't seem to have any documentations either. Does anyone know of any 2d software renderers that can do pixel manipulations at a fast speed?
Quote:Original post by rrr_r
Alright, after a little experimentation, I have found that it is not the rendering of a quad that is slow, it is in fact the building of a texture (glTexImage2D) that is 800x600 that is slowing things down so much, since I am having to call it every frame. This is a problem which I doubt I will be able to get around.
glTexImage2D recreates the entire texture. If you just want to update new texel data to an already created texture, use glTexSubImage2D instead.
Quote:Original post by rrr_r
I am thinking of finding a 2d software renderer, but unfortunately I can't find any. Mesa3d doesn't seem to have any documentations either. Does anyone know of any 2d software renderers that can do pixel manipulations at a fast speed?
OpenGL is not designed for manipulating pixels. If that's what you want to do, I've heard PixelToaster is pretty good, although I've never personally used it.

This topic is closed to new replies.

Advertisement