Hey,
I’m trying to create two OpenGL windows and I couldn’t find any post with a related problem in this forum. Please give me a link if this question was answered earlier.
System: Windows XP, Visual Studio C++
Problem: I have created successfully one window with a triangle but now I want to create two windows and these are my first experiences with OpenGL.
I initialized for every window a seperate device context and a separate rendering context without an error message.
Result:
- Both windows are displayed (no compiling errors).
- The second window is working properly (drawings displayed).
- I can’t do any changes in the first window (e.g. background color) after wglMakeCurrent(first_win, first_win).
Please have a look at the code:
…
// first window
HWND g_hWnd = NULL;
HDC g_hDC = NULL;
HGLRC g_hRC = NULL;
// second window
HWND hWnd2;
HDC hDC2=NULL;
HGLRC hRC2=NULL;
…
// First Window
if(!(hWnd2 = CreateWindowEx (
WS_EX_APPWINDOW | WS_EX_WINDOWEDGE,
“glwin”,
“Randbegrenzung”,
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_POPUPWINDOW,
ScreenX-225,
0,
225,
225,
NULL,
NULL,
hInstance,
NULL)))
{
MessageBox(hWnd2,“Create Window”,“ERROR”,MB_OK);
return false;
}
int nPixelFormat;
PIXELFORMATDESCRIPTOR pfdPixelFormat2 =
{
…
};
if(!(hDC2 = GetDC(hWnd2)))
{
MessageBox(…); return FALSE;
}
// Everything with a separate error message, but i deleted
// the stuff for a better understanding.
nPixelFormat = ChoosePixelFormat(hDC2, &pfdPixelFormat2);
SetPixelFormat(hDC2, nPixelFormat, &pfdPixelFormat2);
hRC2 = wglCreateContext(hDC2);
wglMakeCurrent(hDC2, hRC2);
ShowWindow(hWnd2,SW_SHOW);
glShadeModel(GL_SMOOTH);
//!!!
// Problem: First Window is active but if I do some changes
// e.g. background glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
// nothing happen.
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
//!!!
// second window: is working properly, without any problems
if(!(g_hWnd = CreateWindowEx(
dwExStyle,
“glwin”,
“SR-2 OpenGL”,
dwStyle,
ScreenX-10-WindowRect.right-WindowRect.left,
ScreenY-70-WindowRect.bottom-WindowRect.top,
WindowRect.right-WindowRect.left,
WindowRect.bottom-WindowRect.top,
0,
NULL,
hInstance,
0)))
{MessageBox(…); return false;}
ShowWindow(g_hWnd,SW_SHOW);
int iPixelFormat;
PIXELFORMATDESCRIPTOR pfdPixelFormat =
{…};
// Device context…
g_hDC = GetDC(g_hWnd));
iPixelFormat = ChoosePixelFormat(g_hDC, &pfdPixelFormat;
SetPixelFormat(g_hDC, iPixelFormat, &pfdPixelFormat);
g_hRC = wglCreateContext(g_hDC);
wglMakeCurrent(g_hDC, g_hRC);
glShadeModel(GL_SMOOTH);
//!!!
// If I do here some changes (e.g. background color everything
// is fine.
glClearColor(.0f, .0f, 0.0f, 1.0f);
glEnable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_LINE_SMOOTH);
//!!!
Sorry for the huge source code.
Thank ýou.
Scalax