Originally posted by: Horry Chan
I have also tried to do the similar thing two months before.
According to an example from "OpenGL SUPERBIBLE SE" by RICHARD WRIGHT, I could modify something and finish my task.
But, it seems the method I used is a bit different from yours. However, yours seems more stable coz the OpenGL screen in my simulation program will disappear after the other application's windows overlapped it. Should anyone interest in one done by me, plz email me. I will send you the program including the source in VC6.
Originally posted by: Joel Parris
There has been a more advanced opengl scene in a dialog box application written by Brian Bailey that has been available for more that a year now.
http://www.opengl.org/developers/faqs/technical/mswindows.htm#mswi0160
Also there are a few examples of this at my website.
Originally posted by: meCutio
very cool...
just a quick side note...
Most people would I assume would be interested in using a second Opengl window on a dialog as well as a primary rendering context (generally created in a view). There are a couple of things you must do to make this work.
this is all basic stuff... so if your elite, don't bother.
I assume your looking at the tutorial.
1.)
add an OnCreate Message to your derived CWnd Class
add this code:
//create the rendering context in (HGLRC m_hGLContext)
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
HDC hdc = ::GetDC(m_hWnd);
MySetPixelFormat(::GetDC(m_hWnd));
m_hGLContext = wglCreateContext(hdc) ;
add an OnDestroy Message to your derived CWnd Class
add this code:
//destroy the context
if(wglGetCurrentContext()!=NULL)
{
wglMakeCurrent(NULL, NULL) ;
}
if (m_hGLContext!=NULL)
{
wglDeleteContext(m_hGLContext);
m_hGLContext = NULL;
}
CWnd::OnDestroy();
(From here on this is confined to the OnPaint Message)
(simplicities sake)
2.) get the view...
note, I am using a static cast, that is so I can get at the views HGLRC variable. Also this window(from my app) is located in a tab page in a Dialog Bar, which isn't exactly accessable from the view.
CImagin8App* pApp = (CImagin8App*) AfxGetApp();
CImagin8View* pView;
CImagin8Doc* pDoc;
CMainFrame* pFrameWnd = static_cast<CMainFrame*> ( pApp->GetMainWnd());
if (pFrameWnd)
{
pDoc = static_cast<CImagin8Doc*>(pFrameWnd- >GetActiveDocument());
if (pDoc)
{
POSITION pos = pDoc- > GetFirstViewPosition();
pView = static_cast<CImagin8View*>(pDoc->GetNextView(pos));
}
}
//love these little comment boxes...
3.)HWND hWnd = pView->GetSafeHwnd();
HDC hDC = ::GetDC(hWnd);
if(wglGetCurrentContext()!=NULL)
{
wglMakeCurrent(NULL, NULL) ;
}
Temporarily realease the views rendering context
4.) Enable the Dialog context
HDC hdc = ::GetDC(m_hWnd);
//make current
wglMakeCurrent(hdc, m_hGLContext);
//glBegin and other GL stuff
5.)Disable the Dialog Context && enable the view context
if(wglGetCurrentContext()!=NULL)
{
wglMakeCurrent(NULL, NULL) ;
}
//reinstate the primary DC
wglMakeCurrent(hDC, pView->m_hGLContext) ;
and that just about covers it
Reply
Originally posted by: someice
I have found this material..
Thanks
Reply
Originally posted by: Wonjong Na
Good job..
ReplyOriginally posted by: Ramanan
it's very simple & good demonstration for any OpenGL programming. thanks
ramanan
Reply