0

在 GLForm(带有 borland builder 的 openGL)的 Draw() 函数中,我首先使用名为 capture_card::paintGL() 的 SDK 函数绘制图像。这个函数在被调用之前必须要有这个投影:

glViewport(0, 0, (GLsizei)newSize.width, (GLsizei)newSize.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);

在这个绘制图像的前景上,我必须绘制一个已经为另一个视口和另一个 glortho 投影编码的另一个层:

(在调用“onResize”事件的 MainResizeGL() 中):

glViewport(-width, -height, width * 2, height * 2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(double(-width)*viewport_ratio, double(width)*viewport_ratio, double(-height), double(height), 1000.0, 100000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

(并且在“Ontimer”调用的 MainDraw() 中):

glLoadIdentity();
glTranslatef(0.0, 0.0, -50000.0);
mpGLDrawScene->DrawScene(); //(this calls a doDrawScene() I don't understand exactly how it draws : with calling this->parent, etc.)
glFlush();
SwapBuffers(ghDC);

所以我将 MainDraw() 转换为以下内容:

// viewport and projection needed for the paintGL
glViewport(0, 0, (GLsizei)newSize.width, (GLsizei)newSize.height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

glMatrixMode(GL_MODELVIEW);

// call of the paintGL
if(capture_button_clicked) capture_card::paintGL();

// content of the ResizeGL in order to get back to the projection desired and to matrixmode modelview
glViewport(-width, -height, width * 2, height * 2);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(double(-width)*viewport_ratio, double(width)*viewport_ratio, double(-height), double(height), 1000.0, 100000.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

// original drawscene call
glLoadIdentity();
glTranslatef(0.0, 0.0, -50000.0);
mpGLDrawScene->DrawScene(); //(this calls a doDrawScene() I don't understand exactly how it draws : with calling this->parent, etc.)
glFlush();
SwapBuffers(ghDC);

结果是我看到了古代项目的“drawscene”项目,但是当我点击“capture_button”时,paintGL 仍然不可见,并且绘制的项目变成了类似于 alpha 通道画布的东西。

我尝试在paintGL之后添加glScalef(width,height,1),更改了glTranslatef(0,0,50000),结果我看到了少量带有paintGL颜色的像素,但是覆盖项然后消失了.

我怎样才能让这两个不同的视口叠加(即paintGL上方的drawscene)?

提前感谢,干杯,阿诺德。

4

1 回答 1

0

与视口一起使用剪刀测试

glEnable(GL_SCISSOR_TEST);
glScissor(viewport.x, viewport.y, viewport.width, viewport.height)
glViewport(viewport.x, viewport.y, viewport.width, viewport.height)

并清除不同渲染阶段之间的深度缓冲区(仅深度缓冲区)。

于 2011-03-01T23:28:31.540 回答