Example #1
0
P op_resizewindow(void)
{
#if X_DISPLAY_MISSING
	return NO_XWINDOWS;
#else
  P width, height;
  P k;

  if (dvtdisplay == NULL) return NO_XWINDOWS;
  if (o_3 < FLOORopds) return OPDS_UNF;
  if (CLASS(o_3) != NUM) return OPD_CLA;
  if (!PVALUE(o_3,&wid)) return UNDF_VAL;
  if (CLASS(o_2) != NUM) return OPD_CLA;
  if (!PVALUE(o_2,&width)) return UNDF_VAL;
  if (CLASS(o_1) != NUM) return OPD_CLA;
  if (!PVALUE(o_1,&height)) return UNDF_VAL;

  for (k = 0; k < ndvtwindows; k++)
    if (dvtwindows[k] == wid) {
      resizewindow(width, height);
      break;
    }

  FREEopds = o_3;
  return OK;
#endif
}
static void
getevent(void)			/* get next event */
{
	XNextEvent(ourdisplay, levptr(XEvent));
	switch (levptr(XEvent)->type) {
	case ConfigureNotify:
		resizewindow(levptr(XConfigureEvent));
		break;
	case UnmapNotify:
		mapped = 0;
		break;
	case MapNotify:
		mapped = 1;
		break;
	case Expose:
		fixwindow(levptr(XExposeEvent));
		break;
	case KeyPress:
		getkey(levptr(XKeyPressedEvent));
		break;
	case ButtonPress:
		switch (levptr(XButtonPressedEvent)->button) {
		case Button4:		/* wheel up */
		case Button5:		/* wheel down */
			break;
		default:
			getmove(levptr(XButtonPressedEvent));
			break;
		}
		break;
	}
}
Example #3
0
static void
fixwindow(				/* repair damage to window */
	register XExposeEvent  *eexp
)
{
	if ((hres == 0) | (vres == 0)) {	/* first exposure */
		resizewindow((XConfigureEvent *)eexp);
		return;
	}
	if (eexp->count)		/* wait for final exposure */
		return;
					/* rerender everything */
	render();
}
Example #4
0
static int
dev_input(		/* get next input event */
	int	nsecs
)
{
#if 0
	static time_t	lasttime = 0;
	time_t	thistime;

	if (nsecs > 0) {
		thistime = time(0);
		nsecs -= (long)(thistime - lasttime);
		lasttime = thistime;
	}
	if (nsecs > 0)
		alarm(nsecs);
#endif
	XNextEvent(ourdisplay, levptr(XEvent));
	switch (levptr(XEvent)->type) {
	case ConfigureNotify:
		resizewindow(levptr(XConfigureEvent));
		break;
	case UnmapNotify:
		mapped = 0;
		break;
	case MapNotify:
		mapped = 1;
		break;
	case Expose:
		fixwindow(levptr(XExposeEvent));
		break;
	case KeyPress:
		return(getkey(levptr(XKeyPressedEvent)));
	case ButtonPress:
		getmove(levptr(XButtonPressedEvent));
		break;
	}
	return(1);
}
static void
fixwindow(				/* repair damage to window */
	XExposeEvent  *eexp
)
{
	int	xmin, xmax, ymin, ymax;

	if (odev.hres == 0 || odev.vres == 0)	/* first exposure */
		resizewindow((XConfigureEvent *)eexp);
	xmin = eexp->x; xmax = eexp->x + eexp->width;
	ymin = odev.vres - eexp->y - eexp->height; ymax = odev.vres - eexp->y;
						/* clear portion of depth */
	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
	glDepthFunc(GL_ALWAYS);
	glBegin(GL_POLYGON);
	glVertex3d((double)xmin/odev.hres, (double)ymin/odev.vres, 0.);
	glVertex3d((double)xmax/odev.hres, (double)ymin/odev.vres, 0.);
	glVertex3d((double)xmax/odev.hres, (double)ymax/odev.vres, 0.);
	glVertex3d((double)xmin/odev.hres, (double)ymax/odev.vres, 0.);
	glEnd();
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glDepthFunc(GL_LEQUAL);
	qtRedraw(xmin, ymin, xmax, ymax);
}
Example #6
0
int mainloop(void*)
{
	int drawchange = 0; int refreshdelay[2] = {33, 33}; int rdelay = 33;
	Uint32 time1 = SDL_GetTicks(), time2 = SDL_GetTicks();
	float ts; int u; int i;
	
	if(!init_SDL(surface))
	{ fprintf(stderr, "SDL_OPENGL failed\n"); exit(1);}
	if(!initGL(w_width, w_height))
	{ fprintf(stderr, "OpenGL failed\n"); exit(1);}

	SDL_WM_SetCaption( "Tesseract", NULL );

	glPointSize(8.0f);

	resizewindow(1280, 1024); 

	load_textures();

	lbounds[0] = 10;
	ts = lbounds[0];

	q = (Quaternion*)(malloc(9999999*sizeof(Quaternion)));
	qbuffer = (Quaternion*)(malloc(9999*sizeof(Quaternion)));
	quatnum = 0;

//	quatnum += construct_tesseract(1,1,1,1, 0, 0, 0, 1,quatnum, 0.5);
playerpost.set(0,0,0,0);
	float acc = fack;

	float spp[18] = { 
		0,
		0, 
		(GLfloat)iterations, // 255 iterations
		0.35f,
		0,
		F_QUATMANDEL,
		-acc+playerpost.a,
		acc+playerpost.a,
		-acc+playerpost.b,
		acc+playerpost.b,
		-acc+playerpost.c,
		acc+playerpost.c,
		-acc+playerpost.d,
		acc+playerpost.d,
		acc,
		zoom2,
		tesseract,
		simplex
		};

	if(points)
		{
			quatnum = calc_fractal(spp, q);
		}
	else
		quatnum += construct_tesseract(1,1,1,1, 0, 0, 0, 0,quatnum, 0.5);

	bquat = quatnum; 
	t_size = quatnum;
/*
	quatnum += construct_tesseract(1,1,1,1, -ts,  ts,  ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts, -ts,  ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts,  ts, -ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts,  ts,  ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts, -ts, -ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts, -ts,  ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts,  ts, -ts,  ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts, -ts, -ts,  ts,quatnum, 0.5);

	quatnum += construct_tesseract(1,1,1,1, -ts,  ts,  ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts, -ts,  ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts,  ts, -ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts,  ts,  ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1,  ts, -ts, -ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts, -ts,  ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts,  ts, -ts,  -ts,quatnum, 0.5);
	quatnum += construct_tesseract(1,1,1,1, -ts, -ts, -ts,  -ts,quatnum, 0.5);
*/

	freequat = quatnum; 
//	quatnum += construct_tesseract(1,1,1,1, 0,  0, 0, 0,quatnum, 0.5);

/*
	for(u = 4; u <= 8; u+=2)
	quatnum += construct_tesseract(1,1,1,1, 0,  0, 0, -(5-u*4),quatnum, 1.75);

	for(u = 4; u <= 8; u+=2)
	quatnum += construct_tesseract(1,1,1,1, 0,  0, -(5-u*4), 0,quatnum, 1.75);

	for(u = 4; u <= 8; u+=2)
	quatnum += construct_tesseract(1,1,1,1, 0, -(5-u*4), 0, 0,quatnum, 1.75);

	for(u = 4; u <= 8; u+=2)
	quatnum += construct_tesseract(1,1,1,1, -(5-u*4),  0,  0, 0,quatnum, 1.75);

*/

	movquat = quatnum;

/*
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.8);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 1.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);

	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
	quatnum += construct_tesseract(1,1,1,1, 0,  0,  0, 0,quatnum, 0.1);
*/
	maxquat = quatnum;

	int yy;
	printf("quatnum: %d\n", quatnum);

//	for(u = 0; u < quatnum; u++)
//		qo[u] = q[u];

	playerpos.set(0,0,0,0);
	playerpost.set(0,0,0,0);
	padd.set(0,0,0,0);
	ptemp.set(0,0,0,0);
	ptemp2.set(0,0,0,0);

			randreinit();

	init_fbo(0);	
	init_fbo(1);	
	init_fbo(2);
	
	init_fbo(3);	

	for(i = 0; i < quatnum/4; i++)
	{
		zposbuf[i] = get_zposbuf(i);
		zposbufi[i] = i;
	}

	while(!done)
	{
		framecounter++;
		if(framecounter > 4294967000UL) framecounter = 0;
		drawchange = keylistener();
		SDL_Delay(rdelay*0.5);
		if(!(framecounter%5))
		{
//			printf("Delay: %d\n", rdelay);
			time1 = SDL_GetTicks();
			refreshdelay[framecounter%2] = 
				1000/((((int)(time1-time2)) > 0)
				? (int)(time1-time2) : 1000 );
			time2 = time1;
			if(abs(refreshdelay[framecounter%2]
			- refreshdelay[(framecounter-1)%2])
			>= 2)
			{ 
				rdelay = (refreshdelay[framecounter%2]
				       + refreshdelay[(framecounter-1)%2])/2; 
				rdelay -= 16;
				if(rdelay <= 0) rdelay = 0;
				rdelay = 33;
			}
		}
		if(!(framecounter%((int)(33*20))))
			randreinit();		
		drawGLscene();
	}
	printf("Quit called, cleaning up\n");
	SDL_Quit(); 

	return(0);
}
Example #7
0
/* check for input events and return if a redraw needs to be done */
int keylistener()
{
	int mu = 0; int i; int fd;
	int mprevx, mprevy; bool leftB = false, rightB = false, middleB = false; 
	bool mwheelup = false, mwheeldown = false; struct js_event js; 
	while(SDL_PollEvent(&event))
	{
		switch(event.type)
		{
		case SDL_VIDEORESIZE:
			w_width = event.resize.w; 
			w_height = event.resize.h; 
			resizewindow(w_width, w_height);
			printf("debug: draw function called (resize %dx%d)\n", w_width, w_height);
			break;
		case SDL_KEYDOWN:
			if(keypress(&event.key.keysym, 1)) done = 1;
			break;
		case SDL_KEYUP:
			keypress(&event.key.keysym, 0);
			break;
		case SDL_MOUSEBUTTONDOWN:
			SDL_GetMouseState(&mprevx, &mprevy);
			leftB =(event.button.button == SDL_BUTTON_LEFT);
			rightB=(event.button.button == SDL_BUTTON_RIGHT);
			middleB=(event.button.button == SDL_BUTTON_MIDDLE);
			mwheelup=(event.button.button == SDL_BUTTON_WHEELUP);
			mwheeldown=(event.button.button == SDL_BUTTON_WHEELDOWN);
	//		if(leftB && rightB) mpresslr = 1;
			if(leftB) { mpressl = 1; SDL_GetMouseState(&mxsave, &mysave); }
			if(rightB) { mpressr = 1; SDL_GetMouseState(&mxsave2, &mysave2); }
			if(middleB) { mpressm = 1; SDL_GetMouseState(&mxsave3, &mysave3); }

			break;
		case SDL_MOUSEBUTTONUP:
			leftB =(event.button.button == SDL_BUTTON_LEFT);
			rightB=(event.button.button == SDL_BUTTON_RIGHT);
			middleB=(event.button.button == SDL_BUTTON_MIDDLE);
			mwheelup=(event.button.button == SDL_BUTTON_WHEELUP);
			mwheeldown=(event.button.button == SDL_BUTTON_WHEELDOWN);
//			if(leftB && rightB) mpresslr = 0;
			if(leftB) { mpressl = 0; mxsave = 0; mysave = 0; rrotxy = 0; rrotyz = 0; }
			if(rightB) { mpressr = 0; mxsave2 = 0; mysave2 = 0;  rrotwx = 0; rrotwy = 0; }
			if(middleB) { mpressm = 0; mxsave3 = 0; mysave3 = 0; rrotxz = 0; rrotwz = 0; }
			break;
		case SDL_JOYAXISMOTION:
//			for(i = 1; i < 24; i++) 
//				printf(" %d : %d", i, SDL_JoystickGetAxis(joys, i));
//			printf("\n");
			break;
		case SDL_JOYBUTTONDOWN:
			printf("BUTTON\n");
			break;
		case SDL_QUIT:
			done = 1;
			break;
			default:
			break;
		}
	}
/*
			printf("START\n");
                        for(i = 0; i < 4;) 
                        { 
			while(read(fd, &js, sizeof(struct js_event)) == sizeof(struct js_event))
			printf("Event: type %d, time %d, number %d, value %d\n",
                                js.type, js.time, js.number, js.value);
			if(js.number == 0)
        rotxy = (js.value)*0.000001f;
			if(js.number == 1)
        rotyz = (js.value)*0.000001f;
			if(js.number == 2)
        rotwx = (js.value)*0.000001f;
			if(js.number == 3)
        rotwy = (js.value)*0.000001f; 

			i++;
                        }   
			printf("END\n");
*/
	/* perform a function for each mousebutton according to the
	 * circumstances it was pressed in */
	while(lock);
	lock = 1;
	if(mpressl) lmousepress(0, 0);
	if(mpressr) rmousepress(0,0); 
	if(mpressm) mmousepress(0,0);
	if(mwheelup) zoom-=0.2;
	if(mwheeldown) zoom+=0.2;
	lock = 0;
//	else zoom = 0;
	return(0);
}
Example #8
0
int keypress(SDL_keysym *keysym, int ud)
{
	switch(keysym->sym) 
	{
/* quit */
	case SDLK_ESCAPE:
		if(ud) { done=0; }
		break;
	case SDLK_UP:
		if(ud) movz += 1;
		break;
	case SDLK_DOWN:
		if(ud) movz -= 1;
		break;
	case SDLK_LEFT:
		if(ud) movx += 1;
		break;
	case SDLK_RIGHT:
		if(ud) movx -= 1;
		break;
	case SDLK_RCTRL:
		if(ud) movw += 1;
		break;
	case SDLK_RSHIFT:
		if(ud) movw -= 1;
		break;
	case SDLK_PAGEDOWN:
		if(ud) movy += 1;
		break;
	case SDLK_PAGEUP:
		if(ud) movy -= 1;
		break;


	case SDLK_SPACE:
		if(ud) bulletf = -bulletf;
		break;
	case SDLK_RETURN:
		break;
	case SDLK_f:
		if(ud) {fogcolor[0] = 1; fogcolor[1] = 0; fogcolor[2] = 1; fogcolor[3] = 1;}
		if(!ud) {fogcolor[0] = 0; fogcolor[1] = 0; fogcolor[2] = 0; fogcolor[3] = 1;}
		break;
	case SDLK_RIGHTBRACKET:
		zfov-=0.5;
		if(zfov < 1) { zfov+=0.5; zfov*=0.5; }
		break;
	case SDLK_LEFTBRACKET:
		if(zfov < 1) zfov*=2; 
		else zfov+= 0.5;
		break;
	case SDLK_s:
		if(!ud) arot = ~arot;
		break;
	case SDLK_w:
		if(!ud) grab = ~grab;
		break;

	case SDLK_5:
		if(!ud) skip = !skip?1:0;
		break;

	case SDLK_q:
		if(!ud) aspeed /= 2;
		break;
	case SDLK_a:
		if(!ud) aspeed *= 2;
		break;

	case SDLK_o:
		if(!ud) intensui /= 1.1;
		break;
	case SDLK_p:
		if(!ud) intensui *= 1.1;
		break;

	case SDLK_j:
		if(lrratio <= 0) break;
		if(!ud) lrratio -= 0.05;
		break;
	case SDLK_k:
		if(lrratio >= 1) break;
		if(!ud) lrratio += 0.05;
		break;

	case SDLK_n:
		if(!ud) blurr /= 2;
		break;
	case SDLK_m:
		if(!ud) blurr *= 2;
		break;

	case SDLK_t:
		if(!ud) 
		{
		stereo = ~stereo;
			if(stereo) resizewindow(w_width/2, w_height);
			else resizewindow(w_width, w_height);
		}
		break;


	case SDLK_y:
		if(!ud) tilt = ~tilt;
		break;

	case SDLK_b:
		if(!ud) blurenable = ~blurenable;
		break;
	case SDLK_g:
		if(!ud) enablemov = ~enablemov;
		break;
	case SDLK_i:
		if(!ud) intensswitch = ~intensswitch;
		break;

	case SDLK_1:
		if(!ud) zoom2 *=2;
		break;
	case SDLK_2:
		if(!ud) zoom2 /=2;
		break;

	case SDLK_c:
		if(!ud) depth += 0.2f;
		break;
	case SDLK_v:
		if(!ud) depth -= 0.2f;
		break;
	case SDLK_EQUALS:
		if(fov4d < 1) fov4d*=2; 
		else fov4d+= 0.5;
		break;
	case SDLK_0:
		fov4d = 1;
		break;
	case SDLK_MINUS:
		fov4d-=0.5;
		if(fov4d < 1) { fov4d+=0.5; fov4d*=0.5; }
		break;
		default:
		break;
	}
	return(0);
}