fortran66のブログ

fortran について書きます。

  • ネタ元

http://www.dolfyn.net/dolfyn/f03gl_en.html

いわゆる Green Book からのサンプルのつづき。
元プログラムからの修正点は、RESHAPE ルーチンの引数の value 属性を消したこと。

module fgl08m

  use opengl_gl

  integer(kind=GLint)  :: winWidth = 300, winHeight = 300

end module fgl08m
program fgl08

  use opengl_gl
  use opengl_glu
  use opengl_glut
    
  use fgl08m
  
  interface 
    subroutine display()
    end subroutine display

    subroutine reshape(w,h)
      use opengl_gl
      integer(glcint), intent(in) :: w,h
    end subroutine reshape

    subroutine mouse(b,a,x,y)
      use OpenGL_GL
      integer(GLint), intent(in) :: b,a,x,y
    end subroutine mouse
  end interface 

  integer(kind=GLint) :: iwin
    
  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 100, 100)
  call glutInitWindowSize( winWidth, winHeight )
  iwin = glutCreateWindow("fgl08 Mouse droppings"//char(0))

  call glClearColor(0.0,0.0,0.0,0.0)

  call glMatrixMode(GL_PROJECTION)

  call gluOrtho2D( 0.0_gldouble,  150.0_gldouble, &
                   0.0_gldouble,  150.0_gldouble  )
  
  call glutMouseFunc( mouse )
  call glutDisplayFunc( display )
  call glutReshapeFunc( reshape )

  call glutMainLoop()
  
end program
subroutine display

  use OpenGL_GL

  call glClear(GL_COLOR_BUFFER_BIT)

  call glColor3f(1.0,0.0,0.0)

  call glPointSize(3.0)
  call glFlush()

end subroutine display
subroutine reshape(newWidth, newHeight)

  use OpenGL_GL
  use OpenGL_GLU

  use fgl08m

  integer(kind=GLcint), intent(IN) :: newWidth, newHeight
  real(kind=GLdouble) :: Zero, Width, Height

  Zero   = 0.0
  Width  = newWidth
  Height = newHeight

  call glviewport(0,0,newWidth,newHeight)

  call glMatrixMode(GL_PROJECTION)
  call glLoadIdentity()

  call gluOrtho2D( Zero, Width, Zero, Height )
  
  call glClear(GL_COLOR_BUFFER_BIT)

  winWidth  = newWidth
  winHeight = newHeight
  
end subroutine reshape
subroutine plotpoint(ix,iy)
  
  use OpenGL_GL

  integer(GLint), intent(in) :: ix, iy  
  
  call glBegin(GL_POINTS)
  call glVertex2i(ix,iy)
  call glEnd()
  
end subroutine plotpoint
subroutine mouse( ibutton, iaction, ix, iy )

  use OpenGL_GL
  use OpenGL_GLUT
  use fgl08m

  integer(GLint), intent(in) :: ibutton, iaction, ix, iy  

  if( ibutton == GLUT_LEFT_BUTTON .and. &
      iaction == GLUT_DOWN )then
      
    call plotpoint(ix,winHeight-iy)
  
    call glFlush()
    
  endif
  
end subroutine mouse

DOS窓は略



module fgl09m

  use opengl_gl

  integer(kind=GLint)  :: winWidth = 300, winHeight = 300

  type Point
    integer(kind=GLint) x        
    integer(kind=GLint) y        
  end type

  integer                    :: ip =   0  
  integer, parameter         :: NP = 100  
  type(Point), dimension(NP) :: Pt

end module fgl09m
program fgl09

  use opengl_gl
  use opengl_glu
  use opengl_glut
    
  use fgl09m
  
  interface 
    subroutine display()
    end subroutine display

    subroutine reshape(w,h)
      use opengl_gl
      integer(glcint), intent(in) :: w,h
    end subroutine reshape

    subroutine mouse(b,a,x,y)
      use OpenGL_GL
      integer(GLint), intent(in) :: b,a,x,y
    end subroutine mouse
  end interface 

  integer(kind=GLint) :: iwin
    
  Pt%x = 0
  Pt%y = 0

  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 100, 100)
  call glutInitWindowSize( winWidth, winHeight )
  iwin = glutCreateWindow("fgl09 Mouse trails"//char(0))

  call glClearColor(0.0,0.0,0.0,0.0)

  call glMatrixMode(GL_PROJECTION)

  call gluOrtho2D( 0.0_gldouble,  150.0_gldouble, &
                   0.0_gldouble,  150.0_gldouble  )
  
  call glutMouseFunc( mouse )
  call glutDisplayFunc( display )
  call glutReshapeFunc( reshape )

  call glutMainLoop()
  
end program
subroutine display

  use OpenGL_GL
  use fgl09m

  call glClear(GL_COLOR_BUFFER_BIT)

  if( ip > 1 )then
    do i=2,ip
      call Drawline(Pt(i-1),Pt(i))    
    end do
  endif

  call glFlush()
  
end subroutine display
subroutine reshape(newWidth, newHeight)

  use OpenGL_GL
  use OpenGL_GLU

  use fgl09m

  integer(kind=GLcint), intent(IN) :: newWidth, newHeight
  real(kind=GLdouble) :: Zero, Width, Height

  Zero   = 0.0
  Width  = newWidth
  Height = newHeight

  call glviewport(0,0,newWidth,newHeight)

  call glMatrixMode(GL_PROJECTION)
  call glLoadIdentity()

  call gluOrtho2D( Zero, Width, Zero, Height )
  
  call glClear(GL_COLOR_BUFFER_BIT)

  winWidth  = newWidth
  winHeight = newHeight
  
end subroutine reshape
subroutine drawline( p1, p2 )
  
  use OpenGL_GL
  use fgl09m

  type(Point), intent(in)    :: p1, p2
  
  call glBegin(GL_LINES)
    call glVertex2i(p1%x,p1%y)
    call glVertex2i(p2%x,p2%y)
  call glEnd()
    
end subroutine drawline
subroutine mouse( ibutton, iaction, ix, iy )

  use OpenGL_GL
  use OpenGL_GLUT
  use fgl09m

  integer(GLint), intent(in) :: ibutton, iaction, ix, iy  

  if( ip == 0 )then
    if( ibutton == GLUT_LEFT_BUTTON .and. &
      iaction == GLUT_DOWN )then
      Pt(1)%x = ix
      Pt(1)%y = winHeight - iy
      ip = 1
    else
      if( ibutton == GLUT_RIGHT_BUTTON ) stop 'Done'
    endif
  else
    if( ibutton == GLUT_LEFT_BUTTON .and. &
      iaction == GLUT_DOWN )then
      ip = ip + 1
      Pt(ip)%x = ix
      Pt(ip)%y = winHeight - iy

      call Drawline(Pt(ip-1),Pt(ip))

    else
      if( ibutton == GLUT_RIGHT_BUTTON ) stop 'Done'
    endif
  endif

  call glFlush()
  
end subroutine mouse


  • ネタ元

http://www.dolfyn.net/dolfyn/f03gl_en.html

いわゆる Green Book からのサンプルのつづき。
元プログラムからの修正点は、RESHAPE ルーチンの引数の value 属性を消したこと。C Binding の削除。

program fgl06

  use opengl_gl
  use opengl_glu
  use opengl_glut
    
  interface 
    subroutine polyhedra()
    end subroutine polyhedra

    subroutine reshape(w,h)
      use opengl_gl
      integer(glcint), intent(in) :: w,h
    end subroutine reshape
  end interface 

  integer(kind=GLint)  :: winWidth = 300, winHeight = 300
  integer(kind=GLint) :: iwin

  real(kind=GLdouble) :: x0 = 100.0, y0 = 50.0, z0 = 50.0 ! viewing coor. origin
  real(kind=GLdouble) :: xr =  50.0, yr = 50.0, zr =  0.0 ! look at this point
  real(kind=GLdouble) :: Vx =   0.0, Vy =  1.0, Vz =  0.0 ! view-up vector
  real(kind=GLdouble) :: xwmin = -40.0, ywmin = -60.0, &
                         xwmax =  40.0, ywmax =  60.0, &
                         dnear =  25.0, dfar  = 125.0
    
  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 100, 100)
  call glutInitWindowSize( winWidth, winHeight )
  iwin = glutCreateWindow("fgl06 GLUT Polyhedra"//char(0))

  call glClearColor(1.0,1.0,1.0,0.0)
  
  call glutDisplayFunc( polyhedra )
  call glutReshapeFunc( reshape )

  call glutMainLoop()
  
end program
subroutine polyhedra

  use OpenGL_GL
  use OpenGL_GLU
  use OpenGL_GLUT

  call glClear(GL_COLOR_BUFFER_BIT)

  call glLoadIdentity()
  
  call glColor3f(0.0,0.0,1.0)

  call gluLookAt( 5.0_gldouble, 5.0_gldouble, 5.0_gldouble, &
                  0.0_gldouble, 0.0_gldouble, 0.0_gldouble, &
                  0.0_gldouble, 1.0_gldouble, 0.0_gldouble  )

  call glScalef( 1.5, 2.0, 1.0 )
  call glutWirecube( 1.0_gldouble ) 

  call glColor3f(0.0,1.0,1.0)

  call glScalef( 0.8, 0.5, 0.8 )
  call glTranslatef( -6.0, -5.0, 0.0 )
  call glutWireDodecahedron( ) 

  call glColor3f(1.0,0.0,1.0)

  call glTranslatef( 8.6, 8.6, 2.0 )
  call glScalef( 0.75, 0.75, 0.75 )
  call glutWireTetrahedron( ) 
  call glScalef( 1.333, 1.333, 1.333 )

  call glColor3f(1.0,0.0,0.0)

  call glTranslatef( -3.0, -1.0, 0.0 )
  call glutWireOctahedron( ) 

  call glColor3f(0.0,0.0,0.0)

  call glScalef( 0.8, 0.8, 1.0 )
  call glTranslatef( 4.3, -2.0, 0.5 )
  call glutWireIcosahedron( ) 
  
  call glFlush()

end subroutine polyhedra
subroutine reshape(newWidth, newHeight)

  use OpenGL_GL

  integer(kind=GLcint), intent(IN) :: newWidth, newHeight

  call glviewport(0,0,newWidth,newHeight)

  call glMatrixMode(GL_PROJECTION)
  
  call glLoadIdentity()

  call glFrustum( -1.0_gldouble,  1.0_gldouble, &
                  -1.0_gldouble,  1.0_gldouble, &
                   2.0_gldouble, 20.0_gldouble  )
  
  call glMatrixMode(GL_MODELVIEW)
  
  call glClear(GL_COLOR_BUFFER_BIT)
  
end subroutine reshape

DOS窓は略


  • f03gl と f90gl での定義の違いの修正。
!  type(C_PTR) :: ptr = c_null_ptr 
  TYPE (GLUQuadricObj), POINTER :: ptr
  ptr => gluNewQuadric() 
program fgl07

  use opengl_gl
  use opengl_glu
  use opengl_glut
    
  interface 
    subroutine quadrics()
    end subroutine quadrics

    subroutine reshape(w,h)
      use opengl_gl
      integer(glcint), intent(in) :: w,h
    end subroutine reshape
  end interface 

  integer(kind=GLint) :: winWidth = 300, winHeight = 300
  integer(kind=GLint) :: iwin
    
  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 100, 100)
  call glutInitWindowSize( winWidth, winHeight )
  iwin = glutCreateWindow("fgl07 Quadric Surfaces"//char(0))

  call glClearColor(1.0,1.0,1.0,0.0)
  
  call glutDisplayFunc( quadrics )
  call glutReshapeFunc( reshape )

  call glutMainLoop()
  
end program

subroutine quadrics
  USE, INTRINSIC :: ISO_C_BINDING
  use OpenGL_GL
  use OpenGL_GLU
  use OpenGL_GLUT

!  type(C_PTR) :: ptr = c_null_ptr 
  TYPE (GLUQuadricObj), POINTER :: ptr

  call glClear(GL_COLOR_BUFFER_BIT)
  
  call glLoadIdentity()

  call glColor3f(0.0,0.0,1.0)

  call gluLookAt( 2.0_gldouble, 2.0_gldouble, 2.0_gldouble, &
                  0.0_gldouble, 0.0_gldouble, 0.0_gldouble, &
                  0.0_gldouble, 0.0_gldouble, 1.0_gldouble  )

  call glPushMatrix()
  call glTranslatef( 1.0, 1.0, 0.0 )
  call glutWireSphere( 0.75_gldouble, 8, 6 ) 
  call glPopMatrix()

  call glPushMatrix()
  call glTranslatef( 1.0, -0.5, 0.5 )
  call glutWireCone( 0.7_gldouble, 2.0_gldouble, 7, 6 ) 
  call glPopMatrix()

  call glPushMatrix()
  call glTranslatef( 0.0, 1.2, 0.8 )

  ptr => gluNewQuadric()
  call gluQuadricDrawStyle(ptr, GLU_LINE)
  call gluCylinder(ptr,0.6_gldouble,0.6_gldouble,1.5_gldouble,6,4)

  call glPopMatrix()

  call glFlush()

end subroutine quadrics
subroutine reshape(newWidth, newHeight)

  use OpenGL_GL

  integer(kind=GLcint), intent(IN) :: newWidth, newHeight

  call glviewport(0,0,newWidth,newHeight)

  call glMatrixMode(GL_PROJECTION)
  
  call glLoadIdentity()

  call glOrtho( -2.0_gldouble,  2.0_gldouble, &
                -2.0_gldouble,  2.0_gldouble, &
                 0.0_gldouble,  5.0_gldouble  )
  
  call glMatrixMode(GL_MODELVIEW)
  
  call glClear(GL_COLOR_BUFFER_BIT)
  
end subroutine reshape

  • ネタ元

http://www.dolfyn.net/dolfyn/f03gl_en.html

いわゆる Green Book からのサンプルのつづき。
元プログラムからの修正点は、RESHAPE ルーチンの引数の value 属性を消したこと。C binding を消したこと。

program fgl04

  use opengl_gl
  use opengl_glu
  use opengl_glut
  
  interface 
    subroutine graph()
    end subroutine graph

    subroutine reshape(w,h)
      use opengl_gl
      integer(glcint), intent(in) :: w,h
    end subroutine reshape
  end interface 

  integer(kind=GLint) :: winWidth = 600, winHeight = 400
  integer(kind=GLint) :: iwin
  
  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 100, 100)
  call glutInitWindowSize( winWidth, winHeight )
  iwin = glutCreateWindow("fgl04 Line chart data"//char(0))

  call glClearColor(1.0,1.0,1.0,1.0)
  call glMatrixMode(GL_PROJECTION)
  call gluOrtho2D(0.0_gldouble, 600.0_gldouble, &
                  0.0_gldouble, 400.0_gldouble  )
  
  call glutDisplayFunc( graph )
  call glutReshapeFunc( reshape )

  call glutMainLoop()
  
end program
subroutine graph

  use opengl_gl
  use opengl_glu
  use opengl_glut

  character, dimension(36) :: label =  (/ &
  'J','a','n', 'F','e','b', 'M','a','r', 'A','p','r', &
  'M','a','y', 'J','u','n', 'J','u','l', 'A','u','g', &
  'S','e','p', 'O','k','t', 'N','o','v', 'D','e','c'  /)

  integer(kind=glint) :: xRaster = 25, yRaster =50
  integer(kind=glint) :: month, k, x = 30   
  
  integer(kind=glint), dimension(12) :: data = (/ &
                    420, 342, 324, 310, 262, 185, &
                    190, 196, 217, 240, 312, 438  /)
  
  call glClear(GL_COLOR_BUFFER_BIT)
  
  ! x1, y1 Specify one vertex of a rectangle. 
  ! x2, y2 Specify the opposite vertex of the rectangle
  call glColor3f(1.0,0.0,0.0)
  do i=1,12
    call glRecti(20+(i-1)*50,65,40+(i-1)*50,data(i)-100)
  end do
  
  call glColor3f(0.0,0.0,1.0)
  call glBegin(GL_LINE_STRIP)  
  do i=1,12
    call glVertex2i(x+(i-1)*50,data(i)-100)
  end do
  call GLend()

  call glColor3f(1.0,1.0,0.0)
  xRaster = 25
  do i=1,12
    call glRasterPos2i(xRaster+(i-1)*50,data(i)-4-100)
    call glutBitmapCharacter(GLUT_BITMAP_9_BY_15,iachar('*'))
  end do
  
  call glColor3f(0.0,0.0,0.0)
  xRaster = 20
  do i=1,12
    call glRasterPos2i(xraster,yraster)
    do j=3*(i-1)+1,3*(i-1)+3
      call glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12,iachar(label(j)))
    end do
    xraster=xraster+50
  end do
  
  call glFlush()
  
end subroutine graph
subroutine reshape(newWidth, newHeight)

  use OpenGL_GL
  use OpenGL_GLU

  integer(kind=GLcint), intent(IN) :: newWidth, newHeight
  real(kind=GLdouble) :: Zero, Width, Height

  Zero   = 0.0
  Width  = newWidth
  Height = newHeight

  call glMatrixMode( GL_PROJECTION )
  call glLoadIdentity()
  
  call gluOrtho2D( Zero, Width, Zero, Height )
  
  call glClear( GL_COLOR_BUFFER_BIT )

end subroutine reshape

DOS窓は略


module fgl05mod

  use opengl_gl

  integer(kind=GLint)  :: winWidth = 200, winHeight = 200

end module fgl05mod
program fgl05

  use opengl_gl
  use opengl_glu
  use opengl_glut
  use fgl05mod
    
  interface 
    subroutine square()
    end subroutine square

    subroutine reshape(w,h)
      use opengl_gl
      integer(glcint), intent(in) :: w,h
    end subroutine reshape
  end interface 

  integer(kind=GLint) :: iwin

  real(kind=GLdouble) :: x0 = 100.0, y0 = 50.0, z0 = 50.0 ! viewing coor. origin
  real(kind=GLdouble) :: xr =  50.0, yr = 50.0, zr =  0.0 ! look at this point
  real(kind=GLdouble) :: Vx =   0.0, Vy =  1.0, Vz =  0.0 ! view-up vector
  real(kind=GLdouble) :: xwmin = -40.0, ywmin = -60.0, &
                         xwmax =  40.0, ywmax =  60.0, &
                         dnear =  25.0, dfar  = 125.0
    
  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 100, 100)
  call glutInitWindowSize( winWidth, winHeight )
  iwin = glutCreateWindow("fgl05 Perspective view of a square"//char(0))

  call glClearColor(1.0,1.0,1.0,0.0)
  call glMatrixMode(GL_MODELVIEW)
  call gluLookAt(x0,y0,z0, xr,yr,zr, vx,vy,vz)

  call glMatrixMode(GL_PROJECTION)
  call glFrustum(xwmin,xwmax, ywmin,ywmax, dnear,dfar)
  
  call glutDisplayFunc( square )
  call glutReshapeFunc( reshape )

  call glutMainLoop()
  
end program
subroutine square

  use OpenGL_GL

  call glClear(GL_COLOR_BUFFER_BIT)
  
  call glColor3f(0.0,1.0,0.0)
  call glPolygonMode(GL_FRONT, GL_FILL)
  call glPolygonMode(GL_BACK, GL_LINE)  ! back face wire frame
  call glBegin(GL_QUADS)
    call glVertex3f(  0.0,   0.0, 0.0)
    call glVertex3f(100.0,   0.0, 0.0)
    call glVertex3f(100.0, 100.0, 0.0)
    call glVertex3f(  0.0, 100.0, 0.0)
  call glEnd()
  
  call glFlush()

end subroutine square
subroutine reshape(newWidth, newHeight)

  use OpenGL_GL
  use fgl05mod

  integer(kind=GLcint), intent(IN) :: newWidth, newHeight

  call glviewport(0,0,newWidth,newHeight)
  
  winWidth  = newWidth
  winHeight = newHeight

end subroutine reshape


森の妖精ことビリー・ヘリントン氏の来日がアナウンスされました!
http://anime-ch.nicovideo.jp/static/wonderful_hobby9
楽しみですね。

  • ネタ元

http://www.dolfyn.net/dolfyn/f03gl_en.html

いわゆる Green Book からのサンプルのつづき。
元プログラムからの修正点は、RESHAPE ルーチンの引数の value 属性を消したこと。C binding を消したこと。

module fgl03mod

  use opengl_gl

  integer(kind=GLint)  :: winWidth = 400, winHeight = 300
  integer(kind=GLuint) :: Hexagon

  real :: xc, yc

end module fgl03mod
program fgl03

  use opengl_gl
  use opengl_glu
  use opengl_glut

  use fgl03mod

  interface callbacks
    subroutine draw_hexagon()
    end subroutine draw_hexagon

    subroutine reshape(w,h)
      use opengl_gl
      integer(glcint), intent(in) :: w,h
    end subroutine reshape
  end interface callbacks

  integer(kind=GLint) :: iwin

  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 100, 100)
  call glutInitWindowSize( winWidth, winHeight )
  iwin = glutCreateWindow("fgl03 Reshape and Display lists"//char(0))

  call initialize
  
  call glutDisplayFunc( draw_hexagon )
  call glutReshapeFunc( reshape )

  call glutMainLoop()

end program fgl03
subroutine initialize

  use OpenGL_GL
  use fgl03mod

  integer(GLint) :: ix, iy
  
  ! set circle center coordinates
  xc = 0.5*float(winWidth)
  yc = 0.5*float(winHeight)

  call glClearColor(1.0, 1.0, 1.0, 0.0)
  
  Hexagon = glGenLists(1)
  call glNewList( Hexagon, GL_COMPILE)
  
  call glColor3f( 1.0, 0.0, 0.0 )
  call glBegin(GL_POLYGON)
  do i=1,7
    theta = 6.2831853 * float(i)/ 6.0
    x  = xc + 150.*cos(theta)
    y  = yc + 150.*sin(theta) 
    ix = x
    iy = y
    call glVertex2i( ix, iy)
  end do

  call glEnd()
  call glEndList()
  
end subroutine initialize
subroutine reshape(newWidth, newHeight)

  use OpenGL_GL
  use OpenGL_GLU
  use fgl03mod

  integer(kind=GLcint), intent(IN) :: newWidth, newHeight
  real(kind=GLdouble) :: Zero, Width, Height

  Zero   = 0.0
  Width  = newWidth
  Height = newHeight

  call glMatrixMode( GL_PROJECTION )
  call glLoadIdentity()
  
  call gluOrtho2D( Zero, Width, Zero, Height )
  
  call glClear( GL_COLOR_BUFFER_BIT )

end subroutine reshape
subroutine draw_hexagon

  use OpenGL_GL
  use fgl03mod

  call glClear( GL_COLOR_BUFFER_BIT )

  call glCallList( Hexagon )
  
  call glFlush()
  
end subroutine draw_hexagon

DOS窓は略


  • ネタ元

http://www.dolfyn.net/dolfyn/f03gl_en.html

いわゆる Green Book からのサンプルのつづき。

program fgl02

  use opengl_gl
  use opengl_glu
  use opengl_glut

  external display
  
  integer(kind=GLint) :: iwin
  real(kind=GLdouble) :: window(4) = (/ 0.0, 200.0, 0.0, 100.0 /)
  
  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 50, 100)
  call glutInitWindowSize( 200, 100)
  iwin = glutCreateWindow("fgl02"//char(0))
  
  call glClearColor( 1.0, 1.0, 1.0, 0.0)
  call glMatrixMode( GL_PROJECTION )
  call gluOrtho2D( window(1), window(2), window(3), window(4) )
  
  call glutDisplayFunc( display )
  
  call glutMainLoop()
  
end program fgl02

subroutine display 

use opengl_gl

call glClear( GL_COLOR_BUFFER_BIT )

call glColor3f( 1.0, 0.0, 0.0)
call glBegin( GL_LINES )

call glVertex2i( 180, 20)
call glVertex2i(  20, 80)

call glEnd()

call glFlush()

end subroutine display

DOS窓は略


サンプル集の確認

  • 必要なライブラリのインストール

http://software.intel.com/en-us/forums/intel-visual-fortran-compiler-for-windows/topic/51670/

    • f90gl 本家

http://math.nist.gov/f90gl/

  • リンカーのオプション

glut32.lib f90gl.lib f90glu.lib f90glut.lib


  • 例題

ここの g95 + f03gl 用の Green Book サンプルを IVF + f90gl でw
http://www.dolfyn.net/dolfyn/f03gl_en.html

    • 気をつけるべき点

f03gl では RESHAPE 関数の引数が value 属性の値渡しになっているけれども、f90gl では普通の参照渡しになっているなど、微妙なインターフェースの差。

一部のポインタ定義なども変わっている。

!  type(C_PTR) :: ptr = c_null_ptr 
 TYPE (GLUQuadricObj), POINTER :: ptr

 ptr => gluNewQuadric() 

  • fgl01
module callbacks
  
  contains
  
  subroutine display() 

  use opengl_gl

  call glClear( GL_COLOR_BUFFER_BIT )
  
  call glColor3f( 1.0, 0.0, 0.0)
  call glBegin( GL_LINES )
  
  call glVertex2i( 180, 20)
  call glVertex2i(  20, 80)
  
  call glEnd()
  
  call glFlush()

  end subroutine display
end module callbacks
program fgl01

  use opengl_gl
  use opengl_glu
  use opengl_glut

  use callbacks
  
  integer(kind=GLint) :: iwin
  real(kind=GLdouble) :: window(4) = (/ 0.0, 200.0, 0.0, 100.0 /)
  
  call glutInit
  call glutInitDisplayMode(GLUT_SINGLE + GLUT_RGB )
  call glutInitWindowPosition( 50, 100)
  call glutInitWindowSize( 200, 100)
  iwin = glutCreateWindow("fgl01"//char(0))
  
  call glClearColor( 1.0, 1.0, 1.0, 0.0)
  call glMatrixMode( GL_PROJECTION )
  call gluOrtho2D( window(1), window(2), window(3), window(4) )
  
  call glutdisplayfunc( display )
  
  call glutMainLoop()
  
end program fgl01