	subroutine kvadrat1(v,s,d)	   !spredaj, zadaj
	real v,s,d
	call fglPushMatrix
	call fglTranslatef(0.0, 0.0, d/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglRectf(-s/2, -v/2, s/2, v/2)
	call fglPopMatrix
	end

	subroutine kvadrat2(v,s,d)		!levo, desno
	real v,s,d
	call fglPushMatrix
	call fglTranslatef(0.0, 0.0, s/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglRectf(-d/2, -v/2, d/2, v/2)
	call fglPopMatrix
	end

	subroutine kvadrat3(v,s,d)		!zgoraj, spodaj
	real v,s,d
	call fglPushMatrix
	call fglTranslatef(0.0, 0.0, v/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglRectf(-d/2, -s/2, d/2, s/2)
	call fglPopMatrix
	end

	subroutine kvader(d,s,v,f) 
	real d,s,v,f(3)
	call fglColor3f(f(1), f(2), f(3))
	call fglPushMatrix
	call kvadrat1(v,s,d)
	call fglRotatef(180.0, 0.0, 1.0, 0.0)
	call kvadrat1(v,s,d)
	call fglRotatef(90.0, 0.0, 1.0, 0.0)
	call kvadrat2(v,s,d)
	call fglRotatef(180.0, 0.0, 1.0, 0.0)
	call kvadrat2(v,s,d)
	call fglRotatef(90.0, 1.0, 0.0, 0.0)
	call kvadrat3(v,s,d)
	call fglRotatef(180.0, 1.0, 0.0, 0.0)
	call kvadrat3(v,s,d)
	call fglPopMatrix
	end
 
      subroutine okna(d,s,v)
	include 'GL/fgl.h' 
	real d,s,v
	call fglClear(GL_DEPTH_BUFFER_BIT)
	call fglPushMatrix 
	call fglColor3f(0.0, 0.0, 0.0)
	if(d.ge.s) then
		call fglTranslatef(-(0.2*s), 0.0, d/2)
		call fglRectf(-(0.1*s), -(0.2*v), (0.1*s), (0.2*v))
		call fglTranslatef((2*s)/5, 0.0, 0.0)
		call fglRectf(-(0.1*s), -(0.2*v), (0.1*s), (0.2*v))
		call fglTranslatef(-s/5, -0.2*v, -d/2) 
		call fglRotatef(-90.0, 0.0, 1.0, 0.0)
		call fglTranslatef(d/5, 0.0, s/2)
		call fglRectf(-(0.1*d), -(0.3*v), (0.1*d), (0.3*v))
		call fglTranslatef(-(2*d)/5, 0.2*v, 0.0)
		call fglRectf(-(0.1*d), -(0.1*v), (0.1*d), (0.1*v))
	else
		call fglTranslatef(s/5, -0.2*v, d/2)
		call fglRectf(-(0.1*s), -(0.3*v), (0.1*s), (0.3*v))
		call fglTranslatef(-(2*s)/5, 0.2*v, 0.0)
		call fglRectf(-(0.1*s), -(0.1*v), (0.1*s), (0.1*v))
		call fglTranslatef(s/5, 0.0, -d/2)
		call fglRotatef(-90.0, 0.0, 1.0, 0.0)
		call fglTranslatef(-(0.2*d), 0.0, s/2)
		call fglRectf(-(0.1*d), -(0.2*v), (0.1*d), (0.2*v))
		call fglTranslatef((2*d)/5, 0.0, 0.0)
		call fglRectf(-(0.1*d), -(0.2*v), (0.1*d), (0.2*v))	
	endif
	call fglPopMatrix
	end


	subroutine copi(x,z,t,alfa,f,k)  !rise cope 
	include 'GL/fgl.h'
	real x,z,t,alfa,f(3),k(3)
	call fglPushMatrix
	call fglTranslatef(0.0, t, 0.0)
     	call fglBegin(GL_TRIANGLES)
	call fglColor3f(k(1), k(2), k(3))
	call fglVertex3f(0.0, 0.0, 0.4*z)
	call fglVertex3f(-0.5*x*cos(alfa), -(0.5*x*sin(alfa)), 3*z/5)
	call fglVertex3f(0.5*x*cos(alfa), -(0.5*x*sin(alfa)), 3*z/5)
	call fglEnd
	call fglBegin(GL_POLYGON)
	call fglClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT)
	call fglColor3f(f(1), f(2), f(3))
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglVertex3f(-0.5*x*cos(alfa), -(0.5*x*sin(alfa)), z/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglVertex3f(0.5*x*cos(alfa), -(0.5*x*sin(alfa)), z/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglVertex3f(x*cos(alfa), -x*sin(alfa), z/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglVertex3f(-x*cos(alfa), -x*sin(alfa), z/2)
	call fglend
	call fglRotatef(180.0, 0.0, 1.0, 0.0)  
	call fglBegin(GL_TRIANGLES)
	call fglColor3f(k(1), k(2), k(3))
	call fglVertex3f(0.0, 0.0, 0.4*z)
	call fglVertex3f(-0.5*x*cos(alfa), -(0.5*x*sin(alfa)), 3*z/5)
	call fglVertex3f(0.5*x*cos(alfa), -(0.5*x*sin(alfa)), 3*z/5)
	call fglEnd
	call fglBegin(GL_POLYGON)
	call fglClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT)
	call fglColor3f(f(1), f(2), f(3))
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglVertex3f(-0.5*x*cos(alfa), -(0.5*x*sin(alfa)), z/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglVertex3f(0.5*x*cos(alfa), -(0.5*x*sin(alfa)), z/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglVertex3f(x*cos(alfa), -x*sin(alfa), z/2)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglVertex3f(-x*cos(alfa), -x*sin(alfa), z/2)
	call fglEnd
	call fglPopMatrix
	call fglflush
	end

	subroutine veckotnik(x,z,p,k)
	include 'GL/fgl.h'
	real x,z,p,k(3) 	 
	call fglBegin(GL_POLYGON)
	call fglColor3f(k(1), k(2), k(3))
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglvertex2f(-3*z/5, -p )
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglvertex2f(-3*z/5, -0.5*x)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglvertex2f(-0.4*z, 0.0)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglvertex2f(0.4*z, 0.0)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglvertex2f(3*z/5, -0.5*x)
	call fglNormal3f(0.0, 0.0, 1.0)
	call fglvertex2f(3*z/5, -p  )
	call fglEnd
	call fglFlush
	end


	subroutine streha(d,s,v,f,k)
	parameter(pi=3.141592654) 
	real p,t,x,h,alfa,fi,ro,f(3),k(3)
        alfa=pi/6                             !kot naklona strehe v radianih 
	call fglPushMatrix
	if(d.ge.s)then
		x=((0.5*s)/cos(alfa))
		p=1.2*x
		h=(s/2)*tan(alfa)
		t=(v/2)+h
		fi=(2*alfa*180)/pi
		ro=((pi/2)-alfa)*(180/pi)
		call fglRotatef(90.0, 0.0, 1.0, 0.0)  
		call fglTranslatef(0.0, t, 0.0)
		call fglRotatef(-ro, 1.0, 0.0, 0.0)
		call veckotnik(x,d,p,k)
		call fglRotatef(-fi, 1.0, 0.0, 0.0)
		call veckotnik(-x,d,-p,k)	
		call fglPopMatrix
		call copi(x,d,t,alfa,f,k)

	else
		x=((0.5*d)/cos(alfa))
		p=1.2*x
		h=(d/2)*tan(alfa)
		t=(v/2)+h
		fi=(2*alfa*180)/pi
		ro=((pi/2)-alfa)*(180/pi)  
		call fglTranslatef(0.0, t, 0.0)
		call fglRotatef(-ro, 0.1, 0.0, 0.0)
		call veckotnik(x,s,p,k)  
		call fglRotatef(-fi, 1.0, 0.0, 0.0)
		call veckotnik(-x,s,-p,k) 
		call fglPopMatrix
		call fglRotatef(-90.0, 0.0, 1.0, 0.0)
		call copi(x,s,t,alfa,f,k) 	
	endif
	call fglPopMatrix
	call fglFlush
	end 
 
	subroutine hisa(d,s,v,f,k)	! izhodiscna tocka koordinatnega
      implicit none                   ! sistema je v teziscu osnovnega kvadra
	include 'GL/fgl.h'
	real d,s,v,f(3),k(3)	
	call fglPushMatrix	
	call streha(d,s,v,f,k) 
	call kvader(d,s,v,f)
	call okna(d,s,v)  
	call fglPopMatrix 
	end 


	subroutine display
	implicit none
	include 'GL/fgl.h'
	real d,s,v,f(3),k(3),w
	data d /1/, s /1/, v /1/		! dolzina, sirina, visina hise
	data f /0,0,1/, k /1,0,0/	    ! barva fasade: f(r,g,b) in barva kritine: k(r,g,b)
	call fglPushMatrix
	call fglClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT)
	w=max(d,s,v)
	call fglScalef(1/w, 1/w, 1/w) 		! Skaliranje modela na velikost okna (1,1,1)
	call hisa(d,s,v,f,k)
	call fglPopMatrix 
	call fglFlush
	end

	subroutine reshape(w, h)
	include 'GL/fgl.h'
	implicit none
	common /viewport/ width, height
	integer w, h
	integer width, height 
	real*8 left, right, bottom, top, znear, zfar
        width=w
	height=h 
	if(w.ge.h) then
		left=-width/(1.0*height)
		right=width/(1.0*height)
		bottom=-1.0
		top=1.0
	else
		left=-1.0
		right=1.0
		bottom=-height/(1.0*width)
		top=height/(1.0*width)
	endif
	znear = -1.0
	zfar = 1.0
	call fglViewPort(0, 0, width, height)
	call fglMatrixMode(GL_PROJECTION)
	call fglLoadIdentity
	call fglOrtho(left,right,bottom,top,znear,zfar)
	call fglMatrixMode(GL_MODELVIEW)
	call fglLoadIdentity  	
	call fglRotatef(30.0, 1.0, 0.0, 0.0)
	call fglRotatef(30.0, 0.0, 1.0, 0.0)
	end

	program hisa s copi  
	external display
	external reshape
	include 'GL/fglut.h'
	include 'GL/fgl.h'
	integer window,t
	call fglutinit
	call fglutInitDisplayMode(GLUT_SINGLE + GLUT_DEPTH + GLUT_RGB)
	window=fglutCreateWindow('Fortran GLUT program')
	call fglutDisplayFunc(display)
	call fglutReshapeFunc(reshape)
	call fglEnable(GL_DEPTH_TEST)
	call fglEnable(GL_LIGHTING)
	call fglEnable(GL_LIGHT0)
	call fglEnable(GL_COLOR_MATERIAL)
	call fglClearColor(1.0, 1.0, 1.0, 1.0)
	call fglutmainloop 
	end
	 
													
