在mfc中显示左右平面中的opengl纹理。 [英] Display opengl texture in left and right plane in mfc.

查看:77
本文介绍了在mfc中显示左右平面中的opengl纹理。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在窗口的两侧显示opengl纹理,在MFC中创建一个双视图。怎么做。



我尝试了什么:



我尝试下面的代码,但只有一个出现



void OverlayDisplayDlg :: DrawTwinView()

{

glClear (GL_COLOR_BUFFER_BIT); //清除颜色缓冲区

glMatrixMode(GL_MODELVIEW); //操作模型 - 视图矩阵

glLoadIdentity(); //重置模型视图矩阵

glEnable(GL_TEXTURE_2D);

glGenTextures(5,& m_glTexture [4]);

glBindTexture (GL_TEXTURE_2D,m_glTexture [4]);

glPushMatrix();

m_glTexture [0] = ApplyTexture();

glEnable(GL_TEXTURE_2D) ;

glBindTexture(GL_TEXTURE_2D,m_glTexture [0]);

glBegin(GL_QUADS);

glTexCoord2d(0.0,0.0);

glVertex2f(-1.0f,-1.0f);

glTexCoord2d(1.0,0.0);

glVertex2f(0.0f,-1.0f);

glTexCoord2d(1.0,1.0);

glVertex2f(0.0f,1.0f);

glTexCoord2d(0.0,1.0);

glVertex2f(-1.0f,1.0f);

glEnd();

glDisable(GL_TEXTURE_2D);

glPopMatrix();

glPushMatrix();



GLuint glTexture;

glTexture = ApplyTexture();

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,glTexture);

glBegin(GL_QUADS);

glTexCoord2d(0.0,0.0);

glVertex2f(0.2f,-1.0f);

glTexCoord2d(1.0,0.0);

glVertex2f(1.0f,-1.0f);

glTexCoord2d(1.0,1.0);

glVertex2f(1.0f,1.0f);

glTexCoord2d(0.0,1.0);

glVertex2f(0.2f,1.0f);

glEnd();

glDisable(GL_TEXTURE_2D);

glPopMatrix();

SwapBuffers(m_hDeviceContextDC);

}



GLuint OverlayDisplayDlg :: ApplyTexture()

{

GLuint glTexture;

ReadData(_T(D:\\ Bin Files \\InputData_1280_690.bin),WIDTH,HEIGHT,PIXEL,m_pbyImageData);

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glEnable(GL_TEXTURE_2D);

glEnable(GL_COLOR_MATERIAL);

glGenTextures(1,& glTexture);

glBindTexture(GL_TEXTURE_2D,glTexture);

glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); //选择调制以将纹理与颜色混合以进行着色

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); //当纹理区域很小时,双线性过滤最近的mipmap

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); //当纹理区域很大时,双线性过滤原始的

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); //纹理在边缘包裹(重复)

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

glColor4f(1.0f,1.0f,1.0f,1.0f );

glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,WIDTH,HEIGHT,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,m_pbyImageData); //将纹理应用图像显示到屏幕

glDisable(GL_TEXTURE_2D);

glDisable(GL_COLOR_MATERIAL);

返回glTexture;

}



请帮帮我

I need to display opengl texture on 2 sides of window creating a twin view in MFC. How to do this.

What I have tried:

I tried the below code but only one is appearing

void OverlayDisplayDlg :: DrawTwinView()
{
glClear( GL_COLOR_BUFFER_BIT ); // Clear the color buffer
glMatrixMode( GL_MODELVIEW ); // To operate on Model-View matrix
glLoadIdentity(); // Reset the model-view matrix
glEnable( GL_TEXTURE_2D );
glGenTextures( 5, &m_glTexture[4] );
glBindTexture( GL_TEXTURE_2D, m_glTexture[4] );
glPushMatrix();
m_glTexture[0] = ApplyTexture();
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, m_glTexture[0] );
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2f( -1.0f, -1.0f );
glTexCoord2d( 1.0,0.0 );
glVertex2f( 0.0f, -1.0f );
glTexCoord2d( 1.0,1.0 );
glVertex2f( 0.0f, 1.0f );
glTexCoord2d( 0.0,1.0 );
glVertex2f( -1.0f, 1.0f );
glEnd();
glDisable( GL_TEXTURE_2D );
glPopMatrix();
glPushMatrix();

GLuint glTexture;
glTexture = ApplyTexture();
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, glTexture );
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2f( 0.2f, -1.0f );
glTexCoord2d( 1.0,0.0 );
glVertex2f( 1.0f, -1.0f );
glTexCoord2d( 1.0,1.0 );
glVertex2f( 1.0f, 1.0f );
glTexCoord2d( 0.0,1.0 );
glVertex2f( 0.2f, 1.0f );
glEnd();
glDisable( GL_TEXTURE_2D );
glPopMatrix();
SwapBuffers( m_hDeviceContextDC );
}

GLuint OverlayDisplayDlg :: ApplyTexture()
{
GLuint glTexture;
ReadData( _T( "D:\\Bin Files\\InputData_1280_690.bin" ), WIDTH, HEIGHT, PIXEL, m_pbyImageData);
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable( GL_TEXTURE_2D );
glEnable(GL_COLOR_MATERIAL);
glGenTextures( 1, &glTexture );
glBindTexture( GL_TEXTURE_2D, glTexture );
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE ); // Select modulate to mix texture with color for shading
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); // When texture area is small, bilinear filter the closest mipmap
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); // When texture area is large, bilinear filter the original
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); // The texture wraps over at the edges (repeat)
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glColor4f( 1.0f, 1.0f, 1.0f, 1.0f);
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, WIDTH, HEIGHT, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, m_pbyImageData ); // To dislay texture applied image to screen
glDisable( GL_TEXTURE_2D );
glDisable( GL_COLOR_MATERIAL );
return glTexture;
}

Please help me

推荐答案

你可以运行两个渲染上下文每个部分并使用wglMakeCurrent选择它们。



在使用OpenGL系统执行任何操作之前,您需要记住切换到该渲染上下文。



这就是我在本文中所做的,在每个MDIClient中创建带有OpenGL窗口的MDI应用程序,你可以拥有任意数量的OpenGL窗口

Native Win32 API OpenGL教程 - 第2部分 [ ^ ]



另一种方法是s etup ViewPorts在这里的NeHe教程中

NeHe Productions:Multiple Viewports [ ^ ]



所以NeHe方法有一个大的平面上下文,你在交换缓冲区之前设置了视口。



OpenGL插入命令glScissor试试请大家加快速度,看下一条评论。



我在MDI示例中使用的顶级解决方案在处理开销方面更快,因为每次只有渲染调用处理渲染上下文中的对象。当被要求通过另一个屏幕上的视图和视图之外的事物渲染迭代时,NeHe分屏会接近两个屏幕中的每个屏幕但是仍然需要处理能力才能使渲染过程完成。然而,NeHe方法更容易,因为你不能忘记更改wglContext并最终处理错误的屏幕。当我在该代码上添加拖放功能并创建了一个错误时,我就这样做了:-)



我还应该说这是旧的遗留代码还有更多优雅的方法,如果你准备使用一个你还没有遇到的东西使用更高版本的OpenGL,还有一个名为VAO的东西。
You can either run two render contexts one for each section and select them with wglMakeCurrent.

You need to remember to switch to that render context before you do ANYTHING with the OpenGL system.

That is what I did in this article which create MDI application with an OpenGL window in each MDIClient you can have as many OpenGL windows as you like
Native Win32 API OpenGL Tutorial - Part 2[^]

The alternative approach is to setup ViewPorts which is in a NeHe tutorial here
NeHe Productions: Multiple Viewports[^]

So the NeHe approach has one big flat context and you set the viewport before you swapbuffers for the render.

OpenGL inserted the command glScissor to try and help out with speed on this, see the next comment.

The top solution I used in the MDI example is faster in terms of processing overhead because each render call only deals with objects in the render context. The NeHe split screen approach each of the two screens when asked to render iterates thru things that are on the other screen and out of view but it still takes processing power for the render process to work that out. However the NeHe approach is somewhat easier in that you can't forget to change wglContext and end up dealing with the wrong screen. I did that when I added drag and drop ability on that code and created a bug :-)

I should also say this is all old legacy code there are far more elegant ways to do this if you are prepared to use later versions of OpenGL using a thing you haven't encountered yet called VAO's.


void OverlayDisplayDlg :: DrawTwinView()

{

glClear(GL_COLOR_BUFFER_BIT); //清除颜色缓冲区

glMatrixMode(GL_MODELVIEW); //操作模型 - 视图矩阵

glLoadIdentity(); //重置模型视图矩阵

glEnable(GL_TEXTURE_2D);

glGenTextures(5,&m_glTexture [4]);

glBindTexture(GL_TEXTURE_2D ,m_glTexture [4]);

glPushMatrix();

m_glTexture [0] = ApplyTexture();

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,m_glTexture [0]);

glBegin(GL_QUADS);

glTexCoord2d(0.0,0.0);

glVertex2f(-1.0f,-1.0f);

glTexCoord2d(1.0,0.0);

glVertex2f(0.0f,-1.0f);

glTexCoord2d(1.0,1.0);

glVertex2f(0.0f,1.0f);

glTexCoord2d(0.0,1.0);

glVertex2f(-1.0f,1.0f);

glEnd();

glPopMatrix();

glPushMatrix();

glBegin(GL_QUADS);

glTexCoord2d(0.0,0.0);

glVertex2f(0.0f,-1.0f);

glTexCoord2d(1.0,0.0);

glVertex2f(1.0f,-1.0f);

glTexCoord2d(1.0,1.0);

glVertex2f(1.0f,1.0f);

glTexCoord2d(0.0,1.0);

glVertex2f(0.0f,1.0f);

glEnd();

glPopMatrix();

glDisable(GL_TEXTURE_2D);

SwapBuffers(m_hDeviceContextDC);

}
void OverlayDisplayDlg :: DrawTwinView()
{
glClear( GL_COLOR_BUFFER_BIT ); // Clear the color buffer
glMatrixMode( GL_MODELVIEW ); // To operate on Model-View matrix
glLoadIdentity(); // Reset the model-view matrix
glEnable( GL_TEXTURE_2D );
glGenTextures( 5, &m_glTexture[4] );
glBindTexture( GL_TEXTURE_2D, m_glTexture[4] );
glPushMatrix();
m_glTexture[0] = ApplyTexture();
glEnable( GL_TEXTURE_2D );
glBindTexture( GL_TEXTURE_2D, m_glTexture[0] );
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2f( -1.0f, -1.0f );
glTexCoord2d( 1.0,0.0 );
glVertex2f( 0.0f, -1.0f );
glTexCoord2d( 1.0,1.0 );
glVertex2f( 0.0f, 1.0f );
glTexCoord2d( 0.0,1.0 );
glVertex2f( -1.0f, 1.0f );
glEnd();
glPopMatrix();
glPushMatrix();
glBegin( GL_QUADS );
glTexCoord2d(0.0,0.0);
glVertex2f( 0.0f, -1.0f );
glTexCoord2d( 1.0,0.0 );
glVertex2f( 1.0f, -1.0f );
glTexCoord2d( 1.0,1.0 );
glVertex2f( 1.0f, 1.0f );
glTexCoord2d( 0.0,1.0 );
glVertex2f( 0.0f, 1.0f );
glEnd();
glPopMatrix();
glDisable( GL_TEXTURE_2D );
SwapBuffers( m_hDeviceContextDC );
}


这篇关于在mfc中显示左右平面中的opengl纹理。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆