Want to rewrite the pixel buffer
#1 Members - Reputation: 104
Posted 21 July 2012 - 08:08 PM
I am trying to do some post rendering effect like a color shift to red when the character dies, or maybe a shift to black to make it darker. Here's the piece of code I have cooked up:
----
float normalColor[3] = { float(colorToShift.Get().r.Get()) / 0xFF,
float(colorToShift.Get().g.Get()) / 0xFF,
float(colorToShift.Get().b.Get()) / 0xFF };
GLfloat *data = ((GLfloat *)malloc(3 * screenWidth.Get() * screenHeight.Get() * sizeof(GLfloat)));
if( data )
{
glReadPixels(0, 0, screenWidth.Get(), screenHeight.Get(), GL_RGB, GL_FLOAT, data);
}
else
{
return;
}
for( int i = 0; i < screenWidth.Get() * screenHeight.Get() * 3; i += 3 )
{
GLfloat *dataR = data + i + 0;
GLfloat *dataG = data + i + 1;
GLfloat *dataB = data + i + 2;
*dataR = min( 1.0, max( 0.0, *dataR + ( normalColor[0] - *dataR ) * degree.Get()));
*dataG = min( 1.0, max( 0.0, *dataG + ( normalColor[1] - *dataG ) * degree.Get()));
*dataB = min( 1.0, max( 0.0, *dataB + ( normalColor[2] - *dataB ) * degree.Get()));
}
glDrawPixels(screenWidth.Get(), screenHeight.Get(), GL_RGB, GL_FLOAT, data);
------
The program has read the pixel fine with glReadPixel, the pixel processing is working, but glDrawPixel is not doing anything. I basically want to rewrite the pixels I see on the screen.
What am I doing wrong??
thanks
#2 Members - Reputation: 537
Posted 21 July 2012 - 11:19 PM
Are you just fading to red? Draw a red quad and change the alpha. You can always use a texture with varying red/blood instead of just using pure red.
You have to call glRasterPos and glLoadIdentity to DrawPixels
Edited by dpadam450, 21 July 2012 - 11:20 PM.
#3 Members - Reputation: 3829
Posted 22 July 2012 - 06:47 AM
It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.
#4 Members - Reputation: 104
Posted 22 July 2012 - 09:04 AM
So glRead and glDraw too slow? Better use some quads with alpha to make the special effects? Is this possible any other way?
Thanks
#6 Members - Reputation: 537
Posted 22 July 2012 - 10:31 AM
fade out to black would be
glColor4f(0,0,0,alphaFade);
Where alphaFade = 0 and goes to 1. You just draw a fullscreen quad and its fast.
Motion blur is done with shaders. To do the dizzy effect you copy the screen to texture and use that along with a "distortion" texture. In a shader you wiggle the distortion texture around by manipulating UV coords. You use that texture as offsets from the current pixel.
#8 Members - Reputation: 3829
Posted 22 July 2012 - 07:38 PM
It's fast but it won't be as fast as not doing it at all. If nothing else, the operation requires touching every pixel in your scene twice - once for the regular draw, once for the effect. But it will still be colossally faster than reading back and doing it on the CPU, which is quite possibly the worst thing you could do for this kind of effect.
It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.







