
--
-- Copyright (C) 2023  <fastrgv@gmail.com>
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You may read the full text of the GNU General Public License
-- at <http://www.gnu.org/licenses/>.
--



separate (avent)

procedure draw_temple is

	xeye,yeye,zeye: float;
begin
	if thirdPerson then
		xeye:=xcam; yeye:=ycam; zeye:=zcam;
	else
		xeye:=xme; yeye:=yme; zeye:=zme;
	end if;



--////////////// begin draw cube-mapped skybox ///////////////////

		glUseProgram(pidskyb01);
		glUniform1i(flevid01, 0); --extfoglev);
		glUniform1i(fcolid01, 3); --extfogclr);
		glUniform1i(mapid01, 0);
		glUniformMatrix4fv(mvpid01, 1, GL_FALSE, mmvp(1,1)'address);
		glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

		--glBindTexture(GL_TEXTURE_CUBE_MAP, mooncubemap_texid);
		--glBindTexture(GL_TEXTURE_CUBE_MAP, darkcubemap_texid);
		--glBindTexture(GL_TEXTURE_CUBE_MAP, sunnycubemap_texid);
		glBindTexture(GL_TEXTURE_CUBE_MAP, tropicalcubemap_texid);
		cubemapobj.Draw(skybox, vertbuff,elembuff);

--////////////// end draw cube-mapped skybox /////////////////////





		--for normal textured objects (now with lighting option):
		glUseProgram( pidtex05 );

gluniform1i(eawe05,0);
gluniform1i(noso05,0);


		gluniform3f(eyeid05, glfloat(xeye),glfloat(yeye),glfloat(zeye) );

		gluniformmatrix4fv( mvpid05, 1, gl_false, imvp(1,1)'address );

		gluniform1i(sampid05,0);

		--fog should be level 1 or 0
		if chapter=1 then
			glUniform1i(darkid05, darkness4); --3
			gluniform1i(flevid05, foglev4 ); --1
			gluniform1i(fcolid05, fogclr4 ); --3
		else --chapter 3
			gluniform1i(darkid05, darkness4+1); --4
			gluniform1i(flevid05, foglev4-1); --0 (was 3) 
			gluniform1i(fcolid05, 4 ); 
		end if;

		--gluniform3f(lColrid05, 123.0/255.0, 108.0/255.0, 6.0/255.0 ); --gold
		gluniform3f(lColrid05, 123.0/255.0, 116.0/255.0, 60.0/255.0 ); --lighter
		gluniform1f(lspcid05, 0.5); --fracMspc (dflt=0.1)

		gluniform3f(lposid052, +0.9, -2.4, 9.87 );
		gluniform3f(lposid051, -0.9, -2.4, 9.87 ); --2 torches

		if drawchalice and schalice=4 and not chaliceheld then
			gluniform1i(lflagid05,3); -- 3 light pos
			gluniform3f(lposid053, 
				glfloat(xchalice),glfloat(ychalice),glfloat(zchalice) );
		elsif chaliceheld then
			gluniform1i(lflagid05,3);
			gluniform3f(lposid053, glfloat(xme),glfloat(yme),glfloat(zme) );
		else
			gluniform1i(lflagid05,2); -- 2 light pos
		end if;


------------------------moved----------------------------------

		glbindtexture(gl_texture_2d, gmarble_texid);

	--when outside temple, these 3 are drawn by M6 
	-- as pillars 1,2 + beam12
	if scene=4 then --only draw when NOT outside temple
		--entry pillars + beam
		cylobj.draw(pillar3, vertbuff,uvbuff,elembuff);
		cylobj.draw(pillar4, vertbuff,uvbuff,elembuff);
		pictobj.draw(beam34, vertbuff,uvbuff,elembuff);
	end if;

		cylobj.draw(pillar5, vertbuff,uvbuff,elembuff);
		cylobj.draw(pillar6, vertbuff,uvbuff,elembuff);
		cylobj.draw(pillar7, vertbuff,uvbuff,elembuff);
		--note: pillar-draw was worse with lighting!
		cylobj.draw(pillar8, vertbuff,uvbuff,elembuff);
		cylobj.draw(pillar9, vertbuff,uvbuff,elembuff);
		cylobj.draw(pillar10, vertbuff,uvbuff,elembuff);


		-- roseQuartz altar:
		glbindtexture(gl_texture_2d, rosequartz_texid);
		pictobj.ldraw(rsafe, vertbuff,uvbuff,normbuff,elembuff);

------------------------moved----------------------------------



		glbindtexture(gl_texture_2d, adobe_texid);
		droomobj.ldraw(tdo,vertbuff,uvbuff,normbuff,elembuff); --lighted room
		--simply omit above draw to imagine how a skybox would appear...

		--Greek key designs
		glbindtexture(gl_texture_2d, wgreekey_texid);
		pictobj.draw(zpwall2, vertbuff,uvbuff,elembuff);
		pictobj.draw(zmwall2, vertbuff,uvbuff,elembuff);
		pictobj.draw(xpwall2, vertbuff,uvbuff,elembuff);
		pictobj.draw(xmwall2, vertbuff,uvbuff,elembuff);

		--ZP mural
		glbindtexture(gl_texture_2d, mural_texid);
		pictobj.ldraw(zpmural, vertbuff,uvbuff,normbuff,elembuff);

		--XP mural
		glbindtexture(gl_texture_2d, mural2_texid);
		pictobj.ldraw(xpmural, vertbuff,uvbuff,normbuff,elembuff);

		--XM mural
		glbindtexture(gl_texture_2d, mural3_texid);
		pictobj.ldraw(xmmural, vertbuff,uvbuff,normbuff,elembuff);





		--floor (only needed if different than walls)
		glbindtexture(gl_texture_2d, gmarble_texid);
		--rectobj.ldraw(tfloor, vertbuff,uvbuff,normbuff,elembuff);
		rectobj.draw(tfloor, vertbuff,uvbuff,elembuff);

		--NOTE: lighting effects look bad on marble ceiling/floor!

		--ceiling (only needed if different than walls)
		glbindtexture(gl_texture_2d, gmarble_texid);
		--rectobj.ldraw(rceil, vertbuff,uvbuff,normbuff,elembuff);
		rectobj.draw(rceil, vertbuff,uvbuff,elembuff);



		if not gkeyheld and sgkey=4  then
			glbindtexture(gl_texture_2d, gkey_texid);
			pictobj.draw(key3, vertbuff,uvbuff,elembuff);
		end if;


		if not bkeyheld and sbkey=4 and not bathasbkey then
			glbindtexture(gl_texture_2d, bkey_texid);
			pictobj.draw(key2, vertbuff,uvbuff,elembuff);
		end if;

		if not wkeyheld and swkey=4 and not bathaswkey then
			glbindtexture(gl_texture_2d, key_texid);
			pictobj.draw(key1, vertbuff,uvbuff,elembuff);
		end if;

		if not swordheld and ssword=4 then
			glbindtexture(gl_texture_2d, sword_texid);
			pictobj.draw(sword, vertbuff,uvbuff,elembuff);
		end if;

		if not gateheld and sgate=4  and kgate=0 then
			glbindtexture(gl_texture_2d, frame_texid);
			pictobj.draw(gateway, vertbuff,uvbuff,elembuff);
		end if;


-----------------------------------------------------------------


	if drawchalice and schalice=4 and not chaliceheld then
	-- use uniforms to set position
		glUseProgram(pidcup06);

		gluniform1i(lFlagid06, 1 ); --1 light source
		glUniform1f(hangid06, 0.0);
		gluniform3f(lColrid06, 246.0/255.0, 216.0/255.0, 11.0/255.0 ); --gold
		gluniform3f(lPosid06, glfloat(xchalice),glfloat(ychalice),glfloat(zchalice) );

		gluniform3f(eyeid06, glfloat(xeye),glfloat(yeye),glfloat(zeye) );




		glUniformMatrix4fv(mvpid06, 1, GL_FALSE, imvp(1,1)'address);
		glUniform1i(sampid06, 0);
		glUniform1i(darkid06, 0);
		glUniform3f(cenid06, glfloat(xchalice),glfloat(ychalice),glfloat(zchalice) );
		glUniform3f(radid06, glfloat(wcup), glfloat(hcup), glfloat(wcup) );

		gluniform1i(flevid06, 0); --foglev4 ); 
		gluniform1i(fcolid06, 0); --fogclr4 ); 

		glbindtexture(gl_texture_2d, chalice_texid);
		xtreeobj.ldraw(chalice, vertbuff,uvbuff,normbuff,elembuff);

	end if;



	if scene=4 then
		showWhatIsHeld;
	end if;



	--torch-handle: -------------------------------------------------
	glUseProgram( pidztube04 );

	gluniformmatrix4fv(mvpid04z, 1, gl_false, imvp(1,1)'address );
	gluniform1i(sampid04z,0);

	--gluniform1f(vanglid04z, -fourthpi); --FS test only

	glbindtexture(gl_texture_2d, cherry_texid);

	glUniform3f(cenID04z, -0.9, -2.75, 10.0 );
	shortube.draw( torch, vertbuff,uvbuff,elembuff );

	glUniform3f(cenID04z, +0.9, -2.75, 10.0 );
	shortube.draw( torch, vertbuff,uvbuff,elembuff );

--=================================================================

	--torch-fire: -------------------------------------------------
	glUseProgram(pidtorch04);
	glUniform3f(ieye04, glfloat(xeye), glfloat(yeye), glfloat(zeye));
	glUniform1f(radid04f, 0.08); --wRad
	gluniformmatrix4fv( mvpid04f, 1, gl_false, IMVP(1,1)'address );

	fireobj.update(fire, 1.5, float(currenttime) );

	glUniform1i(sampid04, 0);
	glBindTexture(GL_TEXTURE_2D, ball_texid); --only used by FS


	glUniform3f(cenid04f, +0.9, -2.40, 9.87 ); --wPos
	fireobj.draw(fire,vertbuff,elembuff);


	glUniform3f(cenid04f, -0.9, -2.40, 9.87 ); --wPos
	fireobj.draw(fire,vertbuff,elembuff);




end draw_temple;


