c ===============================
        subroutine pretvori_geom_model_v_GL_gradnike

	include 'fgl.h'

        integer p(5,4)
        real t(8, 3), n(5,3)

        integer i,j

        common /geometrija/ t, p, n

        do 10 i=5,1,-1
          call fglBegin(GL_QUADS)
            do 20 j=1,4
              call fglNormal3f( n(i,1),n(i,2),n(i,3))
              call fglVertex3f(
     *         t(p(i,j), 1), t(p(i,j), 2), t(p(i,j), 3) )
20          continue
          call fglEnd
10	continue

        return
        end
c ===============================
	subroutine risi

	include 'fgl.h'
	include 'fglut.h'	

        real fi_x, fi_y

        common /rotacije  / fi_x, fi_y

        data fi_x/30.0/, fi_y/-30.0/

	call fglClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT)
	call fglColor3f(1.0, 0.4, 1.0)

	call fglLoadIdentity
	call fglScalef(0.5, 0.5, 0.5)
        call fglRotatef(fi_x, 1.0, 0.0, 0.0)
        call fglRotatef(fi_y, 0.0, 1.0, 0.0)

        call pretvori_geom_model_v_GL_gradnike

        call fglutSwapBuffers
	return
	end
c ===============================
	subroutine miska(x, y)

	include 'fglut.h'	
	include 'fgl.h'	

        integer x, y

        integer stari_x, stari_y

        real fi_x, fi_y

        common /rotacije/ fi_x, fi_y

        save stari_x, stari_y

        data stari_x /0/, stari_y/0/

        if (x .gt. stari_x) fi_y = fi_y + 1.0
        if (x .lt. stari_x) fi_y = fi_y - 1.0
        if (y .gt. stari_y) fi_x = fi_x + 1.0
        if (y .lt. stari_y) fi_x = fi_x - 1.0

	stari_x = x
	stari_y = y

	call fglutPostRedisplay
	return
	end	

c ===============================
        subroutine izdelaj_geom_model

	real tocke(8, 3), normale(5,3)
        integer ploskve(5,4)
        common /geometrija/ tocke, ploskve, normale


	data tocke   / -0.5, 0.5, 0.5,-0.5,-0.5, 0.5, 0.5,-0.5, 
     *                 -0.5,-0.5, 0.5, 0.5,-0.5,-0.5, 0.5, 0.5,
     *                 -0.8,-0.8,-0.8,-0.8, 0.8, 0.8, 0.8, 0.8 / 
	data ploskve / 1, 5, 6, 1, 1,
     *                 4, 6, 2, 5, 2,
     *                 3, 7, 3, 8, 6,
     *                 2, 8, 7, 4, 5 /
	data normale / 0.0, 0.0, 1.0,-1.0, 0.0,
     *                 0.0, 0.0, 0.0, 0.0,-1.0,
     *                -1.0, 1.0, 0.0, 0.0, 0.0 /

        return
        end
c ===============================
        subroutine inicializiraj_gl

        include 'fgl.h'

        real*8 a

        a = 1.0
	call fglEnable(GL_LIGHTING)
	call fglEnable(GL_LIGHT0)
	call fglEnable(GL_DEPTH_TEST)
	call fglEnable(GL_COLOR_MATERIAL)
        call fglLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE)
        call fglMatrixMode(GL_PROJECTION)
        call fglLoadIdentity
        call fglOrtho(-a,a, -a,a, -a,a)
        call fglMatrixMode(GL_MODELVIEW)
        call fglLoadIdentity

        return
        end
c ===============================
	program glavni

	implicit none

	external risi
	external miska

	include 'fglut.h'	

        integer moje_okno

        call izdelaj_geom_model


	call fglutInit
        call fglutInitWindowSize(500, 500)
        call fglutInitDisplayMode(GLUT_DOUBLE+GLUT_DEPTH)
        moje_okno = fglutCreateWindow('risi_miska')

        call inicializiraj_gl

	call fglutDisplayFunc(risi)
	call fglutMotionFunc(miska)

	call fglutMainLoop

	stop
	end	


		
