Get color RGB of pixel

Feb 20, 2012 at 10:29 AM

Hi everyone,

I have a question, is it possibile to get RGB color for every single pixel in sceneView with coordinates?

I want to write into buffer video my OpenGL scene,

thanks
vsibilla

Coordinator
Feb 20, 2012 at 11:09 AM

Shouldn't be a problem - can you tell me:

  • What version of SharpGL you are using
  • Is it indeed a SceneView (i.e. the new WPF control from the latest cut of the code [or a late cut of the code!])
  • What RenderContextProvider type you are using?
Feb 20, 2012 at 12:25 PM

- SharpGL version is 2.0 (the last one)

- I'm using WinForm and SceneControl component

- now I'm not using RenderContextProvider, what do you recommend?

 

thanks
vsibilla

Coordinator
Feb 20, 2012 at 1:31 PM

Why not use the gl function readpixels:

http://msdn.microsoft.com/en-us/library/ms537248

int x = 12;
int y = 12;
int width= 1;
int heigth = 1;
uint format = OpenGL.GL_RGBA;
uint type = GL_BYTE;

//  Space for width by height by 4 bytes - i.e. one byte for each of RGBA.
byte[] pixelData = new byte[width * height * 4];
gl.ReadPixels(x, y, width, height, format, type, pixelData);

//  The result.
byte red = pixelData[0];
byte green = pixelData[1];
byte blue = pixelData[2];
byte alpha = pixelData[3];
This'll get you the pixels rendered by OpenGL - regardless of what the underling render context provider is (i.e. it'll work for DIB Sections, Framebuffers etc)