本文介绍了在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

推荐答案



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

10-11 14:38