Ok thanks. So I tried the function gluScaleImage but it is too long (and I don’t achieve to include “glh” lib in my project (to use glhScaleImage)).
Meanwhile, I’ve read here :
http://gamedev.stackexchange.com/questions/10414/faster-way-to-scale-images-than-gluscaleimage
this advice :
" If this is just about displaying images with various sizes, why not create a textured quad and scale it to the requested size? The texture could always be the same size then."
And that is what I try to do with the following code :
the result is that I see well written “BACK” in red but don’t see “before glflush” and the background has a strange color (sometimes purple, sometimes green (concerning the green issue i suspect it to be a wrong initialization of the graphic card))
=> can anyone tell me what is wrong in my texturing of the buffer obtained with glReadPixels ?
=> or is there another solution ?
(I would prefer a correction of this code than another solution (framebuffer, …)).
// —
glColor4ub(255,0,0,200);
myPrintingFunction(200,200,“before glFlush”);
glFlush();
// Unload Bytes
if (mBuffer != NULL)
{
delete[] mBuffer;
mBuffer = NULL;
}
// Load Bytes from current window
mBuffer = new GLubyte[ClientWidth * ClientHeight * 4];
glReadBuffer(GL_BACK);
glReadPixels(0, 0, ClientWidth, ClientHeight, GL_BGRA, GL_UNSIGNED_BYTE, mBuffer);
SwapBuffers(ghDC);
// Unload TextureId
if (mTextureId != 0)
{
glDeleteTextures(1, &mTextureId);
mTextureId = 0;
}
// Load TextureId
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(1, &mTextureId);
glBindTexture(GL_TEXTURE_2D, mTextureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_BGRA, ClientWidth, ClientHeight, 0, GL_BGRA, GL_UNSIGNED_BYTE, mBuffer);
// —
glViewport(-mBufferWidth, -mBufferHeight, mBufferWidth * 2, mBufferHeight * 2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(double(-mBufferWidth), double(mBufferWidth), double(-mBufferHeight), double(mBufferHeight), 1000.0, 100000.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -50000.0);
glClearColor(0,0,0,1);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mTextureId);
mxIncrust0 = 0.0;
myIncrust0 = 0.0;
mxIncrust1 = mBufferWidth;
myIncrust1 = mBufferHeight;
glBegin(GL_QUADS);
glColor4ub((unsigned char)255,(unsigned char)255,(unsigned char)255,(unsigned char)255);
glTexCoord2d(0.0, 0.0);
glVertex2d(mxIncrust0, myIncrust0);
glTexCoord2d(0.0, 1.0);
glVertex2d(mxIncrust0, myIncrust1);
glTexCoord2d(1.0,1.0);
glVertex2d(mxIncrust1, myIncrust1);
glTexCoord2d(1.0,0.0);
glVertex2d(mxIncrust1, myIncrust0);
glEnd();
glDisable(GL_TEXTURE_2D);
glColor4ub(255,0,0,200);
myPrintingFunction(100,100,“BACK”);
glFlush();
if (mBufferPlayout != NULL)
{
delete[] mBufferPlayout;
mBufferPlayout = NULL;
}
mBufferPlayout = new GLubyte [mBufferWidth * mBufferHeight * 4];
glReadBuffer(GL_BACK);
glReadPixels(0, 0, mBufferWidth, mBufferHeight, GL_BGRA, GL_UNSIGNED_BYTE, mBufferPlayout);
// then I pass this mBufferPlayout to a graphic card (capture card in output in fact)
Thanks for any help, cheers, Arnaud.