Ejemplo n.º 1
0
int main(int argc, char** argv) {
  fullscreen = false;
  grab = false;
  quit = false;
  initScreen();
  initFrameBuffer();
  createGLContext();
  createColorMap();

  createWindow();
  
  createBlankCursor();
  
  int x = 0;
  
  while(x<5000) {
    renderFrame();
    updateWindowTitle();
    x++;
    }
  
  
      /* Cleanup 
    glXDestroyWindow(display, glxwindow);
    xcb_destroy_window(connection, window);
    glXDestroyContext(display, context);
    XCloseDisplay(display);
      */
  
  return 0;
}
Ejemplo n.º 2
0
bool window_create(const char *caption,int width,int height) {
  //
  windowData.display = XOpenDisplay(NULL);

  if(!windowData.display) {
    fprintf(stderr,"window_create: Failed to open X display.\n");
    return false;
  }

  //
  if(!window_check_glx(windowData.display)) {
    //todo close display
    fprintf(stderr,"window_create: Invalid GLX version.\n");
    return false;
  }

  //
  int screen;
  screen = XDefaultScreen(windowData.display);

  //
  GLXFBConfig bestFbc=get_gl_bestFbc(windowData.display,screen);

  //
  XVisualInfo *vi = glXGetVisualFromFBConfig(windowData.display,bestFbc);

  if(!vi) {
    //todo close display
    fprintf(stderr,"Could not get visual info.\n");
    return false;
  }

  fprintf(stderr,"Chosen visual ID = 0x%d\n",vi->visualid);

  Visual *viVisual=vi->visual;
  int viScreen=vi->screen;
  int viDepth=vi->depth;
  XFree(vi);

  //
  // int depth = DefaultDepth(windowData.display, screen);
  // XVisualInfo vi;
  // XMatchVisualInfo(windowData.display, screen, depth, TrueColor, &vi);
  // fprintf(stderr,"Chosen visual ID = 0x%d\n",vi.visualid);
  // visual=vi.visual;

  //
  if(!create_window_x11(windowData.display,viScreen,viVisual,viDepth,
                        caption,width,height,
                        &windowData.cmap,&windowData.win)) {
    //todo close display
    return false;
  }

  //
  windowData.wmDelete=XInternAtom(windowData.display, "WM_DELETE_WINDOW", True);
  XSetWMProtocols(windowData.display, windowData.win, &windowData.wmDelete, 1);

  //


  windowData.xiopcode=setupXiInput(windowData.display);

  if(!windowData.xiopcode) {
    //todo destroy window
    //todo free colormap
    //todo close display
    return false;
  }

  //
  windowData.blankCursor=createBlankCursor(windowData.display,windowData.win);

  if(!windowData.blankCursor) {
    //todo destroy xi
    //todo destroy window
    //todo free colormap
    //todo close display
    return false;
  }

  //
  const char *glxExts = glXQueryExtensionsString(windowData.display,viScreen);

  if(!isExtensionSupported(glxExts,"GLX_ARB_create_context")) {
    //todo destroy blank cursor
    //todo destroy xi
    //todo destroy window
    //todo free colormap
    //todo close display

    fprintf(stderr,"window_create: glXCreateContextAttribsARB not supported.\n");
    return false;
  }

  glXCreateContextAttribsARBProc glXCreateContextAttribsARB;
  glXCreateContextAttribsARB=(glXCreateContextAttribsARBProc)
    glXGetProcAddressARB((const GLubyte*)"glXCreateContextAttribsARB");

  if(!glXCreateContextAttribsARB) {
    //todo destroy blank cursor
    //todo destroy xi
    //todo destroy window
    //todo free colormap
    //todo close display

    fprintf(stderr,"glXCreateContextAttribsARB err.\n");
    return false;
  }

  //
  windowData.ctx=0;

  //
  if(
     !window_gl_context(windowData.display,windowData.win,
                        glXCreateContextAttribsARB,bestFbc,
                        &windowData.ctx,3,3,false) &&
     !window_gl_context(windowData.display,windowData.win,
                        glXCreateContextAttribsARB,bestFbc,
                        &windowData.ctx,3,2,false) &&
     !window_gl_context(windowData.display,windowData.win,
                        glXCreateContextAttribsARB,bestFbc,
                        &windowData.ctx,3,1,false) &&
     !window_gl_context(windowData.display,windowData.win,
                        glXCreateContextAttribsARB,bestFbc,
                        &windowData.ctx,3,0,false) &&
     !window_gl_context(windowData.display,windowData.win,
                        glXCreateContextAttribsARB,bestFbc,
                        &windowData.ctx,2,1,false) &&
     !window_gl_context(windowData.display,windowData.win,
                        glXCreateContextAttribsARB,bestFbc,
                        &windowData.ctx,2,0,false)) {

    //todo destroy blank cursor
    //todo destroy xi
    //todo destroy window
    //todo free colormap
    //todo close display

    return false;
  }


  //
    if(!glXIsDirect(windowData.display,windowData.ctx)) {
    fprintf(stderr,"window_create: Indirect GLX rendering context obtained.\n");
  } else {
    fprintf(stderr,"window_create: Direct GLX rendering context obtained.\n");
  }

  //
  run_gl_swap_interval(windowData.display);

  //
  int i;

  //
  windowData.iconic=false;
  windowData.restored=false;
  windowData.sized=false;

  windowData.clientWidth=-1;
  windowData.clientHeight=-1;

  windowData.cursorX=0;
  windowData.cursorY=0;
  windowData.mouseX=0;
  windowData.mouseY=0;
  windowData.mouseZ=0;

  windowData.lockCursor=false;
  windowData.cursorLocked=false;

  for(i=0;i<INPUTS_SIZE;i++) {
    windowData.inputs[i]=INPUT_UP;
  }

  // int event_mask=ButtonPressMask|ButtonReleaseMask|
  //       PointerMotionMask |FocusChangeMask|
  //       EnterWindowMask|LeaveWindowMask;

  //     if(GrabSuccess !=XGrabPointer(windowData.display,windowData.win, True,
  //                                   event_mask,GrabModeAsync,GrabModeAsync,
  //                                   windowData.win, None, CurrentTime)) {
  //       printf("grabfail\n");
  //     }
  //
  return true;
}