Page 1 of 1

MiniGL glCopyPixels bug ?

Posted: Sat Feb 16, 2013 11:01 pm
by AmiDARK
Hello,

When I want to copy the front buffer to the back buffer, I use glCopyPixels.
I know it's slow but it's the only solution I've found to backup the last drawn frame.
(it's mainly used for 2D).

So, I supposed that it should work this way :

Code: Select all

        glViewport( 0, 0, BasicSetup.DisplayWIDTH, BasicSetup.DisplayHEIGHT );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluOrtho2D( 0, BasicSetup.DisplayWIDTH -1, 0, BasicSetup.DisplayHEIGHT -1 );
        glReadBuffer( GL_FRONT ); glDrawBuffer( GL_BACK );
        glRasterPos2i( 0, 0 );
        glCopyPixels( 0, 0, BasicSetup.DisplayWIDTH, BasicSetup.DisplayHEIGHT, GL_COLOR );
but it don't work... the background scroll down each frame....
To get the wanted result (no scroll), I need do this :

Code: Select all

        glViewport( 0, 0, BasicSetup.DisplayWIDTH, BasicSetup.DisplayHEIGHT );
        glMatrixMode( GL_PROJECTION );
        glLoadIdentity();
        gluOrtho2D( 0, BasicSetup.DisplayWIDTH -1, 0, BasicSetup.DisplayHEIGHT -1 );
        glReadBuffer( GL_FRONT ); glDrawBuffer( GL_BACK );
        glRasterPos2f( 0.0f, 0.5f );
        glCopyPixels( 0, 0, BasicSetup.DisplayWIDTH, BasicSetup.DisplayHEIGHT, GL_COLOR );
        glReadBuffer( GL_BACK );
        glEnable( GL_SCISSOR_TEST );
Is it normal that I must put Raster Pos to (0.0, 0.5) instead of (0.0, 0.0) ?
Strange behaviour.. Is this a bug ?

Regards,
AmiDARK

Re: MiniGL glCopyPixels bug ?

Posted: Mon Feb 18, 2013 1:19 pm
by Hans-Joerg Frieden
Do you have a MODELVIEW matrix loaded? The glRasterPos is subject to transformation, so a MODELVIEW matrix might influence it.

Re: MiniGL glCopyPixels bug ?

Posted: Mon Feb 18, 2013 1:40 pm
by AmiDARK
Hello Hans,

Thank you for your answer. Will investigate this problem.

One more question, does default MODELVIEW matrix (without changes) may change the glRasterPos ?
I use gluOrtho2D to create the 2D view system. Does this interact too ?

Kindest Regards,
AmiDARK

Re: MiniGL glCopyPixels bug ?

Posted: Tue Feb 19, 2013 1:35 pm
by Hans-Joerg Frieden
AmiDARK wrote:One more question, does default MODELVIEW matrix (without changes) may change the glRasterPos ?
IIRC, the default matrix for both stacks are Identity, but to be sure, you should simply load one.
I use gluOrtho2D to create the 2D view system. Does this interact too ?
That's a yes. glRasterPos is transformed just like any other vertex specification, so it makes a difference.

Re: MiniGL glCopyPixels bug ?

Posted: Tue Feb 19, 2013 1:38 pm
by AmiDARK
I must admit that I'm lost with all these.

I was thinking that "raster" position cannot be transformed (because it's the raster position and not a 3D position).
But, what should I do to be sure the glRasterPos2i( 0, 0 ) will be on the bottom left corner ?

EDIT : Just seen that glTranslatef() modify glRasterPos ... so, if I use glTranslatef( 0.0f, 0.0f, 0.0f ) it should replace glRasterPos2i ( 0, 0 ) exactly on the bottom left corner. Right ?

Thank you for all your informations.

Kindest Regards,
AmiDARK

Re: MiniGL glCopyPixels bug ?

Posted: Wed Feb 20, 2013 12:29 pm
by Hans-Joerg Frieden
AmiDARK wrote:EDIT : Just seen that glTranslatef() modify glRasterPos ... so, if I use glTranslatef( 0.0f, 0.0f, 0.0f ) it should replace glRasterPos2i ( 0, 0 ) exactly on the bottom left corner. Right ?
glTranslatef (0.0f, 0.0f, 0.0f) is a no-op. Values specified with glTranslate are relative, not absolute. Think of glTranslate as instructions to the guy holding the camera, i.e. "move one meter back".

A good book on OpenGL is this http://www.cse.chalmers.se/edu/year/201 ... edbook.pdf, especially in this case chapter 3. Most of it covers age-old versions of OpenGL, but is still valid up to OpenGL 4.3 (although the Core profile of 4.3 does away with it).

Re: MiniGL glCopyPixels bug ?

Posted: Wed Feb 20, 2013 2:00 pm
by AmiDARK
Hi Hans,

thank you for this link.
I will read it carefully (hoping I'll understand all because ... English is not my native language :p )

Kindest Regards,
AmiDARK