我正在尝试缩放图像而不使用太长的函数gluScaleImage(并且没有在我的项目中实现包含“glh”lib(使用glhScaleImage))。 我看了this advice:
如果这只是显示各种尺寸的图像,为什么不创建纹理四边形和 将其缩放到要求的大小?纹理总是可以是相同的大小。
这就是我尝试使用以下代码: 结果是我看到红色写得很好“BACK”,但是看不到“在glflush之前”并且背景有一种奇怪的颜色(有时是紫色,有时是绿色的(关于绿色问题,我怀疑它是错误的初始化)显卡)) =>任何人都可以告诉我使用glReadPixels获得的缓冲区纹理有什么问题? =>还是有另一种解决方案? (我希望修改此代码而不是其他解决方案(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)
答案 0 :(得分:0)
好的我发现了错误(glGetError()
):
GL_BGRA
不存在
所以我用GL_RGBA
替换它,我的纹理很好地绑定到四边形
(GL_RGBA8
不起作用)
我仍然有一个绿色污点问题,但这必须是另一个问题:框架用YUV初始化?