Advertisement

Multiple Windows

Started by May 19, 2003 11:26 PM
4 comments, last by bennig 21 years, 9 months ago
Using the creating windows tute (Lesson1)...how would you create multiple windows? I''ve tried calling CreateGLWindow() again but that results in a "failed to register window class" runtime error. Thanks,
Why don''t use the last NeHe''s tut ?

I can set up multiple viewport in one window.

Perhaps it''s enough for you ?

========================
Leyder Dylan (dylan.leyder@slug-production.be.tf
http://www.slug-production.be.tf/
========================Leyder Dylan (dylan.leyder@slug-production.be.tf http://users.skynet.be/fa550206/Slug-Production/Index.htm/
Advertisement
Hi - you only need to register your class once - so use some boolean logic to stop multiple calls. eg:
bool first = true;if (first)   {   ... register class ...   first = false;   }






[edited by - chookmaster on May 20, 2003 5:36:16 AM]
Does anyone know how to do the above without using windows.h?
Creating windows without windows.h would mean using Glut! But if you want to use the win32 api and create multiple windows...just register another window class, create the "child" window with the "parent" being the main window... You may also want to look up some stuff on MDI applications. This is the basic setup I'm using for my "work in progress" model editor.
example...
HWND hWndParent, hWndChild
Create different classes for each...register them, then when you actually create the window make the hWndChild window's parent hWndParent. hWndParents parent is NULL. You probably will need to mess with WM_RESIZE for the child's winproc so it fits how you want it in the parent. Get Petzold's Window Programming. It really helps out in doing stuff like this.

Oh yeah...if you're using OpenGL in each window, create a DC and RC for each child or use glScissors to divide up the window into different sectors... I think NeHe's last tutorial illustrates how to do this.

http://lanceusa.com



[edited by - dnagcat on May 20, 2003 12:16:25 PM]
If you are looking to do some non-trivial multiple-window app, then I would suggest not using raw windows, unless you are a big fan of cut-and-paste.

I can recommend the free-ware object-oriented (cross-platform if that interests you) app builder "wxWindows": http://www.wxwindows.org

Here is some (pseudo-ish) code for building an MDI child frame and installing your gl view, with a paint callback. Note, no "RegisterClass" in sight ! You can create as many of these as you like. Also note, because it is O-O you save heaps of confusion.

Also, you would generally have some "controlling" code elsewhere to seup menus etc.

At the (big) risk of repeating myself, I would suggest do not write a 3d editor in raw windows - use some OO framework.

class myOpenGL : public wxGLCanvas   {   public:      myOpenGL(wxWindow *parent,Object *o) : wxGLCanvas(parent,-1), object(o)         {         // some view-specific stuff ...         prev_x = prev_y = 0;         trackball( orientation, 0.0, 0.0, 0.0, 0.0 );         centre[0] = centre[1] = centre[2] = 0.0;         scale = 1.0;         aspect = 1.0;         }      ...      void OnPaint(wxPaintEvent &ev)         {         wxPaintDC dc(this);         SetCurrent();         if (!GetContext()) return;         glMatrix/glVertex calls go here ...         }      ...    };class myView: public wxMDIChildFrame   {   public:      myView(wxMDIParentFrame *frame,const wxString &title)        : wxMDIChildFrame(frame,-1,title,            wxDefaultPosition, wxDefaultSize, wxCLIP_CHILDREN)        {        ...        // object is some 3d data thing        canvas = new myOpenGL(this,object);        ...        }      ...    };

This topic is closed to new replies.

Advertisement