Example #1
0
//-----------------------------------------------------------------------------
void mglCanvasGL::Finish()
{
#if MGL_USE_DOUBLE
#define MGL_GL_TYPE	GL_DOUBLE
#else
#define MGL_GL_TYPE	GL_FLOAT
#endif

	if(Prm.size()>0)
	{
		PreparePrim(0);
/*		glVertexPointer(3, MGL_GL_TYPE, sizeof(mglPnt), &(Pnt[0].x));	// something wrong with arrays
		glNormalPointer(MGL_GL_TYPE, sizeof(mglPnt), &(Pnt[0].u));
		glColorPointer(4, MGL_GL_TYPE, sizeof(mglPnt), &(Pnt[0].r));
		glEnableClientState(GL_VERTEX_ARRAY);
		glEnableClientState(GL_NORMAL_ARRAY);
		glEnableClientState(GL_COLOR_ARRAY);*/

		int pdef=PDef;
		mreal ss=pPos, ww=PenWidth;
		mglPrim p;
		for(size_t i=0;i<Prm.size();i++)
		{
			p=GetPrm(i);	PDef=p.n3;	pPos=p.s;	PenWidth=p.w;
			register long n1=p.n1, n2=p.n2, n3=p.n3, n4=p.n4;
			switch(p.type)
			{
/*			case 0:	mark_draw(Pnt[n1],n4,p.s,0);	break;
			case 1:	line_draw(n1,n2);	break;
			case 2:	trig_draw(n1,n2,n3);	break;
			case 3:	quad_draw(n1,n2,n3,n4);	break;*/
			case 0:	mark_draw(Pnt[n1],n4,p.s,0);	break;
			case 1:	line_draw(Pnt[n1],Pnt[n2],0);	break;
			case 2:	trig_draw(Pnt[n1],Pnt[n2],Pnt[n3],true,0);	break;
			case 3:	quad_draw(Pnt[n1],Pnt[n2],Pnt[n3],Pnt[n4],0);	break;
			case 4:	glyph_draw(p,0);	break;
			}
		}
		PDef=pdef;	pPos=ss;	PenWidth=ww;
	}
	glFinish();
//	glBegin(GL_LINES);	glColor3f(0,0,1);	glVertex2f(0.1,0.1);	glVertex2f(0.9,0.9);	glEnd();
}
Example #2
0
int drawGLscene()
{
	while(resetpso) SDL_Delay(10);

	int i,j,k; float alpha; unsigned char clear;
	int sloop = 0;	float ratio;
	for(sloop = 0; sloop < 2; sloop++)
{
	if(blurenable)	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[0]);
	else if(stereo)
	{
		
		if(sloop == 0) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[1]);
		if(sloop == 1) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo[2]);
	}
	if(!blurenable && !stereo) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);



if(stereo) 
{
//		ratio = (GLfloat)w_width/(2*(GLfloat)w_height);
//		gluPerspective(45.0f, ratio, 0.1f, 800.0f);
ratio = w_width/3;
glViewport(-ratio,0,overtexs+ratio*2,overtexs); 
}

	glMatrixMode(GL_MODELVIEW);
	glDisable(GL_DEPTH_TEST);
 	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
//	glBlendFunc(GL_SRC_ALPHA,GL_ONE);
	//	GL_ACCUM_BUFFER_BIT|GL_STENCIL_BUFFER_BIT);
	glLoadIdentity();

//	if(stereo && sloop == 0) { glTranslatef(0, 0, 0); }
//	if(stereo && sloop == 1) { glTranslatef(0, 0, 0); }
	glBindTexture(GL_TEXTURE_2D, 0);

//	while(lock);
//	lock = 1;
//	rrotxz = rrotyz = rrotxy = rrotwx = rrotwy = rrotwz = 0;

//	lock = 0;
	if(azoom)
	{
		if(zoom > 3 || zoom < -3) azoom = -azoom;
		zoom += azoom;
	}

	playerpos.set(posx, posy, posz, posw);

	glDisable(GL_FOG);

	glFogfv(GL_FOG_COLOR, fogcolor);
	glFogi(GL_FOG_MODE, GL_LINEAR);
	glFogf(GL_FOG_DENSITY, 500);
	glFogf(GL_FOG_START, (1+((zoom*10)))*sqrt(sqrt(depth/20)));
	glFogf(GL_FOG_END, (5+((zoom*10)))*sqrt(sqrt(depth/20)));
	glTranslatef(0, 0, -10*zoom);

	if(points) 
	{
		if(!intensswitch)
		{
			intensval += 0.025f*intensui;
			if(intensval > 1.1f) intensval = -0.1f;
		}
//		list1 = glGenLists (1);
//		glNewList(list1, GL_COMPILE);
		if(stereo && sloop == 0) drawdl('l', intensval);
		if(stereo && sloop == 1) drawdl('r', intensval);
		else drawdl('c', intensval);
//		glEndList();
//		glCallList(list1);
if(ddebug) printf("draw finish %d\n", quatnum);
	}
	else
	{
		if(stereo) posbuf_run(sloop);
		else posbuf_run(10);

		for(j = (quatnum/4)-1; j >= 0; j--)
		{
			i = 4*zposbufi[j];
			if(enablemov) if(i >= movquat) continue;	

			color(2, 1);
			if(zposbufi[j] >= movquat/4) 
				glBindTexture(GL_TEXTURE_2D, texture[2]);
			if(zposbufi[j] >= 0) 
//		else if(zposbufi[j] >= freequat/4) 
				glBindTexture(GL_TEXTURE_2D, texture[1]);
			else if(zposbufi[j] >= bquat/4) 
				glBindTexture(GL_TEXTURE_2D, texture[2]);
			else if(zposbufi[j] >= 0) 
				glBindTexture(GL_TEXTURE_2D, texture[2]);
			else 	glBindTexture(GL_TEXTURE_2D, texture[2]);

			color(((48+i)/48), 0.2f);
			if(zposbufi[j] >= 0) color(((48+i)/48), 0.2f);
			else if(stereo && sloop == 0) quad_draw_l(q, i);
			else if(stereo && sloop == 1) quad_draw_r(q, i);
			//else quad_draw_new(q, i);
			else quad_draw(q, i);
		}
	}
	qbuffer[0].set(padd.a+playerpos.a-1, padd.b+playerpos.b, 
			padd.c+playerpos.c, padd.d+playerpos.d);
	qbuffer[1].set(padd.a+playerpos.a+1, padd.b+playerpos.b, 
			padd.c+playerpos.c, padd.d+playerpos.d);
	qbuffer[2].set(playerpos.a+1, playerpos.b+0.05, 
			playerpos.c, playerpos.d);
	qbuffer[3].set(playerpos.a-1, playerpos.b+0.05, 
			playerpos.c, playerpos.d);

	qbuffer[4].set(padd.a+playerpos.a, padd.b+playerpos.b-1, 
			padd.c+playerpos.c, padd.d+playerpos.d);
	qbuffer[5].set(padd.a+playerpos.a, padd.b+playerpos.b+1, 
			padd.c+playerpos.c, padd.d+playerpos.d);
	qbuffer[6].set(playerpos.a+0.05, playerpos.b+1, 
			playerpos.c, playerpos.d);
	qbuffer[7].set(playerpos.a+0.05, playerpos.b-1, 
			playerpos.c, playerpos.d);


	color(3, 1);
	glBindTexture(GL_TEXTURE_2D, texture[3]);
	for(i = 0; i < 8; i++)
		quat_rotate(qbuffer, i);
//	quad_draw(qbuffer, 0);
//	quad_draw(qbuffer, 4);

	if(blurenable) DrawBlur(10*blurr,0.001f);
}
	if(stereo) DrawStereo();

	SDL_GL_SwapBuffers();

	drawnonce = 1;
	return(0);
}
Example #3
0
//-----------------------------------------------------------------------------
void mglCanvasGL::mark_draw(const mglPnt &q, char type, mreal size, mglDrawReg *d)
{
	mglPnt p0=q,p1=q,p2=q,p3=q;
	mreal ss=fabs(size);

	if(type=='.' || ss==0)
	{
		if(d)	d->PenWidth = ss?ss:sqrt(font_factor/400);
		pnt_draw(q,d);
	}
	else
	{
		if(d)
		{
			d->PDef = MGL_SOLID_MASK;	d->angle = 0;
			d->PenWidth*=fabs(50*size);
			if(d->PenWidth<1)	d->PenWidth=1;
		}
		if(!strchr("xsSoO",type))	ss *= 1.1;
		switch(type)
		{
		case 'P':
			p0.x = q.x-ss;	p0.y = q.y-ss;	p1.x = q.x+ss;	p1.y = q.y-ss;
			p2.x = q.x+ss;	p2.y = q.y+ss;	p3.x = q.x-ss;	p3.y = q.y+ss;
			line_draw(p0,p1,d);	line_draw(p1,p2,d);
			line_draw(p2,p3,d);	line_draw(p3,p0,d);
		case '+':
			p0.x = q.x-ss;	p0.y = q.y;	p1.x = q.x+ss;	p1.y = q.y;	line_draw(p0,p1,d);
			p2.x = q.x;	p2.y = q.y-ss;	p3.x = q.x;	p3.y = q.y+ss;	line_draw(p2,p3,d);
			break;
		case 'X':
			p0.x = q.x-ss;	p0.y = q.y-ss;	p1.x = q.x+ss;	p1.y = q.y-ss;
			p2.x = q.x+ss;	p2.y = q.y+ss;	p3.x = q.x-ss;	p3.y = q.y+ss;
			line_draw(p0,p1,d);	line_draw(p1,p2,d);
			line_draw(p2,p3,d);	line_draw(p3,p0,d);
		case 'x':
			p0.x = q.x-ss;	p0.y = q.y-ss;	p1.x = q.x+ss;	p1.y = q.y+ss;	line_draw(p0,p1,d);
			p2.x = q.x+ss;	p2.y = q.y-ss;	p3.x = q.x-ss;	p3.y = q.y+ss;	line_draw(p2,p3,d);
			break;
		case 'S':
			p0.x = q.x-ss;	p0.y = q.y-ss;	p1.x = q.x-ss;	p1.y = q.y+ss;
			p2.x= q.x+ss;	p2.y= q.y+ss;	p3.x = q.x+ss;	p3.y = q.y-ss;
			quad_draw(p0,p1,p3,p2,d);
		case 's':
			p0.x = q.x-ss;	p0.y = q.y-ss;	p1.x = q.x+ss;	p1.y = q.y-ss;
			p2.x = q.x+ss;	p2.y = q.y+ss;	p3.x = q.x-ss;	p3.y = q.y+ss;
			line_draw(p0,p1,d);	line_draw(p1,p2,d);
			line_draw(p2,p3,d);	line_draw(p3,p0,d);
			break;
		case 'D':
			p0.x = q.x;	p0.y = q.y-ss;	p1.x = q.x+ss;	p1.y = q.y;
			p2.x= q.x;	p2.y= q.y+ss;	p3.x = q.x-ss;	p3.y = q.y;
			quad_draw(p0,p1,p3,p2,d);
		case 'd':
			p0.x = q.x;	p0.y = q.y-ss;	p1.x = q.x+ss;	p1.y = q.y;
			p2.x = q.x;	p2.y = q.y+ss;	p3.x = q.x-ss;	p3.y = q.y;
			line_draw(p0,p1,d);	line_draw(p1,p2,d);
			line_draw(p2,p3,d);	line_draw(p3,p0,d);
			break;
		case 'Y':
			p1.x = q.x;	p1.y = q.y-ss;	line_draw(q,p1,d);
			p2.x = q.x-0.8*ss;	p2.y = q.y+0.6*ss;	line_draw(q,p2,d);
			p3.x = q.x+0.8*ss;	p3.y = q.y+0.6*ss;	line_draw(q,p3,d);
			break;
		case '*':
			p0.x = q.x-ss;		p0.y = q.y;
			p1.x = q.x+ss;		p1.y = q.y;	line_draw(p0,p1,d);
			p0.x = q.x-0.6*ss;	p0.y = q.y-0.8*ss;
			p1.x = q.x+0.6*ss;	p1.y = q.y+0.8*ss;	line_draw(p0,p1,d);
			p0.x = q.x-0.6*ss;	p0.y = q.y+0.8*ss;
			p1.x = q.x+0.6*ss;	p1.y = q.y-0.8*ss;	line_draw(p0,p1,d);
			break;
		case 'T':
			p0.x = q.x-ss;	p0.y = q.y-ss/2;
			p1.x = q.x+ss;	p1.y = q.y-ss/2;
			p2.x= q.x;		p2.y= q.y+ss;
			trig_draw(p0,p1,p2,false,d);
		case '^':
			p0.x = q.x-ss;	p0.y = q.y-ss/2;
			p1.x = q.x+ss;	p1.y = q.y-ss/2;
			p2.x= q.x;		p2.y= q.y+ss;
			line_draw(p0,p1,d);	line_draw(p1,p2,d);
			line_draw(p2,p0,d);	break;
		case 'V':
			p0.x = q.x-ss;	p0.y = q.y+ss/2;
			p1.x = q.x+ss;	p1.y = q.y+ss/2;
			p2.x= q.x;		p2.y= q.y-ss;
			trig_draw(p0,p1,p2,false,d);
		case 'v':
			p0.x = q.x-ss;	p0.y = q.y+ss/2;
			p1.x = q.x+ss;	p1.y = q.y+ss/2;
			p2.x= q.x;		p2.y= q.y-ss;
			line_draw(p0,p1,d);	line_draw(p1,p2,d);
			line_draw(p2,p0,d);	break;
		case 'L':
			p0.x = q.x+ss/2;	p0.y = q.y+ss;
			p1.x = q.x+ss/2;	p1.y = q.y-ss;
			p2.x= q.x-ss;		p2.y= q.y;
			trig_draw(p0,p1,p2,false,d);
		case '<':
			p0.x = q.x+ss/2;	p0.y = q.y+ss;
			p1.x = q.x+ss/2;	p1.y = q.y-ss;
			p2.x= q.x-ss;		p2.y= q.y;
			line_draw(p0,p1,d);	line_draw(p1,p2,d);
			line_draw(p2,p0,d);	break;
		case 'R':
			p0.x = q.x-ss/2;	p0.y = q.y+ss;
			p1.x = q.x-ss/2;	p1.y = q.y-ss;
			p2.x= q.x+ss;		p2.y= q.y;
			trig_draw(p0,p1,p2,false,d);
		case '>':
			p0.x = q.x-ss/2;	p0.y = q.y+ss;
			p1.x = q.x-ss/2;	p1.y = q.y-ss;
			p2.x= q.x+ss;		p2.y= q.y;
			line_draw(p0,p1,d);	line_draw(p1,p2,d);
			line_draw(p2,p0,d);	break;
		case 'O':
/*			for(long j=long(-ss);j<=long(ss);j++)	for(long i=long(-ss);i<=long(ss);i++)
			{
				register long x=long(q.x)+i, y=long(q.y)+j;
				if(i*i+j*j>=ss*ss || !d || x<d->x1 || x>d->x2 || y<d->y1 || y>d->y2)	continue;
				pnt_plot(x,y,q.z+1,cs,d->ObjId);
			}*/
		case 'o':
			for(long i=0;i<=20;i++)	// TODO copy from mark_pix()?!
			{
				p0 = p1;	p1.x = q.x+ss*cos(i*M_PI/10);	p1.y = q.y+ss*sin(i*M_PI/10);
				if(i>0)	line_draw(p0,p1,d);
			}
			break;
		case 'C':
			pnt_draw(q,d);
			for(long i=0;i<=20;i++)
			{
				p0 = p1;	p1.x = q.x+ss*cos(i*M_PI/10);	p1.y = q.y+ss*sin(i*M_PI/10);
				if(i>0)	line_draw(p0,p1,d);
			}
			break;
		}
	}
}