Draw a specific pixel to screen


#1

I have a 3D scene with possibly a bunch of objects. Using a camera to draw everything. In the draw() function, I’m basically doing this:

cam->begin();
ofEnableDepthTest();
for (allObjects) {
    object.draw();
}
// Draw a specific pixel here, overriding what may be under it
ofDisableDepthTest();
cam->end();

Now I have a couple pixels (pairs of x, y) and colors for those pixels, and I’d like to draw them over everything. I can’t figure out a good way to do it.


#2

hi, you can use an ofImage for that.

ofImage img;
img.allocate(width, height, OF_IMAGE_COLOR);//or OF_IMAGE_GRAYSCALE or OF_IMAGE_COLOR_ALPHA depending on your needs.
img.getPixels().setColor(x, y, ofColor(r,g,b,a));//place your pixels

img.update();

img.draw(...);

hope it helps.
best


#3

Will this get drawn covering the screen (and leaving every pixel alone except the ones I changes) no matter how the camera is placed?

What parameters should I send img.draw();?


#4

Using your method, I have gotten it to work for specific pixels, but the colors are all messed up.

If, for exemple, the ofColor is {r: 61, g: 61, b: 182}, the color is some sort of dark red.
If the color is (0, 0, 255), it gives me black. (0, 255, 0) also gives me black.

Overall, bu playing with the rgb, I can get different colors, but not at all the expected colors from a specific RGB. Are there other factors that can affect the color on that ofImage that might be the cause of those differences between the RGB and the resulting color?


#5

Hi,
if you make the image the size of the screen and then draw it at 0,0 (that is img.draw(0,0); ) it should cover all the screen and be independent of the camera. Although, notice that the img.draw(0,0); should go after camera.end(); inside the draw function.

it should be something like

img.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_COLOR_ALPHA);
img.getPixels().setColor(x, y, ofColor(r,g,b,a));//place your pixels
img.update();
/* if you uncomment this you should have a 200x200 yellow square in the top left. 
for(int y =0; y < 200; y++){
		for(int x =0; x < 200; x++){
			img.getPixels().setColor(x, y, ofColor::yellow);
		}
	}
//*/
ofSetColor(255);// if you dont set the color to white the image will be tinted by whichever color was set before.
img.draw(0,0);

best