Results 1 to 6 of 6

Thread: OpenGL Child Windows?

  1. #1
    Member Contributor
    Join Date
    Dec 2001
    Location
    Raleigh, NC, USA
    Posts
    72

    OpenGL Child Windows?

    OK, I am working on a level editor for my OpenGL 3D game, but even though the child window is created, the level and textures are loaded, and OpenGL is initialized, it won't draw ANYTHING on the screen! What's up with that, can you not have a child window that is OpenGL? The program compiles with no errors and it runs fine (I have a logging function to lgo what it's doing), but the window won't show me ANYTHING. Any ideas?
    -Sephiroth

  2. #2
    Senior Member Regular Contributor
    Join Date
    Nov 2000
    Location
    Sydney, NSW, Australia
    Posts
    426

    Re: OpenGL Child Windows?

    Some code fragments would be good...
    :: Sleep is a poor substitute for caffeine ::

  3. #3
    Member Contributor
    Join Date
    Dec 2001
    Location
    Raleigh, NC, USA
    Posts
    72

    Re: OpenGL Child Windows?

    OK, here's the code I use to create my OpenGL child window. Right now the editor is just the game engine, but I create a normal window and then create this OpenGL window as it's child, as you see here.
    Code :
    BOOL CreateGLWindow(int bits)
    	{
    	static PIXELFORMATDESCRIPTOR pfd;
    	GLuint PixelFormat;
    	WNDCLASS wc;
     
    	glinst = minst;
    	wc.style = CS_OWNDC | CS_VREDRAW | CS_HREDRAW;
    	wc.lpfnWndProc = (WNDPROC)GLCalls;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = glinst;
    	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
    	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wc.hbrBackground = NULL;
    	wc.lpszMenuName = NULL;
    	wc.lpszClassName = VIEW_CLASS_NAME;
     
    	if(!RegisterClass(&wc))
    		{
    		MessageBox(NULL, "Failed To Register The Window Class!", "Startup Error", MB_OK | MB_ICONEXCLAMATION);
    		return FALSE;
    		}
     
    	if(!(glwnd = CreateWindowEx(WS_EX_CLIENTEDGE, VIEW_CLASS_NAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, mwnd, (HMENU)ID_VIEW, glinst, NULL)))
    		{
    		KillGLWindow();
    		MessageBox(NULL, "OpenGL window creation error.", "Error", MB_OK | MB_ICONEXCLAMATION);
    		addlog("Error: Couldn't create an OpenGL window!");
    		return FALSE;
    		}
     
    	pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    	pfd.nVersion = 1;
    	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
    	pfd.iPixelType = PFD_TYPE_RGBA;
    	pfd.cColorBits = bits;
    	pfd.cDepthBits = 32;
    	pfd.iLayerType = PFD_MAIN_PLANE;
     
    	if(!(gldc = GetDC(glwnd)))
    		{
    		KillGLWindow();
    		MessageBox(NULL, "Can't create a GL device context.", "Error", MB_OK | MB_ICONEXCLAMATION);
    		addlog("Error: Couldn't create a GL device context!");
    		return FALSE;
    		}
     
    	if(!(PixelFormat = ChoosePixelFormat(gldc, &pfd)))
    		{
    		KillGLWindow();
    		MessageBox(NULL, "Can't find a suitable pixel format.", "Error", MB_OK | MB_ICONEXCLAMATION);
    		addlog("Error: Couldn't find a suitable pixel format!");
    		return FALSE;
    		}
     
    	if(!SetPixelFormat(gldc, PixelFormat, &pfd))
    		{
    		KillGLWindow();
    		MessageBox(NULL, "Can't set the pixel format.", "OpenGL Error", MB_OK | MB_ICONEXCLAMATION);
    		addlog("Error: Couldn't set a pixel format!");
    		return FALSE;
    		}
     
    	if(!(hrc = wglCreateContext(gldc)))
    		{
    		KillGLWindow();
    		MessageBox(NULL, "Can't create a GL rendering context.", "OpenGL Error", MB_OK | MB_ICONEXCLAMATION);
    		addlog("Error: Couldn't create the GL rendering context!");
    		return FALSE;
    		}
     
    	if(!wglMakeCurrent(gldc, hrc))
    		{
    		KillGLWindow();
    		MessageBox(NULL, "Can't activate the GL rendering context.", "OpenGL Error", MB_OK | MB_ICONEXCLAMATION);
    		addlog("Error: Couldn't activate the GL rendering context!");
    		return FALSE;
    		}
     
    	ShowWindow(glwnd, SW_SHOW);
    	ResizeGLScene();
     
    	if(!InitGL())
    		{
    		KillGLWindow();
    		MessageBox(NULL, "Initialization failed.", "OpenGL Error", MB_OK | MB_ICONEXCLAMATION);
    		addlog("Error: Could not initialize OpenGL!");
    		return FALSE;
    		}
     
    	return TRUE;
    	}
    Like I said, everythign else is the same as in the game, which works, so i can't understand why the child window (takes up 1/4 of the parent) won't display anything.
    -Sephiroth

  4. #4
    Senior Member Regular Contributor
    Join Date
    Jan 2002
    Location
    Kingston, Jamaica, W.I.
    Posts
    282

    Re: OpenGL Child Windows?

    I recently tried the same thing and go the same result. It was suggested that I use wglMakeCurrent(...) to map the rendering context to the desired window before drawing. I haven't tred it yet though (I don't really know where to use it and haven't had time to research). I assume it would be used in the OnPaint function though.

  5. #5
    Junior Member Newbie
    Join Date
    Nov 2001
    Posts
    15

    Re: OpenGL Child Windows?

    HI,
    could it be in the CreateWindowEx function? I've heard that openGL requires WS_CLIPCHILDREN | WS_CLIPSIBLINGS in the third parameter.

    Code :
    	if (!(hWnd=CreateWindowEx(	dwExStyle,							// Extended Style For The Window
    								"OpenGL",							// Class Name
    								title,								// Window Title
    								dwStyle |							// Defined Window Style
    								WS_CLIPSIBLINGS |					// Required Window Style
    								WS_CLIPCHILDREN,					// Required Window Style
    								0, 0,								// Window Position
    								WindowRect.right-WindowRect.left,	// Calculate Window Width
    								WindowRect.bottom-WindowRect.top,	// Calculate Window Height
    								NULL,								// No Parent Window
    								NULL,								// No Menu
    								hInstance,							// Instance
    								NULL)))								// Dont Pass Anything To WM_CREATE
    bye,
    mathias_123

  6. #6
    Junior Member Newbie
    Join Date
    Nov 2001
    Posts
    15

    Re: OpenGL Child Windows?

    sorry, I meant in the 4th parameter.

Similar Threads

  1. Using OpenGL with Child Windows (Win32)
    By AcidInjury in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-05-2003, 08:09 AM
  2. win32, child windows, opengl
    By totoronet in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-05-2001, 10:59 AM
  3. child windows
    By lee in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 02-26-2001, 03:40 PM
  4. Multithreaded OpenGL in W32 child-windows
    By lasso in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 01-22-2001, 11:58 PM
  5. OpenGL in a Windows MDI Child Window Splitter pane
    By [SW]Falcon in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-09-2000, 05:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean