Render to buffer

Started by
9 comments, last by zxwyeah 18 years, 4 months ago
Hi. I would like to set and get the buffer OpenGL uses to render the images. I will explain beter: 1) Create a buffer: an array of integers (ARGB) 2) Set this array as the render target 3) Render the scene 4) Read back the scene on the array This is possible?
Advertisement
Are you trying read pixels off the screen? Or are you trying to create a pixel buffer? Yes, it is possible, but do you perfer to do it a special way? You can simply make an array and then use glReadPixels() to record screen data.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
I would like to use an array of integers as the render target of my OpenGL renderings.

I create the buffer with new int[width*height], for example, set as the render target, render the scene, and read back the result on the array.

This way, if I want to know tha value of the pixel at, say, (x = 10, y = 20), I could use the array like this:

int thePixel = array[width*20 + 10];



You realease you can't use an integer, you'd have to use 3 char values for the RGB. You create the array of char values and then use glReadPixels() to take the current screen data and fill up the array. Also, are you trying to render to a texture?

EDIT: I don't know too much about render targets with OpenGL, so I'm doing some Googling.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
But if I want to get the alfa channel, and this
way using integers as ARGB?
Ah, I'll take a look. I'm going to grab my OpenGL book quickly! ;)
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Ok, I'm reading here... If your making a render target, you obviousely don't want to display the scene, just render it to the frame buffer I believe. I'm trying to find out how to acess it...

Sorry buddy, I don't think I can help you on this.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
I would like to read the pixels on the screen to a buffer.
I my example, I could read the color components like this:

After reading the contents of the screen:

int thePixel = array[width*20 + 10];
byte alpha = thePixel & 0xFF000000 ;
byte red = thePixel & 0x00FF0000 ;
byte green = thePixel & 0x0000FF00 ;
byte blue = thePixel & 0x000000FF ;

It's possible to work like this?
Oh, so you are rendering them to the screen! Yes I can help then. You would create your pointer and then call glReadPixels(0,0,width,height,GL_RGBA,GL_INT,array); Then you should be able to mess around with the pixels like you are. Sorry for the giant confusion.
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
Thank you very much for the tips!

This topic is closed to new replies.

Advertisement