ARGS() { int window; HDC hDC; HGLRC gc; THIS_CLASS(); //if (GET_INT_FIELD("renderContext")) // return 1; //pdata = (int)GET_INT_FIELD("pData"); window = GET_INT_FIELD("window"); //printf("Got window id: %d\n", window); hDC = GetDC((HWND)window); if( (gc = get_GC( window, hDC )) == 0 ) { printf( "getGC error" ); return FALSE; } //printf( "got gc: %ld\n", gc ); SET_INT_FIELD("display", (long)hDC ); //printf( "setint field display: %ld\n", hDC ); SET_INT_FIELD("renderContext", (long)gc ); //printf( "setint field renderContext: %ld\n", gc ); // setpData( pdata, env, this ); return 1; }
/* * Name : void vOpenWindow() * * Parameters: None. * * Returns : void * * Purpose : Creates the main viewing window. */ void vOpenWindow() { unsigned int display_width, display_height; unsigned int window_width, window_height, border_width = 2; unsigned int keys_buttons; int screen; int window_x = 0, window_y = 0; int x0, y0, x1, y1, rx, ry; XSizeHints size_hints; char *display_name = NULL; XSetWindowAttributes attribs; int visualAttribList[10]; XVisualInfo *visual; /* make a connection to the Xwindows display server */ if( (display=XOpenDisplay(display_name))==NULL ) { (void)fprintf( stderr, "Main: cannot connect to X server %s\n", XDisplayName(display_name) ); exit( -1 ); } /* query some values that we will need later */ screen = DefaultScreen( display ); display_width = DisplayWidth( display, screen ); window_width = display_width / 2; display_height = DisplayHeight( display, screen ); window_height = display_height / 2; /* Check to see if the Xserver supports OpenGL */ if( !glXQueryExtension(display, (int *) 0, (int *) 0) ) { fprintf( stderr, "Main: this X server does not support OpenGL\n" ); exit( -2 ); } /* find an OpenGL visual that is RGB, single buffered and has at least 4 bits per colour component of r,g and b (ie. at least 12 bit per pixel visual) */ visual = findVisual( display, 4 ); /* tell x what events I want the window to accept */ attribs.event_mask = KeyPressMask | ExposureMask | StructureNotifyMask; /* I do not know why but you MUST specify a border pixel value for XCreateWindow to work. If you do not do this, you WILL get a run time error. */ attribs.border_pixel = BlackPixel(display,screen); attribs.colormap = allocateColourmap( display, visual ); /* this is the more complicated way of opening an X window but we must use it because we want to specifiy the visual that the window is to use. This is necessary for OpenGL */ win = XCreateWindow( display, RootWindow( display, screen ), window_x, window_y, window_width, window_height, border_width, visual->depth, InputOutput, visual->visual, CWColormap | CWEventMask | CWBorderPixel, &attribs ); XStoreName( display, win, "Interaction Demo - Press 'Q' To Quit" ); XClearWindow( display, win ); XFlush( display ); /* This is the call you need to make to tell X which events to pass on to the program for tis window. The events are specified in by the event masks being or'ed together as the last parameter. To get more or less events in this window, add or remove some of the masks. */ XSelectInput(display, win, ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask | StructureNotifyMask | ButtonMotionMask); if (get_GC( win, visual, &gc ) != 0) { XDestroyWindow( display, win ); XCloseDisplay( display ); exit( -3 ); } /* we are now done with the visual so we should free the storage */ XFree( visual ); XMapWindow( display, win ); }
void init_xcl(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); int i; /* scratch */ xclstruct *dp; if (xcls == NULL) { if ((xcls = (xclstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (xclstruct))) == NULL) return; } dp = &xcls[MI_SCREEN(mi)]; /* Update every time */ dp->width = MI_WIDTH(mi); dp->height = MI_HEIGHT(mi); dp->mid_x = (dp->width / 2); dp->mid_y = (dp->height / 2); if(dp->no_preset != 1) { dp->no_preset = 1; /* some presettings */ dp->planes = MI_COUNT(mi); if (dp->planes < -MINPLANES) { dp->planes = NRAND(-MI_COUNT(mi) -MINPLANES + 1) + MINPLANES; } else if (dp->planes < MINPLANES) { dp->planes = MINPLANES; } if(dp->planes > MAXCOUNT) dp->planes = MAXCOUNT; dp->Alpha = 0.0; /* rotate.1 */ dp->Beta = 0.0; /* rotate.2 */ dp->Gamma = 0.0; /* rotate.3 */ dp->Vx = 1; /* width from zero in X */ dp->Vy = 800; /* width from zero in Y */ dp->Vz = -300; /* width from zero in Z */ dp->G = 500.0; /* ZOOM */ dp->time3 = 1.0; dp->drawtime = 25000; dp->xcldelay = STARTUPDELAY; for(i=0;i< dp->planes; i++) { dp->az[i] = 2 * M_PI * i / (float)((dp->planes)); dp->el[i] = 0.0; dp->alpha[i] = 0.75; /* direction */ dp->turn[i] = 0; dp->turn_direction[i] = 1; speed[i] = speed_in; /* see TODO */ } random_pid = getpid(); /* goes here first for randomstart */ if(randomstart) { for(i=0;i< dp->planes; i++) { switch(i) { case 0: dp->az[0] += (random_pid % 31) / 5.0; break; default: dp->az[i] = dp->az[0] + 2 * M_PI * i / (float)((dp->planes)); } } } dp->bg = MI_BLACK_PIXEL(mi); if(MI_NPIXELS(mi) <= 2) for(i=0;i< dp->planes; i++) { dp->planecolor[i] = MI_WHITE_PIXEL(mi); } else { if(!oldcolor) { for(i=0;i< dp->planes; i++) { dp->planecolor[i] = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); } } else { /* with count >2 no so good */ for(i=0;i< dp->planes; i++) { switch(i) { case 0: dp->planecolor[0] = get_color(mi, (char *) "yellow", (XColor *) NULL); break; case 1: dp->planecolor[1] = get_color(mi, (char *) "red", (XColor *) NULL); break; default: dp->planecolor[i] = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); } } } } if(dp->erase_gc == None) if (!get_GC(display, MI_WINDOW(mi), &(dp->erase_gc),dp->bg)) { free_xcl(display, dp); return; } dp->lines = countlines(); for(i=0;i< dp->planes; i++) { if(dp->gc[i] == None) if (!get_GC(display, MI_WINDOW(mi), &(dp->gc[i]), dp->planecolor[i])) { free_xcl(display, dp); return; } dp->omega_const[i] = speed[i]/3.6 /line_length*1000.0; if(dp->xseg[i] == NULL) if ((dp-> xseg[i] = (XSegment *) malloc(sizeof(XSegment) * dp->lines)) == NULL) { free_xcl(display, dp); return; } if(dp->xseg_old[i] == NULL) if ((dp->xseg_old[i] = (XSegment *) malloc(sizeof(XSegment) * dp->lines)) == NULL) { free_xcl(display, dp); return; } } if(MI_IS_VERBOSE(mi)) { (void) printf("X control line combat in a box\n"); #if !defined( lint ) && !defined( SABER ) (void) printf("Version: %s\n",sccsid); #endif (void) printf("Line length: %gm\n",line_length/1000.0); (void) printf("Speed %g km/h \n",speed[0]); (void) printf("Lines per plane: %d\n",dp->lines); (void) printf("Spectator at %gm\n",spectator/1000.0); (void) printf("Try %g frames per Second (frametime: %dus)\n", 1000000.0/frametime,frametime); (void) printf("Calibration at %d frames\n",REGULATE); } } /* clear the screen */ MI_CLEARWINDOW(mi); (void) gettimeofday(&(dp->tv1),0); dp->time1 = (double)dp->tv1.tv_sec + (double)dp->tv1.tv_usec/(double)1000000; dp->xcldelay = frametime; }