我正在尝试渲染从 .asc 文件中读取后生成的图像。我执行所有必要的转换,然后将其显示在屏幕上。输出是 ppm 图像。最初我使用 windows API 相关的 BitBlt 函数来渲染图像,它完美地显示在屏幕上。然后我尝试使用 OpenGL 渲染相同的图像,但它没有。
如果我使用 DrawPixels,它会显示一个黑屏,如果我使用纹理映射,它会显示一个部分白框。我以前使用过 targa 图像,但这是我第一次创建 ppm 图像,但我认为这不是问题,因为我只是试图渲染 char* 类型的缓冲区。
对于 BitBlt,我使用:
binfo->bmiHeader.biBitCount = 24;
binfo->bmiHeader.biHeight = -abs(binfo->bmiHeader.biHeight); //for top-down image
SetDIBits(memDC,m_bitmap,0, pApp->GetFrameBufferHeight(), pApp->GetFrameBuffer(), binfo, DIB_RGB_COLORS); //replace the 3rd last argument with the framebuffer
SetStretchBltMode(hDC, COLORONCOLOR);
RECT client;
GetClientRect(hwnd, &client);
BitBlt(hDC,0,0,pApp->GetFrameBufferWidth(),pApp->GetFrameBufferHeight(),memDC,0,0,SRCCOPY);
使用 OpenGL:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_pTextureID);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -10); //z translation is the last value
glBegin(GL_QUADS);
glTexCoord2f(0,0); glVertex2f(0,0);
glTexCoord2f(1,0); glVertex2f(m_nWindowWidth,0);
glTexCoord2f(1,1); glVertex2f(m_nWindowWidth,m_nWindowHeight);
glTexCoord2f(0,1); glVertex2f(0,m_nWindowHeight);
glEnd();
glPopMatrix();
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);
m_pTextureId 映射 pApp->GetFrameBuffer 对象。我基本上是在尝试使用不同的方法渲染存储在 char* 变量中的图像数据。一种方法有效,所以我确定缓冲区不包含无效数据。