Example #1
0
/* This name doesn't really cover this function, since it also sets up mouse
   and keyboard. This is done over here, since on most display targets the
   mouse and keyboard can't be setup before the display has. */
int xgl_open_display(int reopen)
{
  if(!reopen)
  {
    XWindowAttributes window_attributes;
    VisualGC vgc;
    
    fprintf(stderr, xgl_version_str);

    /* create a window */
    if (x11_create_window(&window_width, &window_height,
        cabview?X11_RESIZABLE:X11_RESIZABLE_ASPECT))
      return 1;
    
    /* Use the window's visual for the OpenGL context. */
    if (XGetWindowAttributes(display, window, &window_attributes) != 0)
       glCaps.nativeVisualID = window_attributes.visual->visualid;

    vgc = findVisualGlX( display, RootWindowOfScreen (screen),
                       &window, 0, 0, window_width, window_height, &glCaps, 
  		       NULL, NULL, 0, NULL, 0, NULL, 
#ifdef GLDEBUG
  		       1);
#else
  		       0);
#endif

    if(vgc.success==0)
    {
  	fprintf(stderr,"OSD ERROR: failed to obtain visual.\n");
  	return 1; 
    }

    glContext=vgc.gc;

    if(!glContext) {
  	fprintf(stderr,"OSD ERROR: failed to create OpenGL context.\n");
  	return 1; 
    }
    
    setGLCapabilities ( display, vgc.visual, &glCaps);
    
    xinput_open(0, 0);
  }
Example #2
0
void LIBAPIENTRY SetDCPixelFormat(HDC hDC, GLCapabilities *glCaps,
		                  int offScreenRenderer, int verbose)
{
    int nPixelFormat=-1;
	const char * text=0;

    PIXELFORMATDESCRIPTOR pfd ;

    if(verbose)
    {
	fprintf(stdout, "GL4Java SetDCPixelFormat: input capabilities:\n");
	printGLCapabilities ( glCaps );
    }

    if(glCaps->nativeVisualID>=0)
    {
            if ( 0 < DescribePixelFormat( hDC, (int)(glCaps->nativeVisualID), 
	                                  sizeof(pfd), &pfd ) )
	    {
	        nPixelFormat=(int)(glCaps->nativeVisualID);
	        if(verbose)
		{
		  fprintf(stderr,"\n\nUSER found stored PIXELFORMAT number: %ld\n",
		  	nPixelFormat);
		  fflush(stderr);
		}	
	    } else {
		  fprintf(stderr,"\n\nUSER no stored PIXELFORMAT number found !!\n");
           nPixelFormat = -1;
		  fflush(stderr);
	    }
	}

    if(nPixelFormat<0)
        setPixelFormatByGLCapabilities( &pfd, glCaps, offScreenRenderer, hDC);

    if(verbose)
    {
		fprintf(stderr,"\n\nUSER CHOOSED PIXELFORMAT (TRYING):\n");
		text=GetTextualPixelFormatByPFD(&pfd, nPixelFormat);			
		fprintf(stderr,text);
		fflush(stderr);
    }

    // Choose a pixel format that best matches that described in pfd
    if( hDC == 0 )
	    printf( "SetDCPixelFormat: Error, no HDC-Contex is given\n");
    else if(nPixelFormat<0)
	    nPixelFormat = ChoosePixelFormat(hDC, &pfd);

    if( nPixelFormat == 0 )
	    printf( "SetDCPixelFormat: Error with PixelFormat\n" );

    // Set the pixel format for the device context
    if( SetPixelFormat(hDC, nPixelFormat, &pfd) == FALSE)
	    printf( "setpixel failed\n" );
    else {
            (void) setGLCapabilities ( hDC, nPixelFormat, glCaps );
	    if(verbose)
	    {
	        fprintf(stdout, "GL4Java SetDCPixelFormat: used capabilities:\n");
	        printGLCapabilities ( glCaps );
	    }
    }
	fflush(stdout);
	fflush(stderr);
}