Example #1
0
void MainLoop()
{
	while (!done)
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg); 
		}
		else if (keys[VK_ESCAPE]) done=true;
		else
		{
			glClear(0x4100);
			glLoadIdentity();
			m_xform3(m,cam.eye,cam.eye);
			m_xform3(m,cam.up,cam.up);
			setcameraview(cam,4.0f/3.0f);
			scene_render(*CNSlogo);
			//scene_render(*copytest);
			SwapBuffers(hDC);
			Sleep(10);
		}

	}
}
Example #2
0
void drawevent(event *e, float t)
{
	glPushAttrib(GL_ALL_ATTRIB_BITS);

	float x1,y1,x2,y2;

	x1=(float)floor(linear((float)e->startrectx1,(float)e->endrectx1,t));
	y1=(float)floor(linear((float)e->startrecty1,(float)e->endrecty1,t));
	if (xres==320) y1+=0.5; if (xres==1024) y1+=1;
	x2=(float)floor(linear((float)e->startrectx2,(float)e->endrectx2,t))+1;
	y2=(float)floor(linear((float)e->startrecty2,(float)e->endrecty2,t))+1;

	if (e->eventtype==layer2d)
	{
		glDepthMask(false);
		glLoadIdentity();
		gluOrtho2D (0, 640, 480,0);
		glViewport(0,0,xres,yres);
		glColor4f(linear(e->startcol[0],e->endcol[0],t),linear(e->startcol[1],e->endcol[1],t),linear(e->startcol[2],e->endcol[2],t),linear(e->startcol[3],e->endcol[3],t));
		glEnable(GL_BLEND);
		glBlendFunc(e->blendfunc1,e->blendfunc2);
		if (e->textured) 
		{
			glEnable(GL_TEXTURE_2D); 
			glBindTexture(GL_TEXTURE_2D,e->mattexture);
			glBegin(GL_QUADS);
			glTexCoord2f(0,0);
			glVertex2f(x1,y1-1);
			glTexCoord2f(0,1);
			glVertex2f(x2,y1-1);
			glTexCoord2f(1,1);
			glVertex2f(x2,y2+1);
			glTexCoord2f(1,0);
			glVertex2f(x1,y2+1);
			glEnd();
		}
		else 
		{
			glDisable(GL_TEXTURE_2D);
			quad(x1,y1,x2,y2);
		}
	}
	if (e->eventtype==layer3d)
	{
		float animtimer=linear((float)e->animstart,(float)e->animend,t);
		scene *pf = e->iscene;
		camera *cam=e->icam;
		
		if (calculatehierarchy[pf->number])
		{
			getscenestate(pf,animtimer,e->ianim);		
			calculateobjhierarchy(pf,-1,NULL);
		}
		
		float f=linear((float)e->camstart,(float)e->camend,t);

		cam->eye.x=cam->eyex->GetKey(f);
		cam->eye.y=cam->eyey->GetKey(f);
		cam->eye.z=cam->eyez->GetKey(f);
		cam->target.x=cam->trgx->GetKey(f);
		cam->target.y=cam->trgy->GetKey(f);
		cam->target.z=cam->trgz->GetKey(f);
		cam->fov=cam->fovt->GetKey(f);
		cam->roll=cam->rollt->GetKey(f);

		glLoadIdentity();
		if (!cam->eyex || (cam->eyex && cam->eyex->numkey==0) ) cam=lastcam;
		setcameraview(*cam,(float)(x2-x1)/(float)(y2-y1));
		lastcam=cam;
		glViewport((int)(x1*(float)xres/640.0),(int)(yres-y2*(float)yres/480.0),(int)((x2-x1)*(float)xres/640.0),(int)((y2-y1)*(float)yres/480.0));
		glEnable(GL_BLEND);
		glEnable(GL_LIGHTING);
		renderscene(pf);
		//switchto2d();
	}
	if (e->eventtype==cleargl)
	{
		if (e->clearzbuffer && !e->clearscreen) glClear(0x100);
		if (!e->clearzbuffer && e->clearscreen) glClear(0x4000);
		if (e->clearzbuffer && e->clearscreen) glClear(0x4100);
	}
	if (e->eventtype==rendertotext)
	{
		glLoadIdentity();
		gluOrtho2D (0, 640, 480,0);
		glViewport(0,0,xres,yres);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,shots[e->texture].texture);
		glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,(int)(x1*(float)xres/640.0),(int)(yres-y2*(float)yres/480.0), 1024, 1024,0);
		shots[e->texture].x1=0;
		shots[e->texture].y1=(y2-y1)*(float)xres/640.0f/1024.0f;
		shots[e->texture].x2=(x2-x1)*(float)yres/480.0f/1024.0f;
		shots[e->texture].y2=0;
	}
	if (e->eventtype==feedback)
	{
		glLoadIdentity();
		gluOrtho2D (0, 640, 480,0);
		glViewport(0,0,xres,yres);
		glColor4f(linear(e->startcol[0],e->endcol[0],t),linear(e->startcol[1],e->endcol[1],t),linear(e->startcol[2],e->endcol[2],t),linear(e->startcol[3],e->endcol[3],t));
		glEnable(GL_BLEND);
		glBlendFunc(e->blendfunc1,e->blendfunc2);
		glDisable(GL_DEPTH_TEST);

		glEnable(GL_TEXTURE_2D); 
		glBindTexture(GL_TEXTURE_2D,shots[e->texture].texture);
		glBegin(GL_QUADS);

		float xc,yc,xs,ys;
		xc=(shots[e->texture].x1+shots[e->texture].x2)/2.0f;
		yc=(shots[e->texture].y1+shots[e->texture].y2)/2.0f;
		xs=(shots[e->texture].x2-shots[e->texture].x1)/2.0f;
		ys=(shots[e->texture].y2-shots[e->texture].y1)/2.0f;

		for (int x=0; x<e->param1; x++)
		{
			float zoom=1.0f+(float)x/e->param1/e->param4;
			glColor4f(linear(e->startcol[0],e->endcol[0],t)*(float)(20-x)/20.0f,linear(e->startcol[1],e->endcol[1],t)*(float)(20-x)/20.0f,linear(e->startcol[2],e->endcol[2],t)*(float)(20-x)/20.0f,linear(e->startcol[3],e->endcol[3],t)*(float)(20-x)/20.0f);
			glTexCoord2f(xc-xs/zoom,yc-ys/zoom);
			glVertex2f(x1,y1);
			glTexCoord2f(xc+xs/zoom,yc-ys/zoom);
			glVertex2f(x2,y1);
			glTexCoord2f(xc+xs/zoom,yc+ys/zoom);
			glVertex2f(x2,y2);
			glTexCoord2f(xc-xs/zoom,yc+ys/zoom);
			glVertex2f(x1,y2);
		}

		glEnd();

	}
	if (e->eventtype==grideffect)
	{
		glDepthMask(false);
		float time=linear(e->gridstart,e->gridend,t);
		glLoadIdentity();
		gluOrtho2D (0, 640, 480,0);
		glViewport(0,0,xres,yres);
		glColor4f(linear(e->startcol[0],e->endcol[0],t),linear(e->startcol[1],e->endcol[1],t),linear(e->startcol[2],e->endcol[2],t),linear(e->startcol[3],e->endcol[3],t));
		glEnable(GL_BLEND);
		glBlendFunc(e->blendfunc1,e->blendfunc2);
		glEnable(GL_TEXTURE_2D);
		glBindTexture(GL_TEXTURE_2D,shots[e->texture].texture);
		MakeEffect(e->effect,time,x1,y1,x2,y2, shots[e->texture].x1, shots[e->texture].y1, shots[e->texture].x2, shots[e->texture].y2,
				0, 0, 0, 0, 0, 0, 0, 0);
	}
	switchto2d();
	glPopAttrib();
}