UPDATED
If you want the full source code of this application in questioned, you can fork it from my github repository : OpenGLModeler
I’ve built a Visual C++.NET 2008 application that display three viewport. All was just fine, until I implemented the Texturing functionality. As you can see from my Screenshot here, only the front viewport got its texture rendered. This is my code for handling its drawing method, base on the type of viewport defined. I can provide you with the full source code if you want, but here is the snippet :
public:
GLvoid ReSizeGLScene(GLsizei width, GLsizei height){ // Resize and initialise the gl window
MySetCurrentGLRC();
if (height==0) // Prevent A Divide By Zero By
{
height=1; // Making Height Equal One
}
glViewport(0,0,width,height); // Reset The Current Viewport
glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
glLoadIdentity(); // Reset The Projection Matrix
// Calculate The Aspect Ratio Of The Window
switch(cameraType){
case 1:
gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
gluLookAt(
-4,4,4,//eye
0,0,0,//center
0,1,0);//up
break;
case 2://front : texture rendered correctly
glOrtho(-2,2,-2,2,-50,50);
gluLookAt(
0,0,2,//eye 0,0,2
0,0,0,//center 0,0,0
0,1,0);//up 0,1,0
break;
case 3://top
glOrtho(-2,2,-2,2,-50,50);
gluLookAt(
0,2,0,//eye
0,0,0,//center, 0
0,0,-1);//up
break;
}
glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
glLoadIdentity(); // Reset The Modelview Matrix
UINT flags = SWP_NOZORDER | SWP_NOACTIVATE;
SetWindowPos((HWND)this->Handle.ToPointer() , 0, 0, 0,
width, height, flags);
}
EDITED : explain modified code
I borrow this code from codeproject, and modify it to have multi viewport functionality. These are I think the important modification : first, the instantiation of OpenGL Viewport:
glPerspective = gcnew COpenGL(picPerspective, picPerspective->Width, picPerspective->Height,1);
glFront = gcnew COpenGL(picFront, picFront->Width, picFront->Height,2);
glTop = gcnew COpenGL(picTop, picTop->Width , picTop->Height,3);
The last argument of the COpenGL is the type of viewport : perspective(1), front(2) and top(3). And the second modification is the way I draw the scene. It using a timer, like this :
private: System::Void timerRefreshPicture_Tick(System::Object^ sender, System::EventArgs^ e) {
UNREFERENCED_PARAMETER(sender);
UNREFERENCED_PARAMETER(e);
glPerspective->Render(daftarObject);
glPerspective->SwapOpenGLBuffers();
glTop->Render(daftarObject);
glTop->SwapOpenGLBuffers();
glFront->Render(daftarObject);
glFront->SwapOpenGLBuffers();
}
I try to disable the code that draw the glFront, and yes, the glTop got its textured correctly. And the same happen if I disabled the glTop. I suspect this code :
virtual System::Void MySetCurrentGLRC()
{
if(m_hDC)
{
if((wglMakeCurrent(m_hDC, m_hglrc)) == NULL)
{
MessageBox::Show("wglMakeCurrent Failed");
}
//wglShareLists(m_hglrc,m_hglrc);<== not working
}
}
How can I use wlgShareList in this code? Thanks

If you have multiple GL contexts, you need to share textures between the contexts to enable them being created in a context and displayed in another.
You may take a look at wglShareLists which is to be called after you create your ‘secondary’ contexts (‘main’ context being the first context created).
You can call wglShareLists after having created your various contexts :
Note that it’s important that ‘glFront’ and ‘glTop’ contexts do not contain any existing texture when calling wglShareLists.