Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 20-Apr-16 19:00pm

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.
 
Share this answer
 
v6
Comments
Member 10536430 20-Apr-16 5:40am    
The above example is for creating window for each opengl textures, actually i want to display 2 opengl textures in one window. How to do that?
leon de boer 20-Apr-16 8:50am    
I am sort of stunned you are asking me that as that is nothing to do with OpenGL. Slide two windows inside the parent window just like normal in an MFC application, the parent doesn't draw. Have you done splitter planes before?.

In my MDI example put two windows up and tile them. If I turned the border style off you have exactly what you are asking for. You can actually do it if you want just turn the WS_OVERLAPPEDWINDOW style off the MDI child and you have two black screens butted hard against each other inside the parent. hmmm let me put a small frame so you see them and I will put splitter on frame.

Update: LOL took me two seconds to do it is this what you mean ... http://tinypic.com/view.php?pic=lh7k7&s=9

Thats two MDIchildren side by side with frames turned off ... looks like one screen to you doesn't it. With a control in on the parent you could even slide the views.
leon de boer 20-Apr-16 9:35am    
There you go I put a splitter control down the middle and moved it so right side smaller than left
http://i65.tinypic.com/xd7dhd.jpg

Its all just an illussion its actually two windows that totally occupy the client area of the parent window with there borders turned off.

I pulled all the MDI code out, code for just a straight splitter window now ... http://s000.tinyupload.com/?file_id=08701924383590736839
Load left or right window off menu or drag and drop a file on the window side you want.
Member 10536430 21-Apr-16 1:00am    
Thanks a lot for your answer.

I updated and cleaned my code and got the answer.
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 );
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900