
--
-- Copyright (C) 2024  <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_scene3 is

	hwdoor : constant float := 0.8;
	fhdoor : constant float := 1.8;

	xeye,yeye,zeye: float;

	near_success : constant boolean := (schalice/=9) or chaliceheld;

begin


	if thirdperson then
		xeye:=xcam; yeye:=ycam; zeye:=zcam;
	else
		xeye:=xme; yeye:=yme; zeye:=zme;
	end if;



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

--Only need one skybox to be drawn, not both, for chasm3/maze7...
--BUT, sky needs to be drawn BEFORE the [transparent] horns !!!
--if scene=3 then
		glUseProgram(pidskyb01);
		glUniform1i(flevid01, 0); --extfoglev);
		glUniform1i(fcolid01, 1); --extfogclr);
		glUniform1i(mapid01, 0);
		glUniformMatrix4fv(mvpid01, 1, GL_FALSE, mmvp(1,1)'address);
		glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);

		--Sync with M7 skybox & exterior:
		if near_success then
			glBindTexture(GL_TEXTURE_CUBE_MAP, mooncubemap_texid);
		else
			--glBindTexture(GL_TEXTURE_CUBE_MAP, cloudycubemap_texid);
			glBindTexture(GL_TEXTURE_CUBE_MAP, darkcubemap_texid);
		end if;
		cubemapobj.Draw(skybox, vertbuff,elembuff);
--end if;

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







	--for normal textured objects:
	glUseProgram( pidtex05 );

	--(see texobjShine.fs):
	if scene=3 then
		myassert( (eawe=1 or eawe=13), 8888, "chasm3 draw eawe");
	end if;

	gluniform1i(ndc05,ndc3);
	gluniform1i(eawe05,eawe);
	gluniform1i(noso05,0);
	gluniform1fv(xdc05,ndc3,xdc3(1)'address);
	gluniform1fv(zdc05,ndc3,zdc3(1)'address);


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


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

	gluniform1i(sampid05,0);
	glUniform1i(darkid05, 2);

	gluniform1i(flevid05, 0 ); --roomWallsFloor
	gluniform1i(fcolid05, 1 ); 

-- instead of 2 lines below, try a room without YP,ZM,ZP walls
	--glbindtexture(gl_texture_2d, roots_texid);
	--droomobj.draw(mdo3,vertbuff,uvbuff,elembuff); --textured room

-- here try a room without YP,ZM,ZP walls
	glbindtexture(gl_texture_2d, bmarble_texid);
	--glbindtexture(gl_texture_2d, wstone_texid);
	droomobj.draw(mdo3,vertbuff,uvbuff,elembuff); --textured room

	glbindtexture(gl_texture_2d, gmarble_texid); --darker grey marble
	cylobj.draw(pillar15,vertbuff,uvbuff,elembuff); --L8
	cylobj.draw(pillar16,vertbuff,uvbuff,elembuff); --L8
	--cylobj.draw(pillar17,vertbuff,uvbuff,elembuff); --M7
	--cylobj.draw(pillar18,vertbuff,uvbuff,elembuff); --M7

	rectobj.draw(cap1,vertbuff,uvbuff,elembuff); --L8
	rectobj.draw(cap2,vertbuff,uvbuff,elembuff); --L8
	--rectobj.draw(cap3,vertbuff,uvbuff,elembuff); --M7
	--rectobj.draw(cap4,vertbuff,uvbuff,elembuff); --M7

	glbindtexture(gl_texture_2d, wstone_texid);
	pictobj.draw(facade,vertbuff,uvbuff,elembuff); --m7 facade

	--glbindtexture(gl_texture_2d, wgreekey_texid); --white bkgd
	glbindtexture(gl_texture_2d, greekey_texid);
	pictobj.draw(greek,vertbuff,uvbuff,elembuff);

	glbindtexture(gl_texture_2d, minoanHorns_texid);
	pictobj.draw(horns,vertbuff,uvbuff,elembuff);


	--floor
	--glbindtexture(gl_texture_2d, slime_texid); -- nice slime!
	--glbindtexture(gl_texture_2d, stone_texid); --
	glbindtexture(gl_texture_2d, bmarble_texid); --
	rectobj.draw(cfloorf, vertbuff,uvbuff,elembuff);
	rectobj.draw(cfloorl, vertbuff,uvbuff,elembuff);
	rectobj.draw(cfloorr, vertbuff,uvbuff,elembuff);

	rectobj.draw(cfloorzm, vertbuff,uvbuff,elembuff);
	rectobj.draw(cfloorzp, vertbuff,uvbuff,elembuff);


	glbindtexture(gl_texture_2d, slime3_texid); --
	rectobj.draw(cfloorb, vertbuff,uvbuff,elembuff);


	--doors
	glbindtexture(gl_texture_2d, doort_texid);
	pictobj.draw(g3, vertbuff,uvbuff,elembuff);
	pictobj.draw(h3, vertbuff,uvbuff,elembuff);


	--exit sign (back to M7)
	--glbindtexture(gl_texture_2d, bexit_texid);
	--pictobj.draw(eh3, vertbuff,uvbuff,elembuff);


	glbindtexture(gl_texture_2d, blab_texid); --labyrinth sign
	pictobj.draw(lh3, vertbuff,uvbuff,elembuff);


	glbindtexture(gl_texture_2d, cherry_texid);
	punobj.draw(pun3a,vertbuff,uvbuff,elembuff);
	punobj.draw(pun3b,vertbuff,uvbuff,elembuff);
	punobj.draw(pun3c,vertbuff,uvbuff,elembuff);
	punobj.draw(pun3d,vertbuff,uvbuff,elembuff);
	punobj.draw(pun3e,vertbuff,uvbuff,elembuff);
	punobj.draw(pun3f,vertbuff,uvbuff,elembuff);


	glbindtexture(gl_texture_2d, path2_texid); --invisible foot path
	rectobj.draw(cfloors, vertbuff,uvbuff,elembuff);





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


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

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

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



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

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

			gluniform1i(lFlagid06, 1 ); --light effects; 1 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); --darkness8);
			glUniform3f(cenid06, glfloat(xchalice),glfloat(ychalice),glfloat(zchalice) );
			glUniform3f(radid06, glfloat(wcup), glfloat(hcup), glfloat(wcup) );

			gluniform1i(flevid06, 0); --foglev8 ); 
			gluniform1i(fcolid06, 0); --fogclr8 ); 

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

		end if;


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



		if scene=3 then
			showWhatIsHeld;
		end if;


end draw_scene3;


