Jump to content

  • Log In with Google      Sign In   
  • Create Account

Want to rewrite the pixel buffer


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 KrimsomKing   Members   -  Reputation: 104

Like
0Likes
Like

Posted 21 July 2012 - 08:08 PM

Hello there,

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

Sponsor:

#2 dpadam450   Members   -  Reputation: 949

Like
1Likes
Like

Posted 21 July 2012 - 11:19 PM

Dont do that. glRead and glDraw are slow.

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 mhagain   Crossbones+   -  Reputation: 8285

Like
0Likes
Like

Posted 22 July 2012 - 06:47 AM

OpenGL will also quite happily apply texturing and lighting to glDrawPixels. And aside from their overall slowness (please don't anybody mention how bandwidth is good nowadays, that's not relevant, pipeline stalls will be the biggest issue there and no amount of bandwidth will eliminate a pipeline stall) you're neither reading from nor drawing to the framebuffer in it's native format, meaning that you're forcing OpenGL to go through extra software stages to convert to and from 3-component RGB floats.

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 KrimsomKing   Members   -  Reputation: 104

Like
0Likes
Like

Posted 22 July 2012 - 09:04 AM

My original intent was to make a class to make some cool post-render effects. After everything is drawn, apply some modifiers to the pixels on the buffer. Like some fade out to black between screen transition... Or maybe some blur effects applied on the render directly when the character is dizzy.

So glRead and glDraw too slow? Better use some quads with alpha to make the special effects? Is this possible any other way?

Thanks

#5 MrDaaark   Members   -  Reputation: 3555

Like
1Likes
Like

Posted 22 July 2012 - 09:16 AM

Use a shader.

#6 dpadam450   Members   -  Reputation: 949

Like
0Likes
Like

Posted 22 July 2012 - 10:31 AM

Like some fade out to black between screen transition..
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.

#7 KrimsomKing   Members   -  Reputation: 104

Like
0Likes
Like

Posted 22 July 2012 - 06:54 PM

Ok thanks, I`ll start looking into shaders.

#8 mhagain   Crossbones+   -  Reputation: 8285

Like
0Likes
Like

Posted 22 July 2012 - 07:38 PM

A shader requires drawing a fullscreen quad too. Basic theory is that you either render to an FBO, or - if you don't support FBOs - glCopyTexSubImage2D to another texture, then draw over the scene with depth test/depth write disabled and a glOrtho projection. For something as simple as a colour tint or a fade-to-black you don't even need that, you can just draw an untextured quad over the scene (also glDisable (GL_TEXTURE_2D) if doing this) with blending enabled and adjusting your glColor4f over time.

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.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS