Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/opengl/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
OpenGL:如何在同一个GL窗口中叠加在不同视口和glortho中绘制的两个GL_Opengl_Adapter_Scale_Translate_Viewport - Fatal编程技术网

OpenGL:如何在同一个GL窗口中叠加在不同视口和glortho中绘制的两个GL

OpenGL:如何在同一个GL窗口中叠加在不同视口和glortho中绘制的两个GL,opengl,adapter,scale,translate,viewport,Opengl,Adapter,Scale,Translate,Viewport,在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, -

在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投影做好了编码:

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

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

因此,我将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_”按钮时,画图仍然不可见,绘制的项目变成类似alpha通道的canva

我尝试在paintGL之后添加glScalef(宽度,高度,1),更改了glTranslatef(0,050000),结果我看到了一个带有paintGL颜色的少量像素,但覆盖项随后消失

如何使这两个不同的视口叠加(即画图上方的绘图场景)

提前感谢,, 干杯
Arnaud.

将剪切测试与视口一起使用

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

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

谢谢!只清除深度缓冲区,并在两者之间调用glBlendFunc、glBlendFuncSeparate和glTexEnvf就是解决方案!
// 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);
glEnable(GL_SCISSOR_TEST);
glScissor(viewport.x, viewport.y, viewport.width, viewport.height)
glViewport(viewport.x, viewport.y, viewport.width, viewport.height)