Advertisement

OpenGL in child wnd (based on Lesson 5). Important, help!

Started by January 29, 2001 05:22 PM
6 comments, last by DaEvOsH 23 years, 9 months ago
Well, this is the story. I am doing a large project as my thesis work and a 3D view is not required of me but would be a very cool thing to do. The app is used to control a robot's movement graphically from the PC, done in Win32 API (no MFC). I am trying to make a child window display the rotating cube from NeHe's tutorial 5, but I haven't been able to do so. I cannot get DrawGLScene() in WinMain. I need to display the OpenGL window in a child window contained in a window opened from a dialog that is called from winmain. I register the class for the window when the program initializes like this:

  wndclass.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
  wndclass.lpfnWndProc   = (WNDPROC) TrayViewPortGLProc;	
  wndclass.cbClsExtra    = 0;
  wndclass.cbWndExtra    = 0; 
  wndclass.hInstance     = g_hInst;
  wndclass.hIcon         = NULL;	
  wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW); 
  wndclass.hbrBackground = NULL;
  wndclass.lpszMenuName	 = NULL;	  
  wndclass.lpszClassName = "TrayViewPortGL";	

  if (!RegisterClass (&wndclass))
  {
    MessageBox (NULL, "foo", "RectWndProc", MB_ICONERROR);
    return 0 ;
  }
   
Then, when the window is opened in WM_CREATE I call:


if(!(g_hwndVPGL=CreateWindow("TrayViewPortGL", NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 0, 0, hwnd, NULL, g_hInst, NULL)))
{
  MessageBox(NULL,"g_hwndVPGL.","ERROR", MB_OK | MB_ICONEXCLAMATION );
}
   
And inmediatly I resize it to the size I need it to be (not 0). Now, in a separate project file I include the win proc for this child window and the GL helper functions, modified so they dont include fullscreen (I dont need that) and I call DrawGLScene() from WM_PAINT in the child window. Since it is a little large and here it would get messed up, the source is at this url: http://venturello.com/files/TrayViewPortGL.cpp As I compile the app, there is no error reported, and I notice a slowdown as some heavy processing is being done, but I dont see any results on screen. I am just beggining on opengl. As you can see my understanding is very basic, I have no idea how to apply it to this specific situacion - I just di what I could to make Tutorial 5 work in my situation - which it did not. I only need to display very basic objects (lines, simple curves, simple solids, no textures, basic rotation, no lightning) but I dont want to do all the 3D projections myself (know how the math work, but openGL looks nicer). Nothing fancy, but I need it to be efficient and not hug down the computer. No movement save under user command to rotate the viewport. Thanks for any help you can give, I knwo this is a long question. I will be looking at the post to see if there is any specific question. Again, thanks beforehand for any help. Juan Miguel Venturello Edited by - DaEvOsH on January 29, 2001 6:34:42 PM Edited by - DaEvOsH on January 29, 2001 7:31:00 PM Edited by - DaEvOsH on January 29, 2001 7:36:25 PM
If you could post the rest of your program, that would be really helpful. It could be a simple problem in your WinMain function.

Thanks
Shawn

PS - I bookmarked this so if you reply and post it, I will see if I can help ya out.
Advertisement
Spanky, posting the whole program would be impossible, since it is more or less 550K of source code (text) + resources. I posted what I think is sufficient - WinMain, as I said, calls a dialog, from there the user can choose many options, one amongst them the ''trajectory manager'' where the OpenGL child window is to reside.

Hope this helps
Anyone? Pretty pleeeeeeeease???
This is just a guess, but I don''t see a break or return 0 after your WM_CREATE case. Your code looks like it might be going into WM_ACTIVATE and might be setting active to FALSE. I also never
see where you set active to TRUE. I would expect that in WM_CREATE or I might just be missing it.
That IS a bug, but not the reason. 10 minutes ago I go it. In WM_PAINT I do a DrawGLScene but I did not SwapBuffers. That fixed all. Also had to add a Sleep call to it.

Got help on irc #opengl @ undernet from a user named this-
Advertisement
I had no problems making an OpenGL window a child of another window (although 4 got a little complicated). Your resizing thing does look wrong to me, ie, it looks like it''s resizing as for the entire window, not taking into account that the child window is not the same size as what you are resizing to.

And what is the handle for the child window and the parent window? I just see hwnd, that isn''t spicific, and it''s only one.

Can I see you winmain function, or what ever function you use to create the windows?

Make sure that the child window is a child, and that it is a child of what ever window you want it on, that both windows are visible, and that you get the device context and rendering context of the child window for rendering.

I don''t think that you will get the resizing of the child window in the call back function, and if you do, you didn''t check which window it was anyway.

Perhaps the way I did my project was wrong. Basically what I did was make a child window, set it''s parent window to my main window, gave it''s windows class the came as the parent, got the device context of the child window, set the pixel format, made a rendering context, used the wglmakecurrent on the device context and rendering context, used glviewport with the childs size (said it was at 0,0), ran my program, rendered stuff, swapped buffers, and at the end free the stuff for the window, set wglmakecurrent to null, and exit. (I kind of gave up on the create/destroy/resize window stuff.)

If you do need to resize the window, move it, resize it, and call glviewport again.

If your trying to do this without a child window, I recommend that you not.

I''m not an expert with windows, but that''s how I did it, and it worked for me.

Did you ever notice how people who don''t know what their talking about say the most (refering to me)?




My software never has bugs. It just develops random features.

I forgot to put in my user name and password, yet my quote still appeared. Should I be worried?


My software never has bugs. It just develops random features.

Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.

This topic is closed to new replies.

Advertisement