• Advertisement
Sign in to follow this  

Manipulating a specific pixel

This topic is 3984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi guys! Let's say we have 1024x768 (or whatever) textured screen quad. How can I change a specific pixel of the texture? Or are there any real time post proceesing trick to change a specific pixel of the rendered scene? Thanks in advance :)

Share this post


Link to post
Share on other sites
Advertisement
It depends on what you want to do because there is dozens of methods to manipulate either individual pixels or all of them in both the frame buffer or in a texture.

Share this post


Link to post
Share on other sites
overlord, I want to implement some post processing operations,but I should be able to change correct pixels.well, i.e. changing the pixel on the (x=120,y=320) point of the screen. I hope it clarifies.

Share this post


Link to post
Share on other sites
What kind of post-processing do you want to do?

GL has functions to simply read and write a pixel values, but they're slow because of the transfer from gfx to system RAM, and therefore aren't exactly used very much in games...

A hardware accelerated post-processing system will usually do something along the lines of:
1)render the scene
2)copy the frame-buffer to a texture
3)bind a pixel shader containing your post-process algorithm
4)set an appropriate blending mode
5)render a full-screen quad using that texture
6)unbind PS and reset blending mode

Share this post


Link to post
Share on other sites
And in a lot of cases you don't even need to use pixel shaders, regular blending works really fine for things like blurring and so on.

One thing you should really take a look at is FBO, since it allows you to render directly to a texture and then use that texture for post processing directly to the framebuffer.
I have written a short tutorial on the subject of FBOs on my site, just go to flashbang.se(see link below) and look up the line FBO on the right.

Share this post


Link to post
Share on other sites
Also, if you dont want to get into FBO's and want to stick to "older methods" then take a look at glReadPixels and glDrawPixels. These two functions get and draw an array of pixels to the frame buffer. You need to note that these functions are awfully slow but with them you can easily get your array of pixels, loop through them and change what pixels need to be modified. Then, you just take the array you modified and redraw it. Hope that helps as an alternative.

Jon

Share this post


Link to post
Share on other sites
Thanks for the great replies guys.But I want to do that in real time. I've looked at it and I think I should use FBO. How can I change a pixel of the screen quad's texture by using FBO? Do you know where I can find an example code? ( no post processing just changing the texture pixels.) Is it logical to do it for a 1024x768+ quad in real time? Thanks again :)

Share this post


Link to post
Share on other sites
If you care to answer: why do you WANT to change a single pixel?
At a resolution of 1024x768 you have 786,432 pixels. Do you think changing a single pixel will make a significant addition to the graphical quality of your scene?

Share this post


Link to post
Share on other sites
Quote:
Original post by Kalasjniekof
If you care to answer: why do you WANT to change a single pixel?
At a resolution of 1024x768 you have 786,432 pixels. Do you think changing a single pixel will make a significant addition to the graphical quality of your scene?


My guess is he wants to do more than edit a single pixel. But in order to do that you need to know how to edit one.

Share this post


Link to post
Share on other sites
Well, I don't why it is sooooo important for you, but I will make a pattern recognition program(neural nets). I need to know how to change a pixel.

Share this post


Link to post
Share on other sites
hmm neural nets you say, ok, to change a single pixel, if you only need to owerwrite the pixel without knowing whats under it you can use one of two pretty fast methods

1. use glTexSubImage2D(GL_TEXTURE_2D, textureid,0,x,y,1,1,GL_RGB,GL_UNSIGNED_BYTE,pixeldata); to change a single pixel(or many if you want).
2. if bound as a FBO you can just draw a pixel with glVertex3f while it is bound as a render buffer if you have the correct glOrtho mode set up.

If you need readback then it becomes a bit more difficult and definitely slower.
First you could just read the entire texture using glGetTexImage, but if you use that you might just as well store the whole thing on the cpu.
the other method requires you to use a combination of FBO and glReadPixels.

But the by far fastest and most flexible is the use of GPGPU shader programs to do all the processing, i am pretty sure that some of that pattern recognition stuff can be done on the gpu at blazing speeds, you could make a program that reads from one texture, compares it with another and then outputs the result to a third one

Share this post


Link to post
Share on other sites
Quote:
Original post by baykalsa
Well, I don't why it is sooooo important for you, but I will make a pattern recognition program(neural nets). I need to know how to change a pixel.

It's sooooo important for me because having a context for your problem can help us a lot in finding a solution for you, or for providing alternate approaches as I will do.

I take it that you will use this pixel changing to draw connections between the nodes? This is a wild guess as you still did not provide a lot of information.

Anyway, if the above scenario is correct a better option would be to use glLines to draw them (obviously).

Another guess would be that you want to use the technique to render some sort of 'action-potential' effect. In that case your initial approach (ps) should be the best option.

As you can see from the above, more information is absolutely a good thing if you want us to help you. Reread your first post. It doesn't give us much of a context, does it?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement