[Fortran] 纯文本查看 复制代码
!************************(第二部分)主函数部分********************************
integer function WinMain( hInstance, hPrevInstance, lpCmdLine, nCmdShow )
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_WinMain@16' :: WinMain
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'WinMain' :: WinMain
!DEC$ ENDIF
use IFwin
use Ifopngl
use VarGlob
Implicit None
integer(4) :: hInstance !保存程序的实例
integer(4) :: hPrevInstance !定义句柄,永远是NULL型
integer(4) :: nCmdShow !定义程序执行的时候窗口的显示方式
integer(4) :: lpCmdLine !指向字符串的指针
integer(4) :: hWnd
character*100 lpszClassName !定义窗口类的名字
character*100 lpszAppName !定义窗口的名字,即窗口的标题
type (T_WNDCLASS) :: wc !定义窗口的结构体类数据,确定窗口的特征
type (T_MSG) :: msg !定义消息的结构体类数据
!●●●●●●●●●●定义函数接口●●●●●●●●●●
interface
integer*4 function MainWndProc( hwnd, message, wParam, lParam )
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'MainWndProc' :: MainWndProc
!DEC$ ENDIF
integer(4) :: hwnd
integer(4) :: message
integer(4) :: wParam
integer(4) :: lParam
end function
end interface
!●●●●●●●●●●定义函数接口●●●●●●●●●●
lpszClassName = "Generic"C
lpszAppName = "OPENGL窗口"C
!注册窗口类
hInstance = GetModuleHandle(NULL) !取得我们窗口的实例
!移动时重画,并为窗口取得DC
wc%style = ior(ior(CS_HREDRAW,CS_VREDRAW),CS_OWNDC)
wc%lpfnWndProc = LOC(MainWndProc) !MainWndProc处理消息
wc%cbClsExtra = 0 !无额外窗口数据
wc%cbWndExtra = 0 !无额外窗口数据
wc%hInstance = hInstance !设置实例
wc%hIcon = LoadIcon( hInstance, IDI_WINLOGO) !装入缺省图标
wc%hCursor = LoadCursor(NULL, IDC_ARROW) !装入鼠标指针
wc%hbrBackground = NULL !背景画刷
wc%lpszMenuName = NULL !菜单
wc%lpszClassName = loc(lpszClassName)
if ( RegisterClass(wc)==0 )then !尝试注册窗口类
results = MessageBox(NULL,"注册窗口失败"C,"错误"C,ior(MB_OK,MB_ICONHAND))
endif
!创建窗口
hWnd = CreateWindowEx(0, & !扩展窗体风格
lpszClassName, & !类名字
lpszAppName, & !窗口标题
!选择的窗体属性
or(or(WS_OVERLAPPEDWINDOW, WS_CLIPCHILDREN),WS_CLIPSIBLINGS), &
CW_USEDEFAULT, &
0, &
CW_USEDEFAULT, &
0, &
NULL, & !无父窗口
NULL, & !无菜单
hInstance, & !实例
NULL) !不向WM_CREATE传递任何东东
!显示窗口
logicalt = ShowWindow( hWnd,SW_MAXIMIZE ) !在这里设置窗口最大化显示方式
logicalt = UpdateWindow( hwnd )
!消息循环
do while( GetMessage (msg, NULL, 0, 0) .NEQV. .FALSE.)
results = TranslateMessage( msg )
results = DispatchMessage( msg )
end do
WinMain = msg%wParam
return
end function WinMain
!****************************(第三部分)窗口调用函数**************************
integer function MainWndProc( hwnd, message, wParam, lParam )
!DEC$ IF DEFINED(_X86_)
!DEC$ ATTRIBUTES STDCALL, ALIAS : '_MainWndProc@16' :: MainWndProc
!DEC$ ELSE
!DEC$ ATTRIBUTES STDCALL, ALIAS : 'MainWndProc' :: MainWndProc
!DEC$ ENDIF
use IFwin
use Ifopngl
use VarGlob
Implicit None
integer(4) :: hwnd !保存我们的窗口句柄
integer(4) :: message !消息类结构体
integer(4) :: wParam !消息相关的附加信息
integer(4) :: lParam !消息相关的附加信息
integer(4) :: glnWidth, glnHeight
type (T_PAINTSTRUCT) :: paintstruct
select case (message)
case ( WM_CREATE ) !有WM_PAINT消息时才能正确显示出图形
call SetupPixelFormat( hwnd ) !调用显示模式安装功能
call InitGL( ) !初始化处理绘图环境
return
case ( WM_PAINT ) !解决屏幕变化时候图形的显示问题
results = BeginPaint(hwnd, paintstruct)
call DrawGLScene( ) !所有的绘图动作都在这个地方
results = EndPaint(hwnd, paintstruct)
return
case ( WM_SIZE ) !屏幕尺寸变化后,自动发送WM_PAINT消息
glnWidth = and(lParam, #0000FFFF) !变化后窗口的宽度
glnHeight = ishft(lParam, -16) !变化后窗口的高度
call ReSizeGLScene(glnWidth, glnHeight)
return
case ( WM_DESTROY )
call KillGLWindow( hwnd )
return
case default
MainWndProc = DefWindowProc(hwnd, message, wParam, lParam)
return
end select
return
end function MainWndProc
!●●●●●●●●●●绘图子程序●●●●●●●●●●
Subroutine Wedge( )
use IFwin
use Ifopngl
use VarGlob
Implicit None
call fglClear(ior(GL_COLOR_BUFFER_BIT,GL_DEPTH_BUFFER_BIT))
call fglLoadIdentity()
call fglTranslatef(-1.5 ,0.0 ,-6.0 )
call fglBegin(GL_POLYGON)
call fglColor3f(1.0 ,0.0 ,0.0 )
call fglVertex3f( 0.0 , 1.0 , 0.0 )
call fglColor3f(0.0 ,1.0 ,0.0 )
call fglVertex3f(-1.0 ,-1.0 , 1.0 )
call fglColor3f(0.0 ,0.0 ,1.0 )
call fglVertex3f( 1.0 ,-1.0 , 1.0 )
call fglColor3f(1.0 ,0.0 ,0.0 )
call fglVertex3f( 0.0 , 1.0 , 0.0 )
call fglColor3f(0.0 ,0.0 ,1.0 )
call fglVertex3f( 1.0 ,-1.0 , 1.0 )
call fglColor3f(0.0 ,1.0 ,0.0 )
call fglVertex3f( 1.0 ,-1.0 , -1.0 )
call fglColor3f(1.0 ,0.0 ,0.0 )
call fglVertex3f( 0.0 , 1.0 , 0.0 )
call fglColor3f(0.0 ,1.0 ,0.0 )
call fglVertex3f( 1.0 ,-1.0 , -1.0 )
call fglColor3f(0.0 ,0.0 ,1.0 )
call fglVertex3f(-1.0 ,-1.0 , -1.0 )
call fglColor3f(1.0 ,0.0 ,0.0 )
call fglVertex3f( 0.0 , 1.0 , 0.0 )
call fglColor3f(0.0 ,0.0 ,1.0 )
call fglVertex3f(-1.0 ,-1.0 ,-1.0 )
call fglColor3f(0.0 ,1.0 ,0.0 )
call fglVertex3f(-1.0 ,-1.0 , 1.0 )
call fglEnd()
call fglLoadIdentity()
call fglTranslatef(1.5 ,0.0 ,-6.0 )
call fglRotatef(45,1.0 ,0.0 ,0.0 )
call fglColor3f(0.5 ,0.5 ,1.0 )
call fglBegin(GL_QUADS)
call fglColor3f(0.0 ,1.0 ,0.0 )
call fglVertex3f( 1.0 , 1.0 ,-1.0 )
call fglVertex3f(-1.0 , 1.0 ,-1.0 )
call fglVertex3f(-1.0 , 1.0 , 1.0 )
call fglVertex3f( 1.0 , 1.0 , 1.0 )
call fglColor3f(1.0 ,0.5 ,0.0 )
call fglVertex3f( 1.0 ,-1.0 , 1.0 )
call fglVertex3f(-1.0 ,-1.0 , 1.0 )
call fglVertex3f(-1.0 ,-1.0 ,-1.0 )
call fglVertex3f( 1.0 ,-1.0 ,-1.0 )
call fglColor3f(1.0 ,0.0 ,0.0 )
call fglVertex3f( 1.0 , 1.0 , 1.0 )
call fglVertex3f(-1.0 , 1.0 , 1.0 )
call fglVertex3f(-1.0 ,-1.0 , 1.0 )
call fglVertex3f( 1.0 ,-1.0 , 1.0 )
call fglColor3f(1.0 ,1.0 ,0.0 )
call fglVertex3f( 1.0 ,-1.0 ,-1.0 )
call fglVertex3f(-1.0 ,-1.0 ,-1.0 )
call fglVertex3f(-1.0 , 1.0 ,-1.0 )
call fglVertex3f( 1.0 , 1.0 ,-1.0 )
call fglColor3f(0.0 ,0.0 ,1.0 )
call fglVertex3f(-1.0 , 1.0 , 1.0 )
call fglVertex3f(-1.0 , 1.0 ,-1.0 )
call fglVertex3f(-1.0 ,-1.0 ,-1.0 )
call fglVertex3f(-1.0 ,-1.0 , 1.0 )
call fglColor3f(1.0 ,0.0 ,1.0 )
call fglVertex3f( 1.0 , 1.0 ,-1.0 )
call fglVertex3f( 1.0 , 1.0 , 1.0 )
call fglVertex3f( 1.0 ,-1.0 , 1.0 )
call fglVertex3f( 1.0 ,-1.0 ,-1.0 )
call fglEnd()
return
end Subroutine Wedge