Esempio n. 1
0
//---------------------------------------------------------------------------
void __fastcall TOpenGL_Form::FormCreate(TObject *Sender)
{
    ghDC = GetDC(Handle);
    if (!bSetupPixelFormat(ghDC))
        Close();
    ghRC = wglCreateContext(ghDC);
    wglMakeCurrent(ghDC, ghRC);
    initializeGL(ClientRect.Right, ClientRect.Bottom);
}
/* main window procedure */ 
long APIENTRY
MainWndProc( HWND hWnd, UINT uMsg, WPARAM  wParam, LPARAM  lParam ) 
{ 
    
    LONG    lRet = 1; 
 
    switch (uMsg) {
 
    case WM_CREATE: 
	ghDC = GetDC(hWnd);

	if (!bSetupPixelFormat(ghDC))
    {
      printf( "bSetupPixelFormat( ) failed\n" );
	  PostQuitMessage (0); 
    }
	ghRC = wglCreateContext(ghDC);
	wglMakeCurrent(ghDC, ghRC); 
	break; 
 
    case WM_PAINT: 
	ValidateRect(hWnd,NULL);
	break; 
 
    case WM_SIZE: 
	break; 
 
    case WM_CLOSE: 
	if (ghRC) 
	    wglDeleteContext(ghRC); 
	if (ghDC) 
	    ReleaseDC(hWnd, ghDC); 
	ghRC = 0; 
	ghDC = 0; 
 
	DestroyWindow (hWnd); 
	break; 
 
    case WM_DESTROY: 
	if (ghRC) 
	    wglDeleteContext(ghRC); 
	if (ghDC) 
	    ReleaseDC(hWnd, ghDC); 
 
	PostQuitMessage (0); 
	break; 
     
    default: 
	lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); 
	break; 
    } 
 
    return lRet; 
} /* end long APIENTRY MainWndProc( ) */
int CCg3DTransView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	PIXELFORMATDESCRIPTOR pfd;
	int         n;
	HGLRC       hrc;
	GLfloat      fAspect;
	CCg3DTransDoc* pDoc = GetDocument();
	
	m_pDC = new CClientDC(this);
	ASSERT(m_pDC != NULL);
	
	if (!bSetupPixelFormat()) return 0;
	
	n = ::GetPixelFormat(m_pDC->GetSafeHdc());
	::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
	
	hrc = wglCreateContext(m_pDC->GetSafeHdc());
	wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
	
	glClearDepth(100.0f);
    glShadeModel(GL_FLAT);
    glEnable(GL_NORMALIZE);
	glDepthFunc(GL_LEQUAL);
	glEnable(GL_DEPTH_TEST);
    glEnable(GL_AUTO_NORMAL);
	GetClientRect(&m_viewRect);
	
	if (!m_viewRect.bottom)	fAspect = 1.0f;
	else                    fAspect = (GLfloat)m_viewRect.right/
		m_viewRect.bottom;
	
	GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 0.15 };
	GLfloat mat_shininess[] = { 100.0 };
	GLfloat position[] = { 0.5, 1.0, 2.0, 0.0 };
	
	glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
	glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
	glLightfv(GL_LIGHT0, GL_POSITION, position);
	
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0f, fAspect, 3.0f, 15.0f);
	glMatrixMode(GL_MODELVIEW);
	
	
// 	m_vecFont.CreateFont(m_pDC, "Arial Black");
 	m_axisFont.CreateFont(m_pDC, "Times New Roman"); //Arial Black
	
	return 0;
}
Esempio n. 4
0
//---------------------------------------------------------------------------
void __fastcall TOpenGL_Form::FormCreate(TObject *Sender)
{
        ghWnd = Handle;
        ghDC = GetDC(Handle);
        if (!bSetupPixelFormat(ghDC))
            Close();
        ghRC = wglCreateContext(ghDC);
        wglMakeCurrent(ghDC, ghRC);
        Application->OnIdle = MyIdleHandler;

}
void InitializeOpenGL(int width, int height) 
{  
    g_hDC = GetDC(g_hWnd);								// This sets our global HDC
														// We don't free this hdc until the end of our program
    if (!bSetupPixelFormat(g_hDC))						// This sets our pixel format/information
        PostQuitMessage (0);							// If there's an error, quit

    g_hRC = wglCreateContext(g_hDC);					// This creates a rendering context from our hdc
    wglMakeCurrent(g_hDC, g_hRC);						// This makes the rendering context we just created the one we want to use

	SizeOpenGLScreen(width, height);					// Setup the screen translations and viewport
}
Esempio n. 6
0
int openfile(const char *fname) {
  HDC hdc = hv->getWidget();
  bSetupPixelFormat(hdc);
  HGLRC ctx = wglCreateContext(hdc);
  if (!ctx) {
    printf("wglCreateContext Failed\n");
    exit(1);
  }
  hv->afterRealize(ctx, width, height);

  ifstream inFile(fname);
  if (!inFile) {
    return(0);
  }
  if (! (hv->setGraph(inFile))) exit(0);

  // hv->newLayout(NULL);

  hv->setGroupKey(0); // start out coloring by mime types
  hv->setColorGroup(0, "html", 0.0, 1.0, 1.0);
  hv->setColorGroup(0, "image", 1.0, 0.0, 1.0);
  hv->setColorGroup(0, "router", 0, 1, 1);
  hv->setColorGroup(0, "text", .90, .35, .05);
  hv->setColorGroup(0, "source", .42, 0, .48);
  hv->setColorGroup(0, "application", .99, .64, .25);
  hv->setColorGroup(0, "audio", .91, .36, .57);
  hv->setColorGroup(0, "video", .91, .36, .57);
  hv->setColorGroup(0, "other", 0, .35, .27);
  hv->setColorGroup(0, "vrml", .09, 0, 1);
  hv->setColorGroup(0, "host", 1.0, 1.0, 1.0);
  hv->setColorGroup(0, "invisible", 0, 0, 0);

  // tree position
  //  hv->setColorGroup(1, "host", 1.0, 1.0, 1.0);
  hv->setColorGroup(1, "main", 0, 1, 1);
  hv->setColorGroup(1, "orphan", 1.0, 0.0, 1.0);
  hv->setColorGroup(1, "external", 1.0, 1.0, 1.0);

  hv->setKeepAspect(1);

  //  hv->gotoCenterNode(HV_JUMP);
  struct timeval idletime;
  idletime.tv_sec = 5;
  idletime.tv_usec = 0;
  hv->setIdleFrameTime(idletime);
  gotfile = 1;
  return 1;
}
Esempio n. 7
0
void InitializeOpenGL(int width, int height)
{
    g_hDC = GetDC(g_hWnd);	
 
    if (!bSetupPixelFormat(g_hDC))		
        PostQuitMessage (0);			
 
    g_hRC = wglCreateContext(g_hDC);		
    wglMakeCurrent(g_hDC, g_hRC);		
    
 
	//glFrontFace(GL_CW);
	//glCullFace(GL_FRONT);
	//glDisable(GL_CULL_FACE);

    //SizeOpenGLScreen(width, height);
}
Esempio n. 8
0
void VidInit ()
{
	ghdc = GetDC(mainwindow);
	bSetupPixelFormat(ghdc);

	baseRC = wglCreateContext( ghdc );

	if (!baseRC)
		MessageBox(NULL, "Could not initialize GL", "ERROR", MB_OK);
	if (!wglMakeCurrent( ghdc, baseRC ))
		MessageBox(NULL, "wglMakeCurrent failed", "ERROR", MB_OK);

	VidInitFullScreen(ghInstance);
//	VidGoFullScreen(0);
	glMyInit();

}
void InitializeOpenGL(int width, int height) 
{  
    g_hDC = GetDC(g_hWnd);								// This sets our global HDC
														// We don't free this hdc until the end of our program
    if (!bSetupPixelFormat(g_hDC))						// This sets our pixel format/information
        PostQuitMessage (0);							// If there's an error, quit

    g_hRC = wglCreateContext(g_hDC);					// This creates a rendering context from our hdc
    wglMakeCurrent(g_hDC, g_hRC);						// This makes the rendering context we just created the one we want to use

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	// This allows us to use texture mapping, otherwise we just use colors.

	glEnable(GL_TEXTURE_2D);							// Enable Texture Mapping

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

	SizeOpenGLScreen(width, height);					// Setup the screen translations and viewport
}
Esempio n. 10
0
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
	RECT rt;

	switch (iMessage)
	{
	case WM_CREATE:
		g_hDC = GetDC(hWnd);
		if (!bSetupPixelFormat(g_hDC))
			PostQuitMessage(0);
		g_hRC = wglCreateContext(g_hDC);
		wglMakeCurrent(g_hDC, g_hRC);
		GetClientRect(hWnd, &rt);
		initializeGL();
		ViewControl.initializeCamera();
		break;

	case WM_PAINT:
	case WM_SIZE:
		GetClientRect(hWnd, &rt);
		ViewControl.SetWindowWidthHeight(rt.right, rt.bottom);
		resize(rt.right, rt.bottom);
		drawScene();
		break;

	case WM_DESTROY:
		if (g_hRC)
			wglDeleteContext(g_hRC);
		if (g_hDC)
			ReleaseDC(hWnd, g_hDC);
		PostQuitMessage(0);
		break;
	}

	MSG_RESULT msgResultMenu  = menuEventMessage(hWnd, iMessage, wParam, lParam);
	if (msgResultMenu == MSG_CHECKEND) return TRUE;
	MSG_RESULT msgResultMouse = mouseEventMessage(hWnd, iMessage, wParam, lParam);
	if (ViewControl.mouseEventControl() == MOUSE_EVT_UPDATE) drawScene();
	if (msgResultMouse == MSG_CHECKEND) return TRUE;
	return (LONG)DefWindowProc(hWnd, iMessage, wParam, lParam);
}
Esempio n. 11
0
void InitializeOpenGL(int width, int height) 
{  
    g_hDC = GetDC(g_hWnd);								// This sets our global HDC
														// We don't free this hdc until the end of our program
    if (!bSetupPixelFormat(g_hDC))						// This sets our pixel format/information
        PostQuitMessage (0);							// If there's an error, quit

    g_hRC = wglCreateContext(g_hDC);					// This creates a rendering context from our hdc
    wglMakeCurrent(g_hDC, g_hRC);						// This makes the rendering context we just created the one we want to use

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////
	
	// Since we have more than ONE primative (shape), we need to do some depth testing.
	// If we do NOT have this line, you will see through all the shapes when you go behind them.
	// Comment out this line and then go behind all the triangles.  It's a cool effect though :)

	glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

//////////// *** NEW *** ////////// *** NEW *** ///////////// *** NEW *** ////////////////////

	SizeOpenGLScreen(width, height);					// Setup the screen translations and viewport
}
Esempio n. 12
0
void VidInit ()
{
	ghdc = GetDC(ghWnd);
	bSetupPixelFormat(ghdc);

	ghrc = wglCreateContext( ghdc );

	if (!ghrc)
	{
		MessageBox(NULL, "Could not initialize GL", "ERROR", MB_OK);
		// quit
	}
	if (!wglMakeCurrent( ghdc, ghrc ))
	{
		MessageBox(NULL, "wglMakeCurrent failed", "ERROR", MB_OK);
		// quit
	}

	VidInitFullScreen(ghInstance);
	if (current_vidmode.fullscreen)
		VidGoFullScreen();
	glOmegaInit();
}
Esempio n. 13
0
/*
============
WMAIN_WndProc
============
*/
LONG WINAPI WMAIN_WndProc (
    HWND    hWnd,
    UINT    uMsg,
    WPARAM  wParam,
    LPARAM  lParam)
{
    LONG    lRet = 1;
    RECT	rect;
	HDC		maindc;

    GetClientRect(hWnd, &rect);

    switch (uMsg)
    {
	case WM_CREATE:
        maindc = GetDC(hWnd);
	    bSetupPixelFormat(maindc);
		break;
    case WM_COMMAND:
		lRet = CommandHandler (hWnd, wParam, lParam);
        break;

	case WM_CLOSE:
		if (!ConfirmModified())
			break;
        PostQuitMessage (0);
		break;
	default:
        /* pass all unhandled messages to DefWindowProc */
        lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
		break;
    }

    /* return 1 if handled message, 0 if not */
    return lRet;
}
Esempio n. 14
0
void InitializeOpenGL(int width, int height)
{
    g_hDC = GetDC(g_hWnd);								// This sets our global HDC
    // We don't free this hdc until the end of our program
    if (!bSetupPixelFormat(g_hDC))						// This sets our pixel format/information
        PostQuitMessage (0);							// If there's an error, quit

    g_hRC = wglCreateContext(g_hDC);					// This creates a rendering context from our hdc
    wglMakeCurrent(g_hDC, g_hRC);						// This makes the rendering context we just created the one we want to use

    glEnable(GL_DEPTH_TEST);							// Enables Depth Testing

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // It's a good idea to have the color of our background the same color as our darkness.
    // Since we are using white as our light color, we will set our background color to black.

    glClearColor(0, 0, 0, 1);							// Set our background color to black (0, 0, 0)

    // Below we create 2 arrays of color.  The first one, ambience[], is the default color
    // when there is no light shinning on the polygon.  If we didn't have an ambience, the
    // polygon's would be extremely dark so you couldn't see them.  Since we are using pure white
    // as our light color, we will set the ambience half of that, so it's not TOO dark when the light
    // isn't shinning on the surface of a polygon.  The second array, "diffuse", is the color
    // of the light that is shinning.  We chose pure white.  The first 3 are the R G B values.
    // (0, 0, 0) is pure black, where (1, 1, 1) is pure white. The last index is the alpha value.
    // Don't worry about that now.  For our ambience color we choose a dark grey light source.
    // For our diffuse color, we chose a half and half between full black light and full white.

    float ambience[4] = {0.3f, 0.3f, 0.3f, 1.0};		// The color of the light in the world
    float diffuse[4] = {0.5f, 0.5f, 0.5f, 1.0};			// The color of the positioned light

    // To set the ambience of our world, we need to give OpenGL our array of values.
    // OpenGL allows us to have multiple lights.  The number of lights is dependant on GL_MAX_LIGHTS.
    // We will use a OpenGL define for the first usable light, GL_LIGHT0.  After we specify a
    // light to use, we pass in the flag that tells OpenGL we are setting the ambience, followed
    // by our ambience array.  To set the diffuse color, we do the same thing but use GL_DIFFUSE
    // and our diffuse array.

    glLightfv( GL_LIGHT0, GL_AMBIENT,  ambience );		// Set our ambience values (Default color without direct light)
    glLightfv( GL_LIGHT0, GL_DIFFUSE,  diffuse );		// Set our diffuse color (The light color)

    // Next, we need to set the POSITION of our light.  We can have many lights at many positions.
    // In this tutorial, we will just do one light, but feel free to add more.  Use GL_LIGHT1 next.
    // We have our light position global so we can change it with the '+' and '-' keys.
    // Our default posiiton stored in g_LightPosition is (0, 1, 0, 1).  This should place our
    // light position directly above the middle pyramid.  The last value in the g_LightPosition array
    // tells OpenGL if we want our light position to be a DIRECTION or a POSITION.  If the
    // value is a 1, that means it is just a position, otherwise it's a direction from our camera.
    // If we have it a direction , it lights up everything in that direction (or vector) from
    // our eye, or in other words our camera.  If we say it's a position, it takes the values
    // as an X Y and Z position in the world.  Then it lights up everything around it.  That is
    // what we want, so we have a 1 to say that.  Once again, we pass in the light we are setting,
    // then GL_POSITION to let OpenGL we are setting the light position, the pass in our array
    // holding the position values.

    glLightfv( GL_LIGHT0, GL_POSITION, g_LightPosition );	// This Sets our light position

    // After we initialize a particular light, we need to turn it on.
    // We use the glEnable() function to do so, then pass in the light to turn on.

    glEnable(  GL_LIGHT0   );								// Turn this light on

    // That is enough though, we still need to allow lighting to take place.
    // Just because the light switch is on, doesn't mean we have power :)
    // This works just like fog, once you init everything, you need to allow it to be displayed.

    glEnable(  GL_LIGHTING );								// This turns on lighting

    // This next line allows us to use colors on our polygons during lighting.
    // If we did not have this line it would turn our pyramids white.

    glEnable(GL_COLOR_MATERIAL);							// Allow color to show during lighting

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    SizeOpenGLScreen(width, height);					// Setup the screen translations and viewport
}
void renderspu_SystemMakeCurrent( WindowInfo *window, GLint nativeWindow, ContextInfo *context )
{
    CRASSERT(render_spu.ws.wglMakeCurrent);

    if (context && window) {
        if (window->visual != context->visual) {
            /*
             * XXX have to revisit this issue!!!
             *
             * But for now we destroy the current window
             * and re-create it with the context's visual abilities
             */

            /*@todo Chromium has no correct code to remove window ids and associated info from 
             * various tables. This is hack which just hides the root case.
             */
            crDebug("Recreating window in renderspu_SystemMakeCurrent\n");
            renderspu_SystemDestroyWindow( window );
            renderspu_SystemVBoxCreateWindow( context->visual, window->visible, window );
        }

        if (render_spu.render_to_app_window && nativeWindow)
        {
            /* The render_to_app_window option 
             * is set and we've got a nativeWindow
             * handle, save the handle for 
             * later calls to swapbuffers().
             *
             * NOTE: This doesn't work, except 
             * for software driven Mesa.
             * We'd need to object link the 
             * crappfaker and crserver to be able to share
             * the HDC values between processes.. FIXME!
             */
            window->nativeWindow = (HDC) nativeWindow;
            if (context->hRC == 0) {
                context->hRC = render_spu.ws.wglCreateContext( window->nativeWindow );
                if (!context->hRC)
                {
                    crError( "(MakeCurrent) Couldn't create the context for the window (error 0x%x)", GetLastError() );
                }
            }
            render_spu.ws.wglMakeCurrent( window->nativeWindow, context->hRC );
        }
        else
        {
            if (!context->visual->device_context) {
                context->visual->device_context = GetDC( window->hWnd );

                crDebug( "Render SPU: MakeCurrent made the DC: 0x%x", context->visual->device_context );

                if ( !bSetupPixelFormat( context->visual->device_context, context->visual->visAttribs ) )
                {
                    crError( "Render SPU: (MakeCurrent) Couldn't set up the device context!  Yikes!" );
                }
            }

            if (!context->hRC) {
                context->hRC = render_spu.ws.wglCreateContext(context->visual->device_context);
                if (!context->hRC)
                {
                    crError( "Render SPU: (MakeCurrent) Couldn't create the context for the window (error 0x%x)", GetLastError() );
                }

                /*Requery ext function pointers, we skip dummy ctx as it should never be used with ext functions*/
                if (0 && context->id)
                {
                    int numFuncs, i;
                    SPUNamedFunctionTable ext_table[1000];


                    crDebug("Default server ctx created, requerying ext functions");
                    /*requery ext functions*/
                    numFuncs = renderspuCreateFunctions(ext_table);
                    numFuncs += crLoadOpenGLExtensions( &render_spu.ws, ext_table+numFuncs);
                    CRASSERT(numFuncs < 1000);

                    /*change spu dispatch*/
                    crSPUChangeDispatch(&render_spu.self, ext_table);


                    /*cleanup temp table*/
                    for (i=0; i<numFuncs; ++i)
                    {
                        if (ext_table[i].name) crFree(ext_table[i].name);
                    }
                }
            }

            /*crDebug("MakeCurrent 0x%x, 0x%x", window->device_context, context->hRC);*/
            if (!render_spu.ws.wglMakeCurrent(window->device_context, context->hRC))
            {
                DWORD err = GetLastError();
                crError("Render SPU: (MakeCurrent) failed to make 0x%x, 0x%x current with 0x%x error.", window->device_context, context->hRC, err);
            }
        }

        renderspuAtiQuirk_ChkApply();
    }
    else {
        render_spu.ws.wglMakeCurrent( 0, 0 );
    }
}
Esempio n. 16
0
/////////////////////////////////////////////////////////
// createGemWindow
//
/////////////////////////////////////////////////////////
GEM_EXTERN int createGemWindow(WindowInfo &info, WindowHints &hints)
{
  static int firstTime = 1;

  // Register the frame class
  HINSTANCE hInstance = GetModuleHandle(NULL);
  if (!hInstance)
    {
      error("GEM: Unable to get module instance");
      return(0);
    }
  if (firstTime)
    {
      WNDCLASS wndclass;
      wndclass.style         = 0;
      wndclass.lpfnWndProc   = (WNDPROC)MainWndProc;
      wndclass.cbClsExtra    = 0;
      wndclass.cbWndExtra    = 0;
      wndclass.hInstance     = hInstance;
      wndclass.hCursor       = LoadCursor(NULL, IDC_CROSS);
      wndclass.hIcon         = LoadIcon(NULL, IDI_WINLOGO);
      wndclass.hbrBackground = NULL;
      wndclass.lpszMenuName  = NULL;
      wndclass.lpszClassName = "GEM";

      if (!RegisterClass(&wndclass) )
        {
	  error("GEM: Unable to register window class");
	  return(0);
        }
      firstTime = 0;
    }

  DWORD dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
  DWORD style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;

  hints.real_w = hints.width;
  hints.real_h = hints.height;

  int x = hints.x_offset;
  int y = hints.y_offset;

  bool fullscreen=(hints.fullscreen!=0);
  if (fullscreen){
    DEVMODE dmScreenSettings;								// Device Mode

    if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmScreenSettings)){
      error("GEM: couldn't get screen capabilities!");
    }
    int w = dmScreenSettings.dmPelsWidth;
    int h = dmScreenSettings.dmPelsHeight;

    x=y=0;

    memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
    dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
    dmScreenSettings.dmPelsWidth	= hints.width;			// Selected Screen Width
    dmScreenSettings.dmPelsHeight	= hints.height;			// Selected Screen Height
    dmScreenSettings.dmBitsPerPel	= 32;					// Selected Bits Per Pixel
    dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
    // Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
    if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) {
      dmScreenSettings.dmPelsWidth	= w;
      dmScreenSettings.dmPelsHeight	= h;
      if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) {
	error("GEM: couldn't switch to fullscreen");
	fullscreen=false;
      } else {
	hints.real_h=h;
	hints.real_w=w;
      }
    }
  }
  if (fullscreen){
    dwExStyle  = WS_EX_APPWINDOW;
    style     |= WS_POPUP;
  } else {
    dwExStyle=WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
    if (hints.border)
      style |= WS_OVERLAPPEDWINDOW;
    else
      style |= WS_POPUP;
  }

  info.fs = fullscreen;//hints.fullscreen;

  // Since Windows uses some of the window for the border, etc,
  //		we have to ask how big the window should really be
  RECT newSize;
  newSize.left = x;
  newSize.top = y;
  newSize.right = hints.real_w+x;
  newSize.bottom = hints.real_h+y;

  AdjustWindowRectEx(&newSize, style, FALSE, dwExStyle); // no menu

  if (newSize.left<0 && x>=0){
	  newSize.right-=newSize.left;
	  newSize.left=0;
  }
  if (newSize.top<0 && y>=0){
	  newSize.bottom-=newSize.top;
	  newSize.top=0;
  }

  // Create the window
  info.win = CreateWindowEx (
			     dwExStyle,
			     "GEM",
			     hints.title,
			     style,
			     newSize.left,
			     newSize.top,
			     newSize.right - newSize.left,
			     newSize.bottom - newSize.top,
			     NULL,
			     NULL,
			     hInstance,
			     NULL);

  if (!info.win)  {
      error("GEM: Unable to create window");
      return(0);
    }

  // create the device context
  info.dc = GetDC(info.win);
  if (!info.dc)  {
      error("GEM: Unable to create device context");
      destroyGemWindow(info);
      return(0);
    }

  // set the pixel format for the window
  if (!bSetupPixelFormat(info.dc, hints))  {
      error("GEM: Unable to set window pixel format");
      destroyGemWindow(info);
      return(0);
    }

  // create the OpenGL context
  info.context = wglCreateContext(info.dc);
  if (!info.context)  {
      error("GEM: Unable to create OpenGL context");
      destroyGemWindow(info);
      return(0);
    }

  // do we share display lists?
  if (hints.shared) wglShareLists(hints.shared, info.context);

  // make the context the current rendering context
  if (!wglMakeCurrent(info.dc, info.context))   {
      error("GEM: Unable to make OpenGL context current");
      destroyGemWindow(info);
      return(0);
    }

  if (!hints.actuallyDisplay) return(1);

  // show and update main window
  if (fullscreen){
    ShowWindow(info.win,SW_SHOW);				// Show The Window
    SetForegroundWindow(info.win);				// Slightly Higher Priority
    SetFocus(info.win);
  } else  ShowWindow(info.win, SW_SHOWNORMAL);

  UpdateWindow(info.win);

  return(1);
}
Esempio n. 17
0
//---------------------------------------------------------------------------
void CFabAtHomeView::InitGL()
//---------------------------------------------------------------------------
{
    PIXELFORMATDESCRIPTOR pfd;
    int         n;
	GLfloat		fMaxObjSize, fAspect;
	GLfloat		fNearPlane, fFarPlane;
	
    m_pDC = new CClientDC(this);
	
    ASSERT(m_pDC != NULL);
	
    if (!bSetupPixelFormat())
        return;
	
    n = ::GetPixelFormat(m_pDC->GetSafeHdc());
    ::DescribePixelFormat(m_pDC->GetSafeHdc(), n, sizeof(pfd), &pfd);
	
    hrc = wglCreateContext(m_pDC->GetSafeHdc());
    wglMakeCurrent(m_pDC->GetSafeHdc(), hrc);
	
    GetClientRect(&m_oldRect);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
	
	if (m_oldRect.bottom)
		fAspect = (GLfloat)m_oldRect.right/m_oldRect.bottom;
	else	// don't divide by zero, not that we should ever run into that...
		fAspect = 1.0f;
	fNearPlane = 0.0f;
	fFarPlane = 100.0f;
	fMaxObjSize = 3.0f;
	m_fRadius = fNearPlane + fMaxObjSize / 2.0f;

	//initialize the panning/zooming cursor start point.
	startPoint = m_oldRect.CenterPoint();
	
	// initialize rolling matrix with unity
	
	glPushMatrix();
    glLoadIdentity();
	glRotated(-90,0,0,1);
	glRotated(-60,0,1,0);
	glScaled(scale, scale, scale);
	glGetDoublev(GL_MODELVIEW_MATRIX, rotmat);
	glPopMatrix();

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
	SetViewTransformation();
    glMatrixMode(GL_MODELVIEW);

//  Load character Set
//  BOOL CreateFont( int nHeight, int nWidth, int nEscapement, int nOrientation, 
//		int nWeight, BYTE bItalic, BYTE bUnderline, BYTE cStrikeOut, BYTE nCharSet, 
//		BYTE nOutPrecision, BYTE nClipPrecision, BYTE nQuality,
//		BYTE nPitchAndFamily, LPCTSTR lpszFacename );
	CFont times;
	times.CreateFont(0,0,0,0,
		FW_NORMAL,FALSE,FALSE,0,DEFAULT_CHARSET,
		OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,
		DEFAULT_PITCH,"Times New Roman");
//	m_pDC->SelectObject(GetStockObject(SYSTEM_FONT)); 
	m_pDC->SelectObject(&times); 
	// create the bitmap display lists 
	// we're making images of glyphs 0 thru 255 
	// the display list numbering starts at 1000, an arbitrary choice 
	wglUseFontBitmaps(m_pDC->GetSafeHdc(), 0, 255, 1000); 
	// display a string: 
	// indicate start of glyph display lists 
	 glListBase(1000); 
	// to draw the characters in a string, do, for example:
//	 glCallLists(24, GL_UNSIGNED_BYTE, "Hello Win32 OpenGL World"); 

}
Esempio n. 18
0
long FAR PASCAL WindowProc(HWND hWnd, UINT message, 
						   WPARAM wParam, LPARAM lParam)
{
	PAINTSTRUCT ps;
	RECT rect; 
 
	switch(message)
	{
	case WM_CREATE: 
		ghDC = GetDC(hWnd); 
		if (!bSetupPixelFormat(ghDC)) 
			PostQuitMessage (0); 
 
		ghRC = wglCreateContext(ghDC); 
		if (!ghRC)
		{
			MessageBox(NULL, "Could not initialize GL", "ERROR", MB_OK);
			PostQuitMessage (0); 
		}
		if (!wglMakeCurrent(ghDC, ghRC))
		{
			MessageBox(NULL, "wglMakeCurrent failed", "ERROR", MB_OK);
			PostQuitMessage (0); 
		}
		GetClientRect(hWnd, &rect); 
		initializeGL(rect.right, rect.bottom); 
		// Other Initialisation should go here
		initText();
		TimeInit();
		TerrainInit("hmap.raw");

		break; 
	case WM_PAINT:
		ghDC = BeginPaint(hWnd, &ps);
		EndPaint(hWnd, &ps);
		return TRUE;

	case WM_SIZE: 
		GetClientRect(hWnd, &rect); 
		resize(rect.right, rect.bottom); 
		break; 

	case WM_CLOSE: 
		if (ghRC) 
			wglDeleteContext(ghRC); 
		if (ghDC) 
			ReleaseDC(hWnd, ghDC); 
		ghRC = 0; 
		ghDC = 0; 
		DestroyWindow (hWnd); 
		break; 
 
	case WM_DESTROY: 
		if (ghRC) 
			wglDeleteContext(ghRC); 
		if (ghDC) 
			ReleaseDC(hWnd, ghDC); 
		PostQuitMessage (0); 
		break; 

	case WM_KEYDOWN: 
		KeyDown(wParam);
		break;
	}
	return DefWindowProc(hWnd, message, wParam, lParam);

}
Esempio n. 19
0
GLboolean renderspu_SystemVBoxCreateWindow( VisualInfo *visual, GLboolean showIt, WindowInfo *window )
{
#if 0
    HDESK     desktop;
#endif
    HINSTANCE hinstance;
    WNDCLASS  wc;
    DWORD     window_style;
    int       window_plus_caption_width;
    int       window_plus_caption_height;

    window->visual = visual;
    window->nativeWindow = 0;

    if ( render_spu.use_L2 )
    {
        crWarning( "Going fullscreen because we think we're using Lightning-2." );
        render_spu.fullscreen = 1;
    }

    /*
     * Begin Windows / WGL code
     */

    hinstance = GetModuleHandle( NULL );
    if (!hinstance)
    {
        crError( "Render SPU: Couldn't get a handle to my module." );
        return GL_FALSE;
    }
    crDebug( "Render SPU: Got the module handle: 0x%x", hinstance );

#if 0
    /* If we were launched from a service, telnet, or rsh, we need to
     * get the input desktop.  */

    desktop = OpenInputDesktop( 0, FALSE,
            DESKTOP_CREATEMENU | DESKTOP_CREATEWINDOW |
            DESKTOP_ENUMERATE | DESKTOP_HOOKCONTROL |
            DESKTOP_WRITEOBJECTS | DESKTOP_READOBJECTS |
            DESKTOP_SWITCHDESKTOP | GENERIC_WRITE );

    if ( !desktop )
    {
        crError( "Render SPU: Couldn't acquire input desktop" );
        return GL_FALSE;
    }
    crDebug( "Render SPU: Got the desktop: 0x%x", desktop );

    if ( !SetThreadDesktop( desktop ) )
    {
        /* If this function fails, it's probably because 
         * it's already been called (i.e., the render SPU 
         * is bolted to an application?) */

        /*crError( "Couldn't set thread to input desktop" ); */
    }
    crDebug( "Render SPU: Set the thread desktop -- this might have failed." );
#endif

    if ( !GetClassInfo(hinstance, WINDOW_NAME, &wc) ) 
    {
        wc.style = CS_OWNDC; // | CS_PARENTDC;
        wc.lpfnWndProc = (WNDPROC) MainWndProc;
        wc.cbClsExtra = 0;
        wc.cbWndExtra = 0;
        wc.hInstance = hinstance;
        wc.hIcon = NULL; //LoadIcon( NULL, IDI_APPLICATION );
        wc.hCursor = NULL; //LoadCursor( NULL, IDC_ARROW );
        wc.hbrBackground = NULL;
        wc.lpszMenuName = NULL;
        wc.lpszClassName = WINDOW_NAME;                       

        if ( !RegisterClass( &wc ) )
        {
            crError( "Render SPU: Couldn't register window class -- you're not trying "
                    "to do multi-pipe stuff on windows, are you?\n\nNote --"
                    "This error message is from 1997 and probably doesn't make"
                    "any sense any more, but it's nostalgic for Humper." );
            return GL_FALSE;
        }
        crDebug( "Render SPU: Registered the class" );
    }
    crDebug( "Render SPU: Got the class information" );

    /* Full screen window should be a popup (undecorated) window */
#if 1
    window_style = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_DISABLED;
    if (render_spu_parent_window_id)
    {
        window_style |= WS_CHILD;
    }
#else
    window_style = ( WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS | WS_CLIPCHILDREN );
    window_style |= WS_SYSMENU;
#endif

    crDebug( "Render SPU: Fullscreen: %s", render_spu.fullscreen ? "yes" : "no");

    if ( render_spu.fullscreen )
    {
#if 0

        int smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
        int smCyFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME ) + 1;
        int smCyCaption = GetSystemMetrics( SM_CYCAPTION );

        window->width = GetSystemMetrics( SM_CXSCREEN ) ;
        window->height = GetSystemMetrics( SM_CYSCREEN ) ;

        crDebug( "Render SPU: Window Dims: %d, %d", window->width, window->height );

        window->x = render_spu->defaultX - smCxFixedFrame - 1;
        window->y = render_spu->defaultY - smCyFixedFrame - smCyCaption;

        window_plus_caption_width = window->width + 2 * smCxFixedFrame;
        window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;

#else
        /* Since it's undecorated, we don't have to do anything fancy
         * with these parameters. */

        window->width = GetSystemMetrics( SM_CXSCREEN ) ;
        window->height = GetSystemMetrics( SM_CYSCREEN ) ;
        window->x = 0;
        window->y = 0;
        window_plus_caption_width = window->width;
        window_plus_caption_height = window->height;

#endif
    }
    else
    {
        /* CreateWindow takes the size of the entire window, so we add
         * in the size necessary for the frame and the caption. */
        int smCxFixedFrame, smCyFixedFrame, smCyCaption;
        smCxFixedFrame = GetSystemMetrics( SM_CXFIXEDFRAME );
        crDebug( "Render SPU: Got the X fixed frame" );
        smCyFixedFrame = GetSystemMetrics( SM_CYFIXEDFRAME );
        crDebug( "Render SPU: Got the Y fixed frame" );
        smCyCaption = GetSystemMetrics( SM_CYCAPTION );
        crDebug( "Render SPU: Got the Caption " );

        window_plus_caption_width = window->width + 2 * smCxFixedFrame;
        window_plus_caption_height = window->height + 2 * smCyFixedFrame + smCyCaption;

        window->x = render_spu.defaultX;
        window->y = render_spu.defaultY;
    }

    crDebug( "Render SPU: Creating the window: (%d,%d), (%d,%d)", render_spu.defaultX, render_spu.defaultY, window_plus_caption_width, window_plus_caption_height );
    /*window->hWnd = CreateWindowEx( WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY,
            WINDOW_NAME, WINDOW_NAME,
            window_style,
            window->x, window->y,
            window->width,
            window->height,
            (void*) render_spu_parent_window_id, NULL, hinstance, &render_spu );*/
    {
        CREATESTRUCT cs;

        cs.lpCreateParams = &window->hWnd;

        cs.dwExStyle    = WS_EX_NOACTIVATE | WS_EX_NOPARENTNOTIFY;
        cs.lpszName     = WINDOW_NAME;
        cs.lpszClass    = WINDOW_NAME;
        cs.style        = window_style;
        cs.x            = window->x;
        cs.y            = window->y;
        cs.cx           = window->width;
        cs.cy           = window->height;
        cs.hwndParent   = (void*) render_spu_parent_window_id;
        cs.hMenu        = NULL;
        cs.hInstance    = hinstance;

        if (render_spu.dwWinThreadId)
        {
            DWORD res;
            int cnt=0;

            if (!PostThreadMessage(render_spu.dwWinThreadId, WM_VBOX_RENDERSPU_CREATE_WINDOW, 0, (LPARAM) &cs))
            {
                crError("Render SPU: PostThreadMessage failed with %i", GetLastError());
                return GL_FALSE;
            }

            do
            {
                res = WaitForSingleObject(render_spu.hWinThreadReadyEvent, 1000);
                cnt++;
            }
            while ((res!=WAIT_OBJECT_0) && (cnt<10));

            crDebug("Render SPU: window thread waited %i secs", cnt);

            if (res!=WAIT_OBJECT_0)
            {
                crError("Render SPU: window thread not responded after %i tries", cnt);
                return GL_FALSE;
            }
        }
        else
        {
            crError("Render SPU: window thread is not running");
            return GL_FALSE;
        }
    }

    if ( !window->hWnd )
    {
        crError( "Render SPU: Create Window failed!  That's almost certainly terrible." );
        return GL_FALSE;
    }

    if (showIt) {
        /* NO ERROR CODE FOR SHOWWINDOW */
        crDebug( "Render SPU: Showing the window" );
        crDebug("renderspu_SystemVBoxCreateWindow: showwindow: %x", window->hWnd);
        ShowWindow( window->hWnd, SW_SHOWNORMAL );
    }

    //SetForegroundWindow( visual->hWnd );

    SetWindowPos( window->hWnd, HWND_TOP, window->x, window->y,
                  window->width, window->height,
                  ( render_spu.fullscreen ? 
                    (SWP_SHOWWINDOW | SWP_NOSENDCHANGING | SWP_NOREDRAW | SWP_NOACTIVATE ) : SWP_NOACTIVATE 
                  ) );
    crDebug("Render SPU: SetWindowPos (%x, %d, %d, %d, %d)", window->hWnd, 
            window->x, window->y, window->width, window->height);

    if ( render_spu.fullscreen )
        ShowCursor( FALSE );

    window->device_context = GetDC( window->hWnd );

    crDebug( "Render SPU: Got the DC: 0x%x", window->device_context );

    if ( !bSetupPixelFormat( window->device_context, visual->visAttribs ) )
    {
        crError( "Render SPU: Couldn't set up the device context!  Yikes!" );
        return GL_FALSE;
    }

    return GL_TRUE;
}
Esempio n. 20
0
  void create(HINSTANCE hInstance, int buffer, bool fullscreen, bool border, std::string title, int &x, int &y, unsigned int &w, unsigned int &h) {
    DWORD dwExStyle;
    DWORD style;

    if (fullscreen){
        DEVMODE dmScreenSettings;								// Device Mode

        if (!EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &dmScreenSettings)){
            ::error("GEM: couldn't get screen capabilities!");
        } else {
        w = dmScreenSettings.dmPelsWidth;
        h = dmScreenSettings.dmPelsHeight;
        }

        x=y=0;

        memset(&dmScreenSettings,0,sizeof(dmScreenSettings));	// Makes Sure Memory's Cleared
        dmScreenSettings.dmSize=sizeof(dmScreenSettings);		// Size Of The Devmode Structure
        dmScreenSettings.dmPelsWidth	= w;			// Selected Screen Width
        dmScreenSettings.dmPelsHeight	= h;			// Selected Screen Height
        dmScreenSettings.dmBitsPerPel	= 32;					// Selected Bits Per Pixel
        dmScreenSettings.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
        // Try To Set Selected Mode And Get Results.  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
        if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) {
          dmScreenSettings.dmPelsWidth	= w;
          dmScreenSettings.dmPelsHeight	= h;
          if (ChangeDisplaySettings(&dmScreenSettings,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) {
              ::error("couldn't switch to fullscreen");
            fullscreen=false;
          }
        }
      }

      // Since Windows uses some of the window for the border, etc,
      //		we have to ask how big the window should really be
      RECT newSize = getRealRect(x, y, w, h,
                          border, fullscreen,
                          style, dwExStyle);
      // Create the window
      win = CreateWindowEx (
                            dwExStyle,
                            "GEM",
                            title.c_str(),
                            style,
                            newSize.left,
                            newSize.top,
                            newSize.right - newSize.left,
                            newSize.bottom - newSize.top,
                            NULL,
                            NULL,
                            hInstance,
                            NULL);
      if (!win)  {
        throw(GemException("Unable to create window"));
      }
      // create the device context
      dc = GetDC(win);
      if (!dc)  {
        throw(GemException("GEM: Unable to create device context"));
      }

      // set the pixel format for the window
      if (!bSetupPixelFormat(dc, buffer))  {
        throw(GemException("Unable to set window pixel format"));
      }

      // create the OpenGL context
      context = wglCreateContext(dc);
      if (!context)  {
        throw(GemException("Unable to create OpenGL context"));
      }

      // do we share display lists?
      if (sharedContext) wglShareLists(sharedContext, context);

      // make the context the current rendering context
      if (!wglMakeCurrent(dc, context))   {
        throw(GemException("Unable to make OpenGL context current"));
      }
    }