PDA

View Full Version : 4 viewport



cwc36
09-18-2002, 10:31 PM
I using MFC to create a tool just like 3D Studio Max.It contain 4 viewports. The problem is :
---when i render a 3ds model to the four viewport. Only one viewport was render in normal. The rest of three are render also but the object look like in black and white.

Can u please let me know y it look like that ?
Thank for your kindly help.....

Mazy
09-19-2002, 12:34 AM
Do you use scissor and glViewport to make 4 viewports on one render context, or do you have 4 render context?

in the later case, remember that each rendercontext have its own states, so if you dont set the material and textures in each RC then you will use the default ( which is a grey material if you have enabled lighting)

Deiussum
09-19-2002, 04:48 AM
There's a couple things you should do if you are using MFC to create multiple panes.

1. Make sure that for the view for each pane you set the CS_OWNDC flag in the PreCreateWindow method. You need to do that by setting the cs.lpszClass member to a new class using the function AfxRegisterWndClass.

2. Before rendering in a particular view, always make sure to make the context current for that view by using wglMakeCurrent.

3. If you are using display lists that need to be shared, make sure to use the wglShareLists function.

cwc36
09-19-2002, 04:21 PM
Thank for your kindly reply,
but i think i post the source code will make it more easy to discuss .....right?

Can u please figure it out:

Init()
{
float fov = 60;
float a_ratio;
float znear = 1;
float zfar = 10000;
CRect rect;

timer = this->SetTimer(0, 1, NULL);
map_window_dc =
m_ViewPortTop.GetDC()-> m_hDC;

Left_window_dc =
m_ViewPortLeft.GetDC()->m_hDC;

Front_window_dc =
m_ViewPortFront.GetDC()->m_hDC;

All_window_dc =
m_ViewPortAll.GetDC()->m_hDC;

SetWindowPixelFormat(map_window_dc);
SetWindowPixelFormat(Left_window_dc);
SetWindowPixelFormat(Front_window_dc);
SetWindowPixelFormat(All_window_dc);

map_window_rc =
wglCreateContext (map_window_dc);

Left_window_rc =
wglCreateContext(Left_window_dc);

Front_window_rc =
wglCreateContext(Front_window_dc);

All_window_rc =
wglCreateContext(All_window_dc);

//***************************************** // Setup Top ViewPort
//****************************************** wglMakeCurrent(map_window_dc,
map_window_rc);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
m_ViewPortTop.GetClientRect(&rect);
w_top = rect.right;
h_top = rect.bottom;
a_ratio = w_top / h_top;
glViewport(0,0, (GLsizei) w_top,
(GLsizei) h_top);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, a_ratio, znear, zfar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//*******************************************// Setup Left ViewPort
//******************************************* wglMakeCurrent(Left_window_dc,
Left_window_rc);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glShadeModel(GL_SMOOTH);
//glEnable(GL_LIGHTING);
//glEnable(GL_LIGHT0);
glEnable(GL_COLOR_MATERIAL);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
m_ViewPortLeft.GetClientRect(&rect);
w_left = rect.right;
h_left = rect.bottom;
a_ratio = w_left / h_left;
glViewport(0,0, (GLsizei) w_left,
(GLsizei) h_left);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fov, a_ratio, znear, zfar);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Font ViewPort...(same as above except
variable.....)
//All viewport..........

}

DrawLeft()
{
wglMakeCurrent(Left_window_dc,
Left_window_rc);
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Render();
glFlush();
SwapBuffers(Left_window_dc);

}

DrawFront()
{
wglMakeCurrent(Front_window_dc,
Front_window_rc);
glClear(GL_COLOR_BUFFER_BIT |
GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
Render();
glFlush();
SwapBuffers(Front_window_dc);
}

rgpc
09-19-2002, 06:51 PM
Is the object you are rendering textured? If so is the view that is correct appearing with the texture, while the others are not (hence one appears "coloured" while the others are "black & white")?

If this is the case then you need to call wglShareLists() so that your Texture objects are available to all Rendering contexts (which I notice is absent from your code example).

Cheers,

Scott S.

[This message has been edited by rgpc (edited 09-19-2002).]

cwc36
09-19-2002, 10:50 PM
No... the object don't have texture.. Only one view look colored and the rest are black

Deiussum
09-20-2002, 04:12 AM
Take a look at point number 1 of my previous response. You don't show the code for the PreCreateWindow anywhere either. Not setting the CS_OWNDC flag can cause weirdness, especially in the case of using multiple views in MFC.

cwc36
09-22-2002, 07:56 PM
Actually i didn't used PreCreateWindow function. i used dialog box and try to
create 4 static text as viewport.Then i put the initialize in the OnInitDialog()....
Actually i'm not understand about the CS_OWNDC flag... Is it like:

HGLRC map_window_rc;
HGLRC Left_window_rc;
HGLRC Front_window_rc;
HGLRC All_window_rc;

HDC map_window_dc;
HDC Left_window_dc;
HDC Front_window_dc;
HDC All_window_dc;

if yes, i had set it in OnInitDialog()......

Deiussum
09-23-2002, 04:15 AM
Ahh, so you are just using static controls for the OpenGL rendering. I was assuming you had an MDI or SDI app with splitter windows with different CView derived classes.

The way you create windows is to first create a window class (not a C++ class, the notion of a window class in Windows is different). After you create that window class you use that to create the window. It is when creating the window class that you need to use CS_OWNDC. Unfortunately, MFC tends to hide this step and you need to do it on the PreCreateWindow function.

In the case of common controls, however, you use pre-made window classes. So by using static controls like that, you do not have the ability to set the CS_OWNDC flag, which may or may not be causing you problems.

cwc36
09-23-2002, 03:56 PM
So................
Do u have any idea or suggestion?
What i should i do now?

Deiussum
09-24-2002, 04:53 AM
Well... if your problem is in fact caused by not having the CS_OWNDC property set (and I'm not positive it is, it's just one possibility I thought of), I think your only option would be to re-think how you are doing the multiple views.

Either:
A) Just use a single static control and break it into 4 distinct views by using glViewport and glScissor commands.

B) Re-design your app so that you can use CView derived classes for each of the distinct views. This might be a bit more complicated.

Before you do the above, you might want to verify that your problem is indeed from not setting the CS_OWNDC and not something else. Perhaps try only initialize OpenGL for one of the views at a time and make sure that that view is correctly displayed.

cwc36
09-25-2002, 04:34 PM
Thank for your help