PDA

View Full Version : glDrawPixels()/glReadPixels on pbuffer



jungki
07-09-2003, 02:38 AM
Hi there!

I want to store non-clamped floating point value into pbuffer.
When i use drawpixels() and readpixels() like this, However, I just got a clamped floating point value.
FLAG == false, then i got non-clamped values(3.0, 2.333, 0, 5.51)
FLAG == true, then I got clamped values between [0,1].


float *saveImage;

// clear all pixels.
glClearColor(3.0, 2.333, 0, 5.51);
glClear( GL_COLOR_BUFFER_BIT );
#if FLAG
glDrawPixels(200, 200, GL_RGBA, GL_FLOAT, floatImage);
glFlush();
#endif
saveImage = (float*)malloc(sizeof(float)*200*200*4);
glReadPixels(0, 0, 200, 200, GL_RGBA, GL_FLOAT, saveImage);

Relic
07-09-2003, 04:38 AM
Which extension do you use to get float buffers?

jungki
07-10-2003, 10:10 PM
I use NV_float_buffer extension.

And I want to write specific float value into pbuffer.

When I use glDrawPixels() to write into pbuffer, and glReadPixels() to read it.
Then I get clamped value between [0,1].
::NV30 spec says, "DrawPixels generates fragments with the originally specified color value; components are not clamped to [0,1]"

At the same situation, When I use fragment program that write specifed float value into pbuffer and glReadPixels(), then I get right value(not clamped).

Thanks for any help.

[This message has been edited by jungki (edited 07-11-2003).]

roffe
07-10-2003, 11:08 PM
Originally posted by jungki:
When I use glDrawPixels() to write into pbuffer

You do have a fragment program loaded and activated when you make that DrawPixels call right? Floating point buffers require it.

jungki
07-11-2003, 11:19 PM
I load my fragment program and activate it, before use DrawPixels.
But I get only clamped value, when I use DrawPixels.
I don't know why it doesn't work well.

My source code is :

glEnable(GL_FRAGMENT_PROGRAM_NV);
glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, fragProgram); //==>fragProgram set fragment's color (3.0, 3.0, 3.0, 3.0)

glClearColor(3.0, 3.0, 3.0, 3.0);
glClear(GL_COLOR_BUFFER_BIT);

glReadPixels(0, 0, 64, 64, GL_RGBA, GL_FLOAT, saveImage);
for(i=0; i<64*64; i++) {
printf("%f\t%f\t%f\t%f\n", saveImage[4*i], saveImage[4*i+1], saveImage[4*i+2], saveImage[4*i+3]);
//====>This prints 3.0 3.0 3.0 3.0
}

/************************************************** ****************************/
glDrawPixels(64, 64, GL_RGBA, GL_FLOAT, myImage);
// myImage is constant color image(all color is (3.0, 3.0, 3.0, 3.0)

glReadPixels(0, 0, 64, 64, GL_RGBA, GL_FLOAT, saveImage);

for(i=0; i<64*64; i++) {
printf("%f\t%f\t%f\t%f\n", saveImage[4*i], saveImage[4*i+1], saveImage[4*i+2], saveImage[4*i+3]);
//====>This prints 1.0 1.0 1.0 1.0
}

/************************************************** ****************************/
glBegin(GL_QUADS);
glVertex2f(-1.0, -1.0);
glVertex2f(1.0, -1.0);
glVertex2f(1.0, 1.0);
glVertex2f(-1.0, 1.0);
glEnd();
glFlush();

glReadPixels(0, 0, 64, 64, GL_RGBA, GL_FLOAT, saveImage);

for(i=0; i<64*64; i++) {
printf("%f\t%f\t%f\t%f\n", saveImage[4*i], saveImage[4*i+1], saveImage[4*i+2], saveImage[4*i+3]);
//====>This prints 3.0 3.0 3.0 3.0
}
/************************************************** ****************************/
glDisable(GL_FRAGMENT_PROGRAM_NV);

roffe
07-12-2003, 03:41 PM
Originally posted by jungki:
glClearColor(3.0, 3.0, 3.0, 3.0);


If you use a clear color of 3.0 how do you know anything gets written if you say you are drawing with 3.0=rgba.

jungki
07-13-2003, 08:39 PM
But it doesn't matter. Because I want to know why clamping is occured by DrawPixels.
I changed color value with 5.0=rgba except clear color(3.0=rgba), but i got a same result (1.0 = rgba, when i use DrawPixels).

[This message has been edited by jungki (edited 07-13-2003).]