fortran66のブログ

fortran について書きます。

色付き四角

MODULE m_callback
USE opengl_gl
USE opengl_glut
IMPLICIT NONE
INTEGER(GLCINT), PARAMETER :: KEY_ESC = 27
CONTAINS
!---------------------------
SUBROUTINE display()
IMPLICIT NONE
CALL glClear( GL_COLOR_BUFFER_BIT )
CALL glBegin( GL_POLYGON )
 CALL glColor3f ( 1.0_glfloat,  0.0_glfloat, 0.0_glfloat)
 CALL glVertex3f( 0.5_glfloat,  0.5_glfloat, 0.0_glfloat)
 CALL glColor3f ( 1.0_glfloat,  1.0_glfloat, 0.0_glfloat)
 CALL glVertex3f(-0.5_glfloat,  0.5_glfloat, 0.0_glfloat)
 CALL glColor3f ( 0.0_glfloat,  1.0_glfloat, 0.0_glfloat)
 CALL glVertex3f(-0.5_glfloat, -0.5_glfloat, 0.0_glfloat)
 CALL glColor3f ( 0.0_glfloat,  0.0_glfloat, 1.0_glfloat)
 CALL glVertex3f( 0.5_glfloat, -0.5_glfloat, 0.0_glfloat)
CALL glEnd()
CALL glFlush()
RETURN
END SUBROUTINE display
!---------------------------
SUBROUTINE myKbd(key, ix, iy)
IMPLICIT NONE
INTEGER(GLCINT), INTENT(IN OUT) :: key, ix, iy
IF (key == KEY_ESC) STOP
RETURN
END SUBROUTINE myKbd
!---------------------------
END MODULE m_callback
!=========================================================
MODULE m_subs
USE m_callback
IMPLICIT NONE
CONTAINS
!---------------------------
SUBROUTINE myInit(progname)
IMPLICIT NONE
CHARACTER(LEN = *), INTENT(IN) :: progname
INTEGER(GLCINT) :: iwidth = 500, iheight = 500
INTEGER(GLCINT) :: iwin
CALL glutInitWindowPosition( 0_glfloat, 0_glfloat )
CALL glutInitWindowSize( iwidth, iheight )
CALL glutInitDisplayMode( GLUT_RGBA )
iwin = glutCreateWindow( progname )
CALL glClearColor( 0.0_glfloat, 0.0_glfloat, 0.0_glfloat, 1.0_glfloat )
CALL glutKeyboardFunc( myKbd )
!
CALL glMatrixMode( GL_PROJECTION )
CALL glLoadIdentity()
CALL glOrtho( -1.0_gldouble, 1.0_gldouble, -1.0_gldouble, &
               1.0_gldouble, -1.0_gldouble, 1.0_gldouble )
RETURN
END SUBROUTINE myInit
!---------------------------
END MODULE m_subs
!=========================================================
PROGRAM GLUT1
USE m_subs
IMPLICIT NONE
CALL glutInit()
CALL myInit("GLUT1")
CALL glutDisplayFunc( display )
CALL glutMainLoop()
STOP
END PROGRAM GLUT1