📄 opengl.asm
字号:
; OpenGL programming example
format PE GUI 4.0
entry start
include 'win32a.inc'
include 'opengl.inc'
section '.data' data readable writeable
_title db 'OpenGL example',0
_class db 'FASMOPENGL32',0
theta GLfloat 0.6
wc WNDCLASS 0,WindowProc,0,0,NULL,NULL,NULL,NULL,NULL,_class
hwnd dd ?
hdc dd ?
hrc dd ?
msg MSG
rc RECT
pfd PIXELFORMATDESCRIPTOR
active dd ?
section '.code' code readable executable
start:
invoke GetModuleHandle,0
mov [wc.hInstance],eax
invoke LoadIcon,0,IDI_APPLICATION
mov [wc.hIcon],eax
invoke LoadCursor,0,IDC_ARROW
mov [wc.hCursor],eax
invoke RegisterClass,wc
invoke CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_OVERLAPPEDWINDOW+WS_CLIPCHILDREN+WS_CLIPSIBLINGS,16,16,432,432,NULL,NULL,[wc.hInstance],NULL
mov [hwnd],eax
msg_loop:
invoke InvalidateRect,[hwnd],NULL,FALSE
invoke GetMessage,msg,NULL,0,0
or eax,eax
jz end_loop
invoke TranslateMessage,msg
invoke DispatchMessage,msg
jmp msg_loop
end_loop:
invoke ExitProcess,[msg.wParam]
proc WindowProc hwnd,wmsg,wparam,lparam
push ebx esi edi
cmp [wmsg],WM_CREATE
je wmcreate
cmp [wmsg],WM_SIZE
je wmsize
cmp [wmsg],WM_ACTIVATEAPP
je wmactivateapp
cmp [wmsg],WM_PAINT
je wmpaint
cmp [wmsg],WM_KEYDOWN
je wmkeydown
cmp [wmsg],WM_DESTROY
je wmdestroy
defwndproc:
invoke DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
jmp finish
wmcreate:
invoke GetDC,[hwnd]
mov [hdc],eax
mov edi,pfd
mov ecx,sizeof.PIXELFORMATDESCRIPTOR shr 2
xor eax,eax
rep stosd
mov [pfd.nSize],sizeof.PIXELFORMATDESCRIPTOR
mov [pfd.nVersion],1
mov [pfd.dwFlags],PFD_SUPPORT_OPENGL+PFD_DOUBLEBUFFER+PFD_DRAW_TO_WINDOW
mov [pfd.dwLayerMask],PFD_MAIN_PLANE
mov [pfd.iPixelType],PFD_TYPE_RGBA
mov [pfd.cColorBits],16
mov [pfd.cDepthBits],16
mov [pfd.cAccumBits],0
mov [pfd.cStencilBits],0
invoke ChoosePixelFormat,[hdc],pfd
invoke SetPixelFormat,[hdc],eax,pfd
invoke wglCreateContext,[hdc]
mov [hrc],eax
invoke wglMakeCurrent,[hdc],[hrc]
invoke GetClientRect,[hwnd],rc
invoke glViewport,0,0,[rc.right],[rc.bottom]
xor eax,eax
jmp finish
wmsize:
invoke GetClientRect,[hwnd],rc
invoke glViewport,0,0,[rc.right],[rc.bottom]
invoke InvalidateRect,[hwnd],NULL,FALSE
xor eax,eax
jmp finish
wmactivateapp:
push [wmsg]
pop [active]
xor eax,eax
jmp finish
wmpaint:
invoke glClear,GL_COLOR_BUFFER_BIT
invoke glRotatef,[theta],0.0,0.0,1.0
invoke glBegin,GL_QUADS
invoke glColor3f,1.0,0.1,0.1
invoke glVertex3f,-0.6,-0.6,0.0
invoke glColor3f,0.1,0.1,0.1
invoke glVertex3f,0.6,-0.6,0.0
invoke glColor3f,0.1,0.1,1.0
invoke glVertex3f,0.6,0.6,0.0
invoke glColor3f,1.0,0.1,1.0
invoke glVertex3f,-0.6,0.6,0.0
invoke glEnd
invoke SwapBuffers,[hdc]
xor eax,eax
jmp finish
wmkeydown:
cmp [wparam],VK_ESCAPE
jne defwndproc
wmdestroy:
invoke wglMakeCurrent,0,0
invoke wglDeleteContext,[hrc]
invoke ReleaseDC,[hwnd],[hdc]
invoke PostQuitMessage,0
xor eax,eax
finish:
pop edi esi ebx
ret
endp
section '.idata' import data readable writeable
library kernel,'KERNEL32.DLL',\
user,'USER32.DLL',\
gdi,'GDI32.DLL',\
opengl,'OPENGL32.DLL',\
glu,'GLU32.DLL'
import kernel,\
GetModuleHandle,'GetModuleHandleA',\
ExitProcess,'ExitProcess'
import user,\
RegisterClass,'RegisterClassA',\
CreateWindowEx,'CreateWindowExA',\
DefWindowProc,'DefWindowProcA',\
GetMessage,'GetMessageA',\
TranslateMessage,'TranslateMessage',\
DispatchMessage,'DispatchMessageA',\
LoadCursor,'LoadCursorA',\
LoadIcon,'LoadIconA',\
GetClientRect,'GetClientRect',\
InvalidateRect,'InvalidateRect',\
GetDC,'GetDC',\
ReleaseDC,'ReleaseDC',\
PostQuitMessage,'PostQuitMessage'
import gdi,\
ChoosePixelFormat,'ChoosePixelFormat',\
SetPixelFormat,'SetPixelFormat',\
SwapBuffers,'SwapBuffers'
import opengl,\
glAccum,'glAccum',\
glAlphaFunc,'glAlphaFunc',\
glAreTexturesResident,'glAreTexturesResident',\
glArrayElement,'glArrayElement',\
glBegin,'glBegin',\
glBindTexture,'glBindTexture',\
glBitmap,'glBitmap',\
glBlendFunc,'glBlendFunc',\
glCallList,'glCallList',\
glCallLists,'glCallLists',\
glClear,'glClear',\
glClearAccum,'glClearAccum',\
glClearColor,'glClearColor',\
glClearDepth,'glClearDepth',\
glClearIndex,'glClearIndex',\
glClearStencil,'glClearStencil',\
glClipPlane,'glClipPlane',\
glColor3b,'glColor3b',\
glColor3bv,'glColor3bv',\
glColor3d,'glColor3d',\
glColor3dv,'glColor3dv',\
glColor3f,'glColor3f',\
glColor3fv,'glColor3fv',\
glColor3i,'glColor3i',\
glColor3iv,'glColor3iv',\
glColor3s,'glColor3s',\
glColor3sv,'glColor3sv',\
glColor3ub,'glColor3ub',\
glColor3ubv,'glColor3ubv',\
glColor3ui,'glColor3ui',\
glColor3uiv,'glColor3uiv',\
glColor3us,'glColor3us',\
glColor3usv,'glColor3usv',\
glColor4b,'glColor4b',\
glColor4bv,'glColor4bv',\
glColor4d,'glColor4d',\
glColor4dv,'glColor4dv',\
glColor4f,'glColor4f',\
glColor4fv,'glColor4fv',\
glColor4i,'glColor4i',\
glColor4iv,'glColor4iv',\
glColor4s,'glColor4s',\
glColor4sv,'glColor4sv',\
glColor4ub,'glColor4ub',\
glColor4ubv,'glColor4ubv',\
glColor4ui,'glColor4ui',\
glColor4uiv,'glColor4uiv',\
glColor4us,'glColor4us',\
glColor4usv,'glColor4usv',\
glColorMask,'glColorMask',\
glColorMaterial,'glColorMaterial',\
glColorPointer,'glColorPointer',\
glCopyPixels,'glCopyPixels',\
glCopyTexImage1D,'glCopyTexImage1D',\
glCopyTexImage2D,'glCopyTexImage2D',\
glCopyTexSubImage1D,'glCopyTexSubImage1D',\
glCopyTexSubImage2D,'glCopyTexSubImage2D',\
glCullFace,'glCullFace',\
glDeleteLists,'glDeleteLists',\
glDeleteTextures,'glDeleteTextures',\
glDepthFunc,'glDepthFunc',\
glDepthMask,'glDepthMask',\
glDepthRange,'glDepthRange',\
glDisable,'glDisable',\
glDisableClientState,'glDisableClientState',\
glDrawArrays,'glDrawArrays',\
glDrawBuffer,'glDrawBuffer',\
glDrawElements,'glDrawElements',\
glDrawPixels,'glDrawPixels',\
glEdgeFlag,'glEdgeFlag',\
glEdgeFlagPointer,'glEdgeFlagPointer',\
glEdgeFlagv,'glEdgeFlagv',\
glEnable,'glEnable',\
glEnableClientState,'glEnableClientState',\
glEnd,'glEnd',\
glEndList,'glEndList',\
glEvalCoord1d,'glEvalCoord1d',\
glEvalCoord1dv,'glEvalCoord1dv',\
glEvalCoord1f,'glEvalCoord1f',\
glEvalCoord1fv,'glEvalCoord1fv',\
glEvalCoord2d,'glEvalCoord2d',\
glEvalCoord2dv,'glEvalCoord2dv',\
glEvalCoord2f,'glEvalCoord2f',\
glEvalCoord2fv,'glEvalCoord2fv',\
glEvalMesh1,'glEvalMesh1',\
glEvalMesh2,'glEvalMesh2',\
glEvalPoint1,'glEvalPoint1',\
glEvalPoint2,'glEvalPoint2',\
glFeedbackBuffer,'glFeedbackBuffer',\
glFinish,'glFinish',\
glFlush,'glFlush',\
glFogf,'glFogf',\
glFogfv,'glFogfv',\
glFogi,'glFogi',\
glFogiv,'glFogiv',\
glFrontFace,'glFrontFace',\
glFrustum,'glFrustum',\
glGenLists,'glGenLists',\
glGenTextures,'glGenTextures',\
glGetBooleanv,'glGetBooleanv',\
glGetClipPlane,'glGetClipPlane',\
glGetDoublev,'glGetDoublev',\
glGetError,'glGetError',\
glGetFloatv,'glGetFloatv',\
glGetIntegerv,'glGetIntegerv',\
glGetLightfv,'glGetLightfv',\
glGetLightiv,'glGetLightiv',\
glGetMapdv,'glGetMapdv',\
glGetMapfv,'glGetMapfv',\
glGetMapiv,'glGetMapiv',\
glGetMaterialfv,'glGetMaterialfv',\
glGetMaterialiv,'glGetMaterialiv',\
glGetPixelMapfv,'glGetPixelMapfv',\
glGetPixelMapuiv,'glGetPixelMapuiv',\
glGetPixelMapusv,'glGetPixelMapusv',\
glGetPointerv,'glGetPointerv',\
glGetPolygonStipple,'glGetPolygonStipple',\
glGetString,'glGetString',\
glGetTexEnvfv,'glGetTexEnvfv',\
glGetTexEnviv,'glGetTexEnviv',\
glGetTexGendv,'glGetTexGendv',\
glGetTexGenfv,'glGetTexGenfv',\
glGetTexGeniv,'glGetTexGeniv',\
glGetTexImage,'glGetTexImage',\
glGetTexLevelParameterfv,'glGetTexLevelParameterfv',\
glGetTexLevelParameteriv,'glGetTexLevelParameteriv',\
glGetTexParameterfv,'glGetTexParameterfv',\
glGetTexParameteriv,'glGetTexParameteriv',\
glHint,'glHint',\
glIndexMask,'glIndexMask',\
glIndexPointer,'glIndexPointer',\
glIndexd,'glIndexd',\
glIndexdv,'glIndexdv',\
glIndexf,'glIndexf',\
glIndexfv,'glIndexfv',\
glIndexi,'glIndexi',\
glIndexiv,'glIndexiv',\
glIndexs,'glIndexs',\
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -