Консультация № 62761
15.11.2006, 15:23
0.00 руб.
0 1 1
Привет.
Кто нибудь может привести каркасное приложение OpenGL на асме, только ссылок не надо.
Пока

Обсуждение

Неизвестный
16.11.2006, 13:51
общий
это ответ
Здравствуйте, SchoolBoy!
Принимайте!
.586
.Model Flat,StdCall
Option Scoped
Option CaseMap:None
Include windows.inc
Include user32.inc
Include kernel32.inc
Include gdi32.inc
Include OpenGL\gl.def
Include OpenGL\glu.def
IncludeLib user32.lib
IncludeLib kernel32.lib
IncludeLib opengl32.lib
IncludeLib glu32.lib
IncludeLib gdi32.lib
WinMain Proto :DWORD,:DWORD,:DWORD,:DWORD
WndProc Proto :DWORD,:DWORD,:DWORD,:DWORD
EnableOpenGL Proto :DWORD
DisableOpenGL Proto :DWORD
.Const
ClassName db "OGLMainWinClass", 0
AppName db "OpenGL App", 0
IDC_ICON1 equ 500
.Data?
hInstance HINSTANCE ?
CommandLine LPSTR ?
hDC HDC ?
hRC HGLRC ?
.Code
Start:
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GetCommandLine
mov CommandLine, eax
invoke WinMain, hInstance, NULL, CommandLine, SW_SHOWDEFAULT
invoke ExitProcess, eax
WinMain Proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR, CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
LOCAL bQuit:BOOL
mov bQuit, FALSE
mov wc.cbSize, sizeof WNDCLASSEX
mov wc.style, CS_OWNDC
mov wc.lpfnWndProc, offset WndProc
mov wc.cbClsExtra, NULL
mov wc.cbWndExtra, NULL
m2m wc.hInstance, hInstance
invoke GetStockObject, BLACK_BRUSH
mov wc.hbrBackground, eax
mov wc.lpszMenuName, NULL
mov wc.lpszClassName, offset ClassName
invoke LoadIcon, hInstance, IDC_ICON1
mov wc.hIcon, eax
mov wc.hIconSm, eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx,NULL, addr ClassName, addr AppName,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT,\
256, 256, NULL, NULL,hInst, NULL
mov hwnd,eax
invoke ShowWindow, eax, SW_SHOWNORMAL
invoke UpdateWindow, hwnd
invoke EnableOpenGL, hwnd
.while !( bQuit )
invoke GetMessage, addr msg, NULL, 0, 0
invoke PeekMessage, addr msg, NULL, 0, 0, PM_REMOVE
; handle or dispatch messages
.if ( eax )
.if ( msg.message == WM_QUIT )
mov bQuit, TRUE
.else
invoke TranslateMessage, addr msg
invoke DispatchMessage, addr msg
.endif
.else

; ...OpenGL animation code goes here...

.endif
.endw
invoke DisableOpenGL, hwnd
; mov eax,msg.wParam
; ret
return msg.wParam
;}
WinMain EndP

;========================================================
WndProc Proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
;{
LOCAL Rect:RECT

.if ( uMsg == WM_DESTROY )
;{
GetOutaHere:
invoke PostQuitMessage, NULL
;}
.elseif ( uMsg == WM_CREATE )
;{

;}
.elseif ( uMsg == WM_SIZE )
;{
invoke GetClientRect, hWnd, addr Rect
invoke glViewport, 0, 0, Rect.right, Rect.bottom
;}
.elseif ( uMsg == WM_KEYDOWN )
;{
.if ( wParam == VK_ESCAPE)
;{
jmp GetOutaHere
;}
.endif
;}
.else
;{
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
;}
.endif

xor eax,eax
ret

WndProc EndP

;========================================================
EnableOpenGL Proc hWnd:HWND
;{
LOCAL iFormat:dword
LOCAL pfd:PIXELFORMATDESCRIPTOR

; get the device context (DC)
invoke GetDC, hWnd
mov hDC, eax

; set the pixel format for the DC
lea edi, pfd
xor eax, eax
mov ecx, sizeof pfd / sizeof DWORD
rep stosd ; zero pfd structure

mov pfd.nSize, sizeof pfd
mov pfd.nVersion, 1
mov pfd.dwFlags, PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_DOUBLEBUFFER
mov pfd.iPixelType, PFD_TYPE_RGBA
mov pfd.cColorBits, 24
mov pfd.cDepthBits, 16
mov pfd.iLayerType, PFD_MAIN_PLANE
invoke ChoosePixelFormat, hDC, addr pfd
mov iFormat, eax
invoke SetPixelFormat, hDC, iFormat, addr pfd

; create and enable the render context (RC)
invoke wglCreateContext, hDC
mov hRC, eax
invoke wglMakeCurrent, hDC, hRC
ret
;}
EnableOpenGL EndP
;========================================================
DisableOpenGL Proc hWnd:HWND
;{
invoke wglMakeCurrent, NULL, NULL
invoke wglDeleteContext, hRC
invoke ReleaseDC, hWnd, hDC
ret
;}
DisableOpenGL EndP
;========================================================
End Start
Форма ответа