f



Porting from Win32 OpenGL code to non-Win32 OpenGL code

Hi,

I've come across a pile of OpenGL tutorials which seem to be based in
the Win32 arena and while 99% of the code will hold true for any
platform, I'm at a loss of how to remove the likes of the following

HDC             hDC=NULL;               
HGLRC           hRC=NULL;               
HWND            hWnd=NULL;              
HINSTANCE       hInstance;

LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg,WPARAM wParam,LPARAM
lParam)         
{
  switch (uMsg)                                                         
  {
    case WM_ACTIVATE:                                           
    {
      active = !HIWORD(wParam) ? true : false;
      return 0;                                                 
    }

    case WM_SYSCOMMAND:                                         
    {
      switch (wParam)                                           
      {
        case SC_SCREENSAVE:                             
        case SC_MONITORPOWER:                   
        return 0;                                               
      }
      break;                                                            
     }

     case WM_SIZE:                                                      
     {
       ReSizeGLScene(LOWORD(lParam),HIWORD(lParam)); 
       return 0;                                                        
     }
   }
  return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
lpCmdLine, int nCmdShow)                
{
  MSG msg;
  bool done=FALSE;                                                      
  yspeed=40.0f;
  ci=0.0f;
  ci1=10.0f;
  tato=0;
  if (!CreateGLWindow("Blending Tutorial",800,600,32,fullscreen))
   return 0;
  HideTaskbar();
  while(!done)
  {
    if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))   
    {
      if (msg.message==WM_QUIT)                 
      {
        done=TRUE;                                              
      }
      else                                                              
      {
         TranslateMessage(&msg);                        
         DispatchMessage(&msg);                 
      }
    }
    else
    {
      if ((active && !DrawGLScene()) || keys[VK_ESCAPE])        
      {
         done=TRUE;                                             
      }
      else                                                              
      {
        SwapBuffers(hDC);// if vsync is enabled it waits here for
refresh the monitor
        fps=(1 / cas.GetTime());
        polsekundy += cas.GetTime();
        if (polsekundy>=0.5f)
        {
          fpsms=fps;
          polsekundy=0.0f;
        }
     }  
  }  
  ShowTaskbar();
  KillFont();
  KillGLWindow();
  return (msg.wParam);                                          
}

Is it safe for me to just omit all of the windows messaging and window
handle material or is there something else I need to do? I haven't
really the first clue as to how Windows does it's messaging and window
handling.

TTFN

Paul
-- 
"A lot of football success is in the mind. You must believe you are the
best and then make sure that you are. In my time at Liverpool we always
said we had the best two teams on Merseyside, Liverpool and Liverpool
Reserves." - Bill Shankly

0
paul84 (611)
8/20/2005 1:57:51 PM
comp.graphics.api.opengl 7074 articles. 1 followers. Post Follow

2 Replies
540 Views

Similar Articles

[PageSpeed] 12

Hi,

want you are asking is how to abstract the platform-dependent portions
of OpenGL away.  There's plenty of little toolkits which do this with
varying degrees of "invasiveness".  Take for example GLUT, which takes
control over the event loop and is callback centered.  On the other
hand you have SDL, which lets you control exactly how you want to deal
with events and doesn't actually have any sort of hooks.  Between the
two, I like the later better, because I can build my own on top of that
with greater ease.

I can recommend looking thru the NeHe tutorials, which have plently of
code ported to different systems and will let you get the hang of it
rather easily.  http://nehe.gamedev.net/lesson.asp?index=01

Cheers,

Marcelo

0
marcelo
8/20/2005 4:57:17 PM
On Sat, 20 Aug 2005 13:57:51 GMT, "Paul F. Johnson"
<paul@all-the-johnsons.co.uk> wrote:

>Hi,
>
>I've come across a pile of OpenGL tutorials which seem to be based in
>the Win32 arena and while 99% of the code will hold true for any
>platform, I'm at a loss of how to remove the likes of the following
>
>  ..... Piece of code
>

Some of the functions in your piece of code, like 'CreateGLWindow',
'KillGLWindow', 'ReSizeGLScene' and (I think) 'KillFont' are not win32
library functions. There's probably also a Redraw function hidden
somewheres. You need to find the sources for these functions and
figure out how to make them functional for your platform of choice,
perhaps through callbacks. Also, generally, you should look around for
any functions that start with 'wgl'-- these are the functions that
create, relate, and manage rendering contexts in win32 & whose
functionality will need to be replaced.

Another issue is getting extensions to work. You need to look for
places where likely-looking function pointers are being fetched.

Matt Feinstein

--
There is no virtue in believing something that can be proved to be true.
0
Matt
8/22/2005 3:12:13 PM
Reply: