
separate (adagate.drawisland)


procedure rustyZPM is
	gx,gz: glfloat;
begin


	--////// draw double cylinder ZPM begin ///////////
	glUseProgram(pidzpm34a);

-------------------------------------------------------------------------
	bmvp := imvp;
	bmm := identity;
	if mrolling then

		barreltime := glfwGetTime;
		tt := float( (barreltime - timeofroll ) / secperroll );
		barangle := onepi*tt*rad2deg;

		if( tt<1.0 ) then
			mposbar(1):=olbarrl(1)+tt*(nubarrl(1)-olbarrl(1));
			mposbar(2):=olbarrl(2)+tt*(nubarrl(2)-olbarrl(2));
			mposbar(3):=olbarrl(3)+tt*(nubarrl(3)-olbarrl(3));

			if    (rolldir=-1) then axis:=xaxis; barangle:=-barangle;
			elsif (rolldir=+1) then axis:=xaxis;
			elsif (rolldir=+3) then axis:=zaxis; barangle:=-barangle;
			elsif (rolldir=-3) then axis:=zaxis;
			end if;

			cyl2lit.updcyl2(rbarrel, mposbar(1),mposbar(2),mposbar(3));
			translate(bmm, -mposbar(1), -mposbar(2), -mposbar(3) );
			degRotate(bmm, barangle, axis(1), axis(2), axis(3) );
			translate(bmm, mposbar(1), mposbar(2), mposbar(3) );
			bmvp := bmm;
			matXmat( bmvp, iviewmatrix ); --vm ); -- check vm
			matXmat( bmvp, projMatrix ); -- check pm
		else
			mrolling:=false;
			mposbar:=nubarrl;
			cyl2lit.updcyl2(rbarrel, mposbar(1),mposbar(2),mposbar(3));
		end if; -- tt
	end if; -- mrolling
-------------------------------------------------------------------------



	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, albedo34a);

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, normal34a);

	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, metallic34a);

	glActiveTexture(GL_TEXTURE3);
	glBindTexture(GL_TEXTURE_2D, roughness34a);

	glActiveTexture(GL_TEXTURE4);
	glBindTexture(GL_TEXTURE_2D, ao34a);

	gluniformmatrix4fv( proj34a, 1, gl_false, projMatrix(1,1)'address );
	gluniformmatrix4fv( view34a, 1, gl_false, iviewMatrix(1,1)'address );
	gluniformmatrix4fv( modl34a, 1, gl_false, bmm(1,1)'address );


	gluniform1i(albm34a,0);
	gluniform1i(nrmm34a,1);
	gluniform1i(metm34a,2);
	gluniform1i(rufm34a,3);
	gluniform1i(aom34a,4);

	if bkg = 3 then
		gluniform3f(pColr34a, 250.0, 140.0, 0.0 ); --gold lightColor
	elsif bkg=4 then
		gluniform3f(pColr34a, 120.0, 120.0, 120.0 ); --lightColor
	else
		gluniform3f(pColr34a, 250.0, 250.0, 250.0 ); --lightColor
	end if;


	gx:=glfloat(barx);
	gz:=glfloat(barz);

	for i in 1..3 loop --define 3 light positions

		if i=1 then
			if bkg<3 then
				gluniform3f(pos0_34a, 0.0, 20.0, 0.0 ); --lightPos
			end if;
		elsif i=2 then
			if bkg<3 then
				gluniform3f(pos1_34a, gx+10.0, 20.0, gz+10.0);
			end if;
		elsif i=3 then
			if bkg>=3 then
				gluniform3f(pos0_34a, gx+10.0, 20.0, gz-10.0);
				gluniform3f(pos1_34a, gx+10.0, 20.0, gz-10.0);
			end if;
			gluniform3f(pos2_34a, gx+10.0, 20.0, gz-10.0);
		end if;

	end loop;

--warning:  need to use camera in 3rd person mode:
	gluniform3f(CamPos34a, glfloat(xeye),glfloat(yeye),glfloat(zeye));
	gluniform1i(flevl34a,foglev);
	gluniform1i(fcolr34a,fogclr);


	cyl2lit.Ldraw(rbarrel,vertbuff,uvbuff,normbuff,elembuff);

	--////// draw double cylinder ZPM end ///////////

	glActiveTexture(GL_TEXTURE0);

end rustyZPM;


