flat assembler
Message board for the users of flat assembler.

Index > Windows > 3D rendering questions

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 660
Location: Russian Federation, Sochi
ProMiNick
I tryed to realize in different renderers things exactly.

;==================================================================
01 INIT

dx8:
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

include 'dx8(x32).inc'
WINDOWWIDTH  = 640
WINDOWHEIGHT = 480
D3D81_SDK_VERSION = 220

section '.text' code readable executable
start:
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClassEx,wc

        invoke  MessageBox, 0, szIsFullScreen, szAppName, MB_YESNO
        xor     eax,IDYES
        mov     [bWindowed],eax
        mov     ecx, WS_POPUP or WS_VISIBLE
        jz      @F
        mov     ecx, WS_OVERLAPPEDWINDOW or WS_VISIBLE
      @@:
        invoke  CreateWindowEx,0,szClassName,szAppName,ecx,100,75,WINDOWWIDTH,WINDOWHEIGHT,NULL,NULL,PE_IMAGE_BASE,NULL
        mov     [hwndmain],eax

        invoke  ShowWindow, [hwndmain], SW_SHOWNORMAL
        invoke  UpdateWindow, [hwndmain]

        stdcall Init3D
        or      eax,eax
        jz      .init_ok
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
        invoke  SendMessage, [hwndmain], WM_CLOSE, 0, 0
        jmp     .msgLoop
      .init_ok:
        inc     [bReady]
      .msgLoop:
        mov     eax,[msg.message]
        cmp     eax, WM_QUIT
        jz      .exitLoop
        invoke  PeekMessage, msg, NULL, 0, 0, PM_REMOVE
        or      eax,eax
        jz      .idleuse
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     .msgLoop
      .idleuse:
        mov     eax, [bReady]
        or      eax,eax
        jz      .msgLoop
        stdcall RenderScene
        jmp     .msgLoop
   .error:
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
   .exitLoop:
        stdcall Free3D
        mov     eax,[msg.wParam]
        invoke  ExitProcess, eax

proc WndProc hWnd, uMsg, wParam, lParam
        push    esi edi ebx
        mov     eax, [uMsg]
        cmp     eax, WM_KEYDOWN
        jz      .wmkeydown
        cmp     eax, WM_SETCURSOR
        jz      .wmsetcursor
        cmp     eax, WM_DESTROY
        jz      .wmdestroy
        cmp     eax, WM_CLOSE
        jnz     .def
        xor     eax, eax
        mov     [bReady], eax
   .def:
        invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
        jmp     .RetProc
   .wmkeydown:
        mov     eax, [wParam]
        cmp     eax, VK_ESCAPE
        jnz     .def
        invoke  SendMessage, [hWnd], WM_CLOSE, NULL, NULL
        jmp     .ExitProc
   .wmsetcursor:
        mov     eax,[bWindowed]
        or      eax, eax
        jnz     .def
        invoke  SetCursor, NULL
        jmp     .ExitProc
   .wmdestroy:
        invoke  PostQuitMessage, NULL
        xor     eax, eax
   .ExitProc:
   .RetProc:
        pop     ebx edi esi
        ret
endp

proc Init3D
        invoke  Direct3DCreate8, D3D81_SDK_VERSION
        or      eax,eax
        jnz     @F
        mov     eax,errCreate3D
        jmp     start.error
   @@:
        mov     [context],eax
        comcall [context],IDirect3D8,GetAdapterDisplayMode, NULL, DisplayMode
        or      eax,eax
        jz     @F
        mov     eax,errGetAdapterDM
        jmp     start.error
   @@:
        mov     eax,[DisplayMode.Format]
        mov     [d3dpp.BackBufferFormat],eax

        mov     eax,[bWindowed]
        or      eax,eax
        jnz     @F
        mov     [d3dpp.SwapEffect], D3DSWAPEFFECT_FLIP
   @@:
        invoke  GetClientRect, [hwndmain], rect
        mov     eax, [rect.right]
        mov     [d3dpp.BackBufferWidth], eax                                          ; ñîõðàíÿåì â ñòðóêòóðå D3DPRESENT_PARAMETERS
        mov     eax, [rect.bottom]
        mov     [d3dpp.BackBufferHeight], eax

        comcall [context],IDirect3D8,CreateDevice, NULL, D3DDEVTYPE_HAL, [hwndmain], \
                                            D3DCREATE_SOFTWARE_VERTEXPROCESSING,d3dpp,device
        or      eax,eax
        jz      @F
        mov     eax,errCreateDevice
        jmp     start.error
   @@:
        ret
endp

proc Free3D
        mov     eax,[device]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice8,Release
        xor     eax,eax
        mov     [device],eax
   @@:
        mov     eax,[context]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice8,Release
        xor     eax,eax
        mov     [context],eax
   @@:
        ret
endp

proc RenderScene
        comcall [device],IDirect3DDevice8,TestCooperativeLevel
        cmp     eax,D3DERR_DEVICELOST                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jz      @render_exit
        cmp     eax, D3DERR_DEVICENOTRESET                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jnz     @reseted
        comcall [device],IDirect3DDevice8,Reset,d3dpp
   @reseted:
        comcall [device],IDirect3DDevice8,Clear,0,NULL,D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER,$808080,1.0,0
        comcall [device],IDirect3DDevice8,BeginScene
        nop
        comcall [device],IDirect3DDevice8,EndScene
        comcall [device],IDirect3DDevice8,Present, NULL, NULL, NULL, NULL
   @render_exit:
        ret
endp

section '.data' data readable writeable
        wc              WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_OWNDC, WndProc,0,0,PE_IMAGE_BASE,0,0,0,0,szClassName,0
        szClassName     TCHAR 'demoD3D', 0
        szAppName       TCHAR '[01] Init D3D', 0
        szIsFullScreen  TCHAR 'Fullscreen mode ?', 0
        errCreate3D     TCHAR 'Direct3DCreate failed !', 0
        errGetAdapterDM TCHAR 'GetAdapterDisplayMode failed !', 0
        errCreateDevice TCHAR 'CreateDevice failed !', 0
        ;hdc            dd ?
        d3dpp           D3DPRESENT_PARAMETERS 0,0,0,2,0,D3DSWAPEFFECT_DISCARD,0,0,1,D3DFMT_D16,0,0,0
        DisplayMode     D3DDISPLAYMODE
        label hwndmain dword at d3dpp.hDeviceWindow ;hwndmain           dd ?
        label bWindowed at d3dpp.Windowed ;bwindowed          dd ?
        context         IDirect3D8
        device          IDirect3DDevice8

        rect            RECT
        msg             MSG
        bReady          dd ?

section '.idata' import data readable writeable
  library  kernel32, 'KERNEL32.DLL',\
           user32,   'USER32.DLL',\
           gdi32,    'GDI32.DLL',\
           d3d8,     'D3D8.DLL'

        include  'os_specs/windows/api/x86/kernel32.inc'
        include  'os_specs/windows/api/x86/user32.inc'
        include  'os_specs/windows/api/x86/gdi32.inc'
        include  'os_specs/windows/api/x86/directx/d3d8.inc'    

dx9:
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

include 'dx9(x32).inc'
WINDOWWIDTH  = 640
WINDOWHEIGHT = 480
D3D9b_SDK_VERSION = 31

section '.text' code readable executable
start:
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClassEx,wc

        invoke  MessageBox, 0, szIsFullScreen, szAppName, MB_YESNO
        xor     eax,IDYES
        mov     [bWindowed],eax
        mov     ecx, WS_POPUP or WS_VISIBLE
        jz      @F
        mov     ecx, WS_OVERLAPPEDWINDOW or WS_VISIBLE
      @@:
        invoke  CreateWindowEx,0,szClassName,szAppName,ecx,100,75,WINDOWWIDTH,WINDOWHEIGHT,NULL,NULL,PE_IMAGE_BASE,NULL
        mov     [hwndmain],eax

        invoke  ShowWindow, [hwndmain], SW_SHOWNORMAL
        invoke  UpdateWindow, [hwndmain]

        stdcall Init3D
        or      eax,eax
        jz      .init_ok
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
        invoke  SendMessage, [hwndmain], WM_CLOSE, 0, 0
        jmp     .msgLoop
      .init_ok:
        inc     [bReady]
      .msgLoop:
        mov     eax,[msg.message]
        cmp     eax, WM_QUIT
        jz      .exitLoop
        invoke  PeekMessage, msg, NULL, 0, 0, PM_REMOVE
        or      eax,eax
        jz      .idleuse
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     .msgLoop
      .idleuse:
        mov     eax, [bReady]
        or      eax,eax
        jz      .msgLoop
        stdcall RenderScene
        jmp     .msgLoop
   .error:
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
   .exitLoop:
        stdcall Free3D
        mov     eax,[msg.wParam]
        invoke  ExitProcess, eax

proc WndProc hWnd, uMsg, wParam, lParam
        push    esi edi ebx
        mov     eax, [uMsg]
        cmp     eax, WM_KEYDOWN
        jz      .wmkeydown
        cmp     eax, WM_SETCURSOR
        jz      .wmsetcursor
        cmp     eax, WM_DESTROY
        jz      .wmdestroy
        cmp     eax, WM_CLOSE
        jnz     .def
        xor     eax, eax
        mov     [bReady], eax
   .def:
        invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
        jmp     .RetProc
   .wmkeydown:
        mov     eax, [wParam]
        cmp     eax, VK_ESCAPE
        jnz     .def
        invoke  SendMessage, [hWnd], WM_CLOSE, NULL, NULL
        jmp     .ExitProc
   .wmsetcursor:
        mov     eax,[bWindowed]
        or      eax, eax
        jnz     .def
        invoke  SetCursor, NULL
        jmp     .ExitProc
   .wmdestroy:
        invoke  PostQuitMessage, NULL
        xor     eax, eax
   .ExitProc:
   .RetProc:
        pop     ebx edi esi
        ret
endp

proc Init3D
        invoke  Direct3DCreate9, D3D9b_SDK_VERSION
        or      eax,eax
        jnz     @F
        mov     eax,errCreate3D
        jmp     start.error
   @@:
        mov     [context],eax
        comcall [context],IDirect3D9,GetAdapterDisplayMode, NULL, DisplayMode
        or      eax,eax
        jz     @F
        mov     eax,errGetAdapterDM
        jmp     start.error
   @@:
        mov     eax,[DisplayMode.Format]
        mov     [d3dpp.BackBufferFormat],eax

        mov     eax,[bWindowed]
        or      eax,eax
        jnz     @F
        mov     [d3dpp.SwapEffect], D3DSWAPEFFECT_FLIP
   @@:
        invoke  GetClientRect, [hwndmain], rect
        mov     eax, [rect.right]
        mov     [d3dpp.BackBufferWidth], eax                                          ; ñîõðàíÿåì â ñòðóêòóðå D3DPRESENT_PARAMETERS
        mov     eax, [rect.bottom]
        mov     [d3dpp.BackBufferHeight], eax

        comcall [context],IDirect3D9,CreateDevice, NULL, D3DDEVTYPE_HAL, [hwndmain], \
                                            D3DCREATE_SOFTWARE_VERTEXPROCESSING,d3dpp,device
        or      eax,eax
        jz      @F
        mov     eax,errCreateDevice
        jmp     start.error
   @@:
        ret
endp

proc Free3D
        mov     eax,[device]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice9,Release
        xor     eax,eax
        mov     [device],eax
   @@:
        mov     eax,[context]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice9,Release
        xor     eax,eax
        mov     [context],eax
   @@:
        ret
endp

proc RenderScene
        comcall [device],IDirect3DDevice9,TestCooperativeLevel
        cmp     eax,D3DERR_DEVICELOST                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jz      @render_exit
        cmp     eax, D3DERR_DEVICENOTRESET                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jnz     @reseted
        comcall [device],IDirect3DDevice9,Reset,d3dpp
   @reseted:
        comcall [device],IDirect3DDevice9,Clear,0,NULL,D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER,$808080,1.0,0
        comcall [device],IDirect3DDevice9,BeginScene
        nop
        comcall [device],IDirect3DDevice9,EndScene
        comcall [device],IDirect3DDevice9,Present, NULL, NULL, NULL, NULL
   @render_exit:
        ret
endp

section '.data' data readable writeable
        wc              WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_OWNDC, WndProc,0,0,PE_IMAGE_BASE,0,0,0,0,szClassName,0
        szClassName     TCHAR 'demoD3D', 0
        szAppName       TCHAR '[01] Init D3D', 0
        szIsFullScreen  TCHAR 'Fullscreen mode ?', 0
        errCreate3D     TCHAR 'Direct3DCreate failed !', 0
        errGetAdapterDM TCHAR 'GetAdapterDisplayMode failed !', 0
        errCreateDevice TCHAR 'CreateDevice failed !', 0
        ;hdc            dd ?
        d3dpp           D3DPRESENT_PARAMETERS 0,0,0,2,0,0,D3DSWAPEFFECT_DISCARD,0,0,1,D3DFMT_D16,0,0,0
        DisplayMode     D3DDISPLAYMODE
        label hwndmain dword at d3dpp.hDeviceWindow ;hwndmain           dd ?
        label bWindowed at d3dpp.Windowed ;bwindowed          dd ?
        context         IDirect3D9
        device          IDirect3DDevice9

        rect            RECT
        msg             MSG
        bReady          dd ?

section '.idata' import data readable writeable
  library  kernel32, 'KERNEL32.DLL',\
           user32,   'USER32.DLL',\
           gdi32,    'GDI32.DLL',\
           d3d9,     'D3D9.DLL'

        include  'os_specs/windows/api/x86/kernel32.inc'
        include  'os_specs/windows/api/x86/user32.inc'
        include  'os_specs/windows/api/x86/gdi32.inc'
        include  'os_specs/windows/api/x86/directx/d3d9.inc'    


opengl(I guess opengl1.0-2.0):
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

include 'technlgy/pseudo3d/opengl/equates/opengl.inc'
WINDOWWIDTH  = 640
WINDOWHEIGHT = 480

section '.text' code readable executable
start:
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClassEx,wc

        invoke  MessageBox, 0, szIsFullScreen, szAppName, MB_YESNO
        xor     eax,IDYES
        mov     [bWindowed],eax
        mov     ecx, WS_POPUP or WS_VISIBLE
        jz      @F
        mov     ecx, WS_OVERLAPPEDWINDOW or WS_VISIBLE
      @@:
        invoke  CreateWindowEx,0,szClassName,szAppName,ecx,100,75,WINDOWWIDTH,WINDOWHEIGHT,NULL,NULL,PE_IMAGE_BASE,NULL
        mov     [hwndmain],eax

        invoke  ShowWindow, [hwndmain], SW_SHOWNORMAL
        invoke  UpdateWindow, [hwndmain]

        stdcall Init3D
        or      eax,eax
        jz      .init_ok
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
        invoke  SendMessage, [hwndmain], WM_CLOSE, 0, 0
        jmp     .msgLoop
      .init_ok:
        inc     [bReady]
      .msgLoop:
        mov     eax,[msg.message]
        cmp     eax, WM_QUIT
        jz      .exitLoop
        invoke  PeekMessage, msg, NULL, 0, 0, PM_REMOVE
        or      eax,eax
        jz      .idleuse
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     .msgLoop
      .idleuse:
        mov     eax, [bReady]
        or      eax,eax
        jz      .msgLoop
        stdcall RenderScene
        jmp     .msgLoop
   .error:
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
   .exitLoop:
        stdcall Free3D
        mov     eax,[msg.wParam]
        invoke  ExitProcess, eax

proc WndProc hWnd, uMsg, wParam, lParam
        push    esi edi ebx
        mov     eax, [uMsg]
        cmp     eax, WM_KEYDOWN
        jz      .wmkeydown
        cmp     eax, WM_SETCURSOR
        jz      .wmsetcursor
        cmp     eax, WM_DESTROY
        jz      .wmdestroy
        cmp     eax, WM_CLOSE
        jnz     .def
        xor     eax, eax
        mov     [bReady], eax
   .def:
        invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
        jmp     .RetProc
   .wmkeydown:
        mov     eax, [wParam]
        cmp     eax, VK_ESCAPE
        jnz     .def
        invoke  SendMessage, [hWnd], WM_CLOSE, NULL, NULL
        jmp     .ExitProc
   .wmsetcursor:
        mov     eax,[bWindowed]
        or      eax, eax
        jnz     .def
        invoke  SetCursor, NULL
        jmp     .ExitProc
   .wmdestroy:
        invoke  PostQuitMessage, NULL
        xor     eax, eax
   .ExitProc:
   .RetProc:
        pop     ebx edi esi
        ret
endp

proc Init3D
        invoke  GetDC,[hwndmain]
        mov     [hdc],eax
        invoke  ChoosePixelFormat, eax, pfd
        invoke  SetPixelFormat, [hdc], eax, pfd
        invoke  wglCreateContext,[hdc]
        or      eax,eax
        jnz     @F
        int3
        mov     eax,errCreate3D
        jmp     start.error
   @@:
        mov     [context],eax
        invoke  wglMakeCurrent,[hdc],[context]
        invoke  GetClientRect,[hwndmain],rect
        invoke  glClearColor,0.5,0.5,0.5,1.0
        invoke  glViewport,0,0,[rect.right],[rect.bottom]
        xor     eax,eax
        ret
endp

proc Free3D
        invoke  wglMakeCurrent,0,0
        invoke  wglDeleteContext,[context]
        invoke  ReleaseDC,[hwndmain],[hdc]
     ret
endp

proc RenderScene
        invoke  glClear,GL_COLOR_BUFFER_BIT
        invoke  glBegin,GL_QUADS
        nop
        invoke  glEnd
        invoke  SwapBuffers,[hdc]
   @render_exit:
     ret
endp

section '.data' data readable writeable
        wc              WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_OWNDC, WndProc,0,0,PE_IMAGE_BASE,0,0,0,0,szClassName,0
        pfd             PIXELFORMATDESCRIPTOR sizeof.PIXELFORMATDESCRIPTOR, 1, \
                        PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_TYPE_RGBA or PFD_DOUBLEBUFFER ,\ ;PFD_DOUBLEBUFFER or
                        32,\ ;Select Our Color Depth
                        0, 0, 0, 0, 0, 0,\ ;Color Bits Ignored
                        0,\ ;No Alpha Buffer
                        0,\ ;Shift Bit Ignored
                        0,\          ;No Accumulation Buffer
                        0, 0, 0, 0,\ ;Accumulation Bits Ignored
                        16,\         ;16Bit Z-Buffer (Depth Buffer)
                        0,\          ;No Stencil Buffer
                        0,\          ;No Auxiliary Buffer
                        PFD_MAIN_PLANE,\ ;Main Drawing Layer
                        0,\          ;Reserved
                        0, 0, 0      ;Layer Masks Ignored
        szClassName     TCHAR 'demoOpenGL', 0
        szAppName       TCHAR '[01] Init OpenGL', 0
        szIsFullScreen  TCHAR 'Fullscreen mode ?', 0
        errCreate3D     TCHAR 'OpenGL create context failed !', 0
        hdc             dd ?
        hwndmain        dd ?
        bWindowed       dd ?
        context         dd ?

        rect            RECT
        msg             MSG
        bReady          dd ?

section '.idata' import data readable writeable
  library  kernel32, 'KERNEL32.DLL',\
           user32,   'USER32.DLL',\
           gdi32,    'GDI32.DLL',\
           opengl32, 'OPENGL32.DLL'

        include  'os_specs/windows/api/x86/kernel32.inc'
        include  'os_specs/windows/api/x86/user32.inc'
        include  'os_specs/windows/api/x86/gdi32.inc'
        include  'os_specs/windows/api/x86/opengl/opengl32.inc'    


All succesfuly inited in all 3 cases, differences are undetectable because of simplifity of example.

;==================================================================
02 TRIANGLE
dx8:
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

include 'dx8(x32).inc'
WINDOWWIDTH  = 640
WINDOWHEIGHT = 480
D3D81_SDK_VERSION = 220
90° equ 1.5707963267948966192313216916398

section '.text' code readable executable
start:
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClassEx,wc

        invoke  MessageBox, 0, szIsFullScreen, szAppName, MB_YESNO
        xor     eax,IDYES
        mov     [bWindowed],eax
        mov     ecx, WS_POPUP or WS_VISIBLE
        jz      @F
        mov     ecx, WS_OVERLAPPEDWINDOW or WS_VISIBLE
      @@:
        invoke  CreateWindowEx,0,szClassName,szAppName,ecx,100,75,WINDOWWIDTH,WINDOWHEIGHT,NULL,NULL,PE_IMAGE_BASE,NULL
        mov     [hwndmain],eax

        invoke  ShowWindow, [hwndmain], SW_SHOWNORMAL
        invoke  UpdateWindow, [hwndmain]

        stdcall Init3D
        or      eax,eax
        jz      .init_ok
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
        invoke  SendMessage, [hwndmain], WM_CLOSE, 0, 0
        jmp     .msgLoop
      .init_ok:
        inc     [bReady]
      .msgLoop:
        mov     eax,[msg.message]
        cmp     eax, WM_QUIT
        jz      .exitLoop
        invoke  PeekMessage, msg, NULL, 0, 0, PM_REMOVE
        or      eax,eax
        jz      .idleuse
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     .msgLoop
      .idleuse:
        mov     eax, [bReady]
        or      eax,eax
        jz      .msgLoop
        stdcall RenderScene
        jmp     .msgLoop
   .error:
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
   .exitLoop:
        stdcall Free3D
        mov     eax,[msg.wParam]
        invoke  ExitProcess, eax

proc WndProc hWnd, uMsg, wParam, lParam
        push    esi edi ebx
        mov     eax, [uMsg]
        cmp     eax, WM_KEYDOWN
        jz      .wmkeydown
        cmp     eax, WM_SETCURSOR
        jz      .wmsetcursor
        cmp     eax, WM_DESTROY
        jz      .wmdestroy
        cmp     eax, WM_CLOSE
        jnz     .def
        xor     eax, eax
        mov     [bReady], eax
   .def:
        invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
        jmp     .RetProc
   .wmkeydown:
        mov     eax, [wParam]
        cmp     eax, VK_ESCAPE
        jnz     .def
        invoke  SendMessage, [hWnd], WM_CLOSE, NULL, NULL
        jmp     .ExitProc
   .wmsetcursor:
        mov     eax,[bWindowed]
        or      eax, eax
        jnz     .def
        invoke  SetCursor, NULL
        jmp     .ExitProc
   .wmdestroy:
        invoke  PostQuitMessage, NULL
        xor     eax, eax
   .ExitProc:
   .RetProc:
        pop     ebx edi esi
        ret
endp

proc Init3D
        invoke  Direct3DCreate8, D3D81_SDK_VERSION
        or      eax,eax
        jnz     @F
        mov     eax,errCreate3D
        jmp     start.error
   @@:
        mov     [context],eax
        comcall [context],IDirect3D8,GetAdapterDisplayMode, NULL, DisplayMode
        or      eax,eax
        jz     @F
        mov     eax,errGetAdapterDM
        jmp     start.error
   @@:
        mov     eax,[DisplayMode.Format]
        mov     [d3dpp.BackBufferFormat],eax

        mov     eax,[bWindowed]
        or      eax,eax
        jnz     @F
        mov     [d3dpp.SwapEffect], D3DSWAPEFFECT_FLIP
   @@:
        invoke  GetClientRect, [hwndmain], rect
        mov     eax, [rect.right]
        mov     [d3dpp.BackBufferWidth], eax                                          ; ñîõðàíÿåì â ñòðóêòóðå D3DPRESENT_PARAMETERS
        mov     eax, [rect.bottom]
        mov     [d3dpp.BackBufferHeight], eax

        comcall [context],IDirect3D8,GetDeviceCaps, NULL, D3DDEVTYPE_HAL, caps
        mov     eax,[caps.DevCaps]
        and     eax,D3DDEVCAPS_HWTRANSFORMANDLIGHT
        shr     eax,11
        add     eax,D3DCREATE_SOFTWARE_VERTEXPROCESSING

        comcall [context],IDirect3D8,CreateDevice, NULL, D3DDEVTYPE_HAL, [hwndmain], \
                                            eax,d3dpp,device
        or      eax,eax
        jz      @F
        mov     eax,errCreateDevice
        jmp     start.error
   @@:
        comcall [device],IDirect3DDevice8,CreateVertexBuffer, sizeof.D3DVECTOR*3, D3DUSAGE_WRITEONLY, D3DFVF_XYZ, \
                                                           D3DPOOL_MANAGED, triangle
        or      eax,eax
        jz     @F
        mov     eax,errCreateVertexBuffer
        jmp     start.error
   @@:
        comcall [triangle],IDirect3DVertexBuffer8,Lock,0,0,vertices,0
        or      eax,eax
        jz     @F
        mov     eax,errTriangleLock
        jmp     start.error
   @@:
        mov     ecx, [vertices]
        mov     dword [ecx], -1.0
        mov     dword [ecx + 4], 0.0
        mov     dword [ecx + 8], 2.0

        mov     dword [ecx + 12], 0.0
        mov     dword [ecx + 16], 1.0
        mov     dword [ecx + 20], 2.0

        mov     dword [ecx + 24], 1.0
        mov     dword [ecx + 28], 0.0
        mov     dword [ecx + 32], 2.0
        comcall [triangle],IDirect3DVertexBuffer8,Unlock

        finit
        fild    [scr.x]
        fidiv   [scr.y]
        fstp    [scr.x]
        invoke  D3DXMatrixPerspectiveFovLH, projection, 90°, [scr.x], 1.0, 1000.0
        comcall [device],IDirect3DDevice8,SetTransform, D3DTS_PROJECTION, projection
        comcall [device],IDirect3DDevice8,SetRenderState, D3DRS_FILLMODE, D3DFILL_WIREFRAME
        ret
endp

proc Free3D
        mov     eax,[triangle]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DVertexBuffer8,Release
        xor     eax,eax
        mov     [triangle],eax
   @@:
        mov     eax,[device]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice8,Release
        xor     eax,eax
        mov     [device],eax
   @@:
        mov     eax,[context]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice8,Release
        xor     eax,eax
        mov     [context],eax
   @@:
        ret
endp

proc RenderScene
        comcall [device],IDirect3DDevice8,TestCooperativeLevel
        cmp     eax,D3DERR_DEVICELOST                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jz      @render_exit
        cmp     eax, D3DERR_DEVICENOTRESET                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jnz     @reseted
        comcall [device],IDirect3DDevice8,Reset,d3dpp
   @reseted:
        comcall [device],IDirect3DDevice8,Clear,0,NULL,D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER,$808080,1.0,0
        comcall [device],IDirect3DDevice8,BeginScene

        comcall [device],IDirect3DDevice8,SetStreamSource, 0, [triangle], sizeof.D3DVECTOR
        comcall [device],IDirect3DDevice8,SetVertexShader, D3DFVF_XYZ
        comcall [device],IDirect3DDevice8,DrawPrimitive, D3DPT_TRIANGLELIST, 0, 1

        comcall [device],IDirect3DDevice8,EndScene
        comcall [device],IDirect3DDevice8,Present, NULL, NULL, NULL, NULL
   @render_exit:
        ret
endp

section '.data' data readable writeable
        wc              WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_OWNDC, WndProc,0,0,PE_IMAGE_BASE,0,0,0,0,szClassName,0
        szClassName     TCHAR 'demoD3D', 0
        szAppName       TCHAR '[02] Triangle D3D', 0
        szIsFullScreen  TCHAR 'Fullscreen mode ?', 0
        errCreate3D     TCHAR 'Direct3DCreate failed !', 0
        errGetAdapterDM TCHAR 'GetAdapterDisplayMode failed !', 0
        errCreateDevice TCHAR 'CreateDevice failed !', 0
        errCreateVertexBuffer TCHAR 'CreateVertexBuffer failed !', 0
        errTriangleLock TCHAR 'Triangle->Lock failed !', 0
        scr.x           dd 640
        scr.y           dd 480
        ;hdc            dd ?
        d3dpp           D3DPRESENT_PARAMETERS 0,0,0,2,0,D3DSWAPEFFECT_DISCARD,0,0,1,D3DFMT_D16,0,0,0
        DisplayMode     D3DDISPLAYMODE
        caps            D3DCAPS8
        projection      D3DMATRIX
        label hwndmain dword at d3dpp.hDeviceWindow ;hwndmain           dd ?
        label bWindowed at d3dpp.Windowed ;bwindowed          dd ?
        context         IDirect3D8
        device          IDirect3DDevice8
        triangle        IDirect3DVertexBuffer8

        rect            RECT
        msg             MSG
        bReady          dd ?
        vertices        dd ?

section '.idata' import data readable writeable
  library  kernel32, 'KERNEL32.DLL',\
           user32,   'USER32.DLL',\
           gdi32,    'GDI32.DLL',\
           d3d8,     'D3D8.DLL',\
           d3dx8d,   'D3DX8D.DLL'

        include  'os_specs/windows/api/x86/kernel32.inc'
        include  'os_specs/windows/api/x86/user32.inc'
        include  'os_specs/windows/api/x86/gdi32.inc'
        include  'os_specs/windows/api/x86/directx/d3d8.inc'
        include  'os_specs/windows/api/x86/directx/d3dx8d.inc'    


dx9:
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

include 'dx9(x32).inc'
WINDOWWIDTH  = 640
WINDOWHEIGHT = 480
D3D9b_SDK_VERSION = 31
90° equ 1.5707963267948966192313216916398

section '.text' code readable executable
start:
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClassEx,wc

        invoke  MessageBox, 0, szIsFullScreen, szAppName, MB_YESNO
        xor     eax,IDYES
        mov     [bWindowed],eax
        mov     ecx, WS_POPUP or WS_VISIBLE
        jz      @F
        mov     ecx, WS_OVERLAPPEDWINDOW or WS_VISIBLE
      @@:
        invoke  CreateWindowEx,0,szClassName,szAppName,ecx,100,75,WINDOWWIDTH,WINDOWHEIGHT,NULL,NULL,PE_IMAGE_BASE,NULL
        mov     [hwndmain],eax

        invoke  ShowWindow, [hwndmain], SW_SHOWNORMAL
        invoke  UpdateWindow, [hwndmain]

        stdcall Init3D
        or      eax,eax
        jz      .init_ok
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
        invoke  SendMessage, [hwndmain], WM_CLOSE, 0, 0
        jmp     .msgLoop
      .init_ok:
        inc     [bReady]
      .msgLoop:
        mov     eax,[msg.message]
        cmp     eax, WM_QUIT
        jz      .exitLoop
        invoke  PeekMessage, msg, NULL, 0, 0, PM_REMOVE
        or      eax,eax
        jz      .idleuse
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     .msgLoop
      .idleuse:
        mov     eax, [bReady]
        or      eax,eax
        jz      .msgLoop
        stdcall RenderScene
        jmp     .msgLoop
   .error:
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
   .exitLoop:
        stdcall Free3D
        mov     eax,[msg.wParam]
        invoke  ExitProcess, eax

proc WndProc hWnd, uMsg, wParam, lParam
        push    esi edi ebx
        mov     eax, [uMsg]
        cmp     eax, WM_KEYDOWN
        jz      .wmkeydown
        cmp     eax, WM_SETCURSOR
        jz      .wmsetcursor
        cmp     eax, WM_DESTROY
        jz      .wmdestroy
        cmp     eax, WM_CLOSE
        jnz     .def
        xor     eax, eax
        mov     [bReady], eax
   .def:
        invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
        jmp     .RetProc
   .wmkeydown:
        mov     eax, [wParam]
        cmp     eax, VK_ESCAPE
        jnz     .def
        invoke  SendMessage, [hWnd], WM_CLOSE, NULL, NULL
        jmp     .ExitProc
   .wmsetcursor:
        mov     eax,[bWindowed]
        or      eax, eax
        jnz     .def
        invoke  SetCursor, NULL
        jmp     .ExitProc
   .wmdestroy:
        invoke  PostQuitMessage, NULL
        xor     eax, eax
   .ExitProc:
   .RetProc:
        pop     ebx edi esi
        ret
endp

proc Init3D
        invoke  Direct3DCreate9, D3D9b_SDK_VERSION
        or      eax,eax
        jnz     @F
        mov     eax,errCreate3D
        jmp     start.error
   @@:
        mov     [context],eax
        comcall [context],IDirect3D9,GetAdapterDisplayMode, NULL, DisplayMode
        or      eax,eax
        jz     @F
        mov     eax,errGetAdapterDM
        jmp     start.error
   @@:
        mov     eax,[DisplayMode.Format]
        mov     [d3dpp.BackBufferFormat],eax

        mov     eax,[bWindowed]
        or      eax,eax
        jnz     @F
        mov     [d3dpp.SwapEffect], D3DSWAPEFFECT_FLIP
   @@:
        invoke  GetClientRect, [hwndmain], rect
        mov     eax, [rect.right]
        mov     [d3dpp.BackBufferWidth], eax                                          ; ñîõðàíÿåì â ñòðóêòóðå D3DPRESENT_PARAMETERS
        mov     eax, [rect.bottom]
        mov     [d3dpp.BackBufferHeight], eax

        comcall [context],IDirect3D9,GetDeviceCaps, NULL, D3DDEVTYPE_HAL, caps
        mov     eax,[caps.DevCaps]
        and     eax,D3DDEVCAPS_HWTRANSFORMANDLIGHT
        shr     eax,11
        add     eax,D3DCREATE_SOFTWARE_VERTEXPROCESSING

        comcall [context],IDirect3D9,CreateDevice, NULL, D3DDEVTYPE_HAL, [hwndmain], \
                                            eax,d3dpp,device
        or      eax,eax
        jz      @F
        mov     eax,errCreateDevice
        jmp     start.error
   @@:
        comcall [device],IDirect3DDevice9,CreateVertexBuffer, sizeof.D3DVECTOR*3, D3DUSAGE_WRITEONLY, D3DFVF_XYZ, \
                                                           D3DPOOL_MANAGED, triangle, 0
        or      eax,eax
        jz     @F
        mov     eax,errCreateVertexBuffer
        jmp     start.error
   @@:
        comcall [triangle],IDirect3DVertexBuffer9,Lock,0,0,vertices,0
        or      eax,eax
        jz     @F
        mov     eax,errTriangleLock
        jmp     start.error
   @@:
        mov     ecx, [vertices]
        mov     dword [ecx], -1.0
        mov     dword [ecx + 4], 0.0
        mov     dword [ecx + 8], 2.0

        mov     dword [ecx + 12], 0.0
        mov     dword [ecx + 16], 1.0
        mov     dword [ecx + 20], 2.0

        mov     dword [ecx + 24], 1.0
        mov     dword [ecx + 28], 0.0
        mov     dword [ecx + 32], 2.0
        comcall [triangle],IDirect3DVertexBuffer9,Unlock

        finit
        fild    [scr.x]
        fidiv    [scr.y]
        fstp    [scr.x]
        invoke  D3DXMatrixPerspectiveFovLH, projection, 90°, [scr.x], 1.0, 1000.0
        comcall [device],IDirect3DDevice9,SetTransform, D3DTS_PROJECTION, projection
        comcall [device],IDirect3DDevice9,SetRenderState, D3DRS_FILLMODE, D3DFILL_WIREFRAME
        ret
endp

proc Free3D
        mov     eax,[triangle]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DVertexBuffer9,Release
        xor     eax,eax
        mov     [triangle],eax
   @@:
        mov     eax,[device]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice9,Release
        xor     eax,eax
        mov     [device],eax
   @@:
        mov     eax,[context]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice9,Release
        xor     eax,eax
        mov     [context],eax
   @@:
        ret
endp

proc RenderScene
        comcall [device],IDirect3DDevice9,TestCooperativeLevel
        cmp     eax,D3DERR_DEVICELOST                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jz      @render_exit
        cmp     eax, D3DERR_DEVICENOTRESET                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jnz     @reseted
        comcall [device],IDirect3DDevice9,Reset,d3dpp
   @reseted:
        comcall [device],IDirect3DDevice9,Clear,0,NULL,D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER,$808080,1.0,0
        comcall [device],IDirect3DDevice9,BeginScene

        comcall [device],IDirect3DDevice9,SetStreamSource, 0, [triangle], 0, sizeof.D3DVECTOR
        comcall [device],IDirect3DDevice9,SetFVF, D3DFVF_XYZ
        comcall [device],IDirect3DDevice9,DrawPrimitive, D3DPT_TRIANGLELIST, 0, 1

        comcall [device],IDirect3DDevice9,EndScene
        comcall [device],IDirect3DDevice9,Present, NULL, NULL, NULL, NULL
   @render_exit:
        ret
endp

section '.data' data readable writeable
        wc              WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_OWNDC, WndProc,0,0,PE_IMAGE_BASE,0,0,0,0,szClassName,0
        szClassName     TCHAR 'demoD3D', 0
        szAppName       TCHAR '[02] Triangle D3D', 0
        szIsFullScreen  TCHAR 'Fullscreen mode ?', 0
        errCreate3D     TCHAR 'Direct3DCreate failed !', 0
        errGetAdapterDM TCHAR 'GetAdapterDisplayMode failed !', 0
        errCreateDevice TCHAR 'CreateDevice failed !', 0
        errCreateVertexBuffer TCHAR 'CreateVertexBuffer failed !', 0
        errTriangleLock TCHAR 'Triangle->Lock failed !', 0
        scr.x           dd 640
        scr.y           dd 480
        ;hdc            dd ?
        d3dpp           D3DPRESENT_PARAMETERS 0,0,0,2,0,0,D3DSWAPEFFECT_DISCARD,0,0,1,D3DFMT_D16,0,0,0
        DisplayMode     D3DDISPLAYMODE
        caps            D3DCAPS9
        projection      D3DMATRIX
        label hwndmain dword at d3dpp.hDeviceWindow ;hwndmain           dd ?
        label bWindowed at d3dpp.Windowed ;bwindowed          dd ?
        context         IDirect3D9
        device          IDirect3DDevice9
        triangle        IDirect3DVertexBuffer9

        rect            RECT
        msg             MSG
        bReady          dd ?
        vertices        dd ?

section '.idata' import data readable writeable
  library  kernel32, 'KERNEL32.DLL',\
           user32,   'USER32.DLL',\
           gdi32,    'GDI32.DLL',\
           d3d9,     'D3D9.DLL',\
           d3dx9_24, 'D3DX9_24.DLL'

        include  'os_specs/windows/api/x86/kernel32.inc'
        include  'os_specs/windows/api/x86/user32.inc'
        include  'os_specs/windows/api/x86/gdi32.inc'
        include  'os_specs/windows/api/x86/directx/d3d9.inc'
        include  'os_specs/windows/api/x86/directx/d3dx9_24.inc'    


opengl(I guess opengl1.0-2.0):
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

include 'technlgy/pseudo3d/opengl/equates/opengl.inc'
WINDOWWIDTH  = 640
WINDOWHEIGHT = 480

section '.text' code readable executable
start:
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClassEx,wc

        invoke  MessageBox, 0, szIsFullScreen, szAppName, MB_YESNO
        xor     eax,IDYES
        mov     [bWindowed],eax
        mov     ecx, WS_POPUP or WS_VISIBLE
        jz      @F
        mov     ecx, WS_OVERLAPPEDWINDOW or WS_VISIBLE
      @@:
        invoke  CreateWindowEx,0,szClassName,szAppName,ecx,100,75,WINDOWWIDTH,WINDOWHEIGHT,NULL,NULL,PE_IMAGE_BASE,NULL
        mov     [hwndmain],eax

        invoke  ShowWindow, [hwndmain], SW_SHOWNORMAL
        invoke  UpdateWindow, [hwndmain]

        stdcall Init3D
        or      eax,eax
        jz      .init_ok
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
        invoke  SendMessage, [hwndmain], WM_CLOSE, 0, 0
        jmp     .msgLoop
      .init_ok:
        inc     [bReady]
      .msgLoop:
        mov     eax,[msg.message]
        cmp     eax, WM_QUIT
        jz      .exitLoop
        invoke  PeekMessage, msg, NULL, 0, 0, PM_REMOVE
        or      eax,eax
        jz      .idleuse
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     .msgLoop
      .idleuse:
        mov     eax, [bReady]
        or      eax,eax
        jz      .msgLoop
        stdcall RenderScene
        jmp     .msgLoop
   .error:
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
   .exitLoop:
        stdcall Free3D
        mov     eax,[msg.wParam]
        invoke  ExitProcess, eax

proc WndProc hWnd, uMsg, wParam, lParam
        push    esi edi ebx
        mov     eax, [uMsg]
        cmp     eax, WM_KEYDOWN
        jz      .wmkeydown
        cmp     eax, WM_SETCURSOR
        jz      .wmsetcursor
        cmp     eax, WM_DESTROY
        jz      .wmdestroy
        cmp     eax, WM_CLOSE
        jnz     .def
        xor     eax, eax
        mov     [bReady], eax
   .def:
        invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
        jmp     .RetProc
   .wmkeydown:
        mov     eax, [wParam]
        cmp     eax, VK_ESCAPE
        jnz     .def
        invoke  SendMessage, [hWnd], WM_CLOSE, NULL, NULL
        jmp     .ExitProc
   .wmsetcursor:
        mov     eax,[bWindowed]
        or      eax, eax
        jnz     .def
        invoke  SetCursor, NULL
        jmp     .ExitProc
   .wmdestroy:
        invoke  PostQuitMessage, NULL
        xor     eax, eax
   .ExitProc:
   .RetProc:
        pop     ebx edi esi
        ret
endp

proc Init3D
        invoke  GetDC,[hwndmain]
        mov     [hdc],eax
        invoke  ChoosePixelFormat, eax, pfd
        invoke  SetPixelFormat, [hdc], eax, pfd
        invoke  wglCreateContext,[hdc]
        or      eax,eax
        jnz     @F
        int3
        mov     eax,errCreate3D
        jmp     start.error
   @@:
        mov     [context],eax
        invoke  wglMakeCurrent,[hdc],[context]
        invoke  GetClientRect,[hwndmain],rect
        invoke  glClearColor,0.5,0.5,0.5,1.0
        invoke  glViewport,0,0,[rect.right],[rect.bottom]

        invoke  glMatrixMode, GL_PROJECTION
        invoke  glLoadIdentity

        finit
        fild    [rect.right]
        fidiv   [rect.bottom]
        fstp    [aspectRatio]
        invoke  gluPerspective, qword 90.0, qword [aspectRatio], qword 1.0, qword 1000.0
        invoke  glMatrixMode, GL_MODELVIEW
        xor     eax,eax
        ret
endp

proc Free3D
        invoke  wglMakeCurrent,0,0
        invoke  wglDeleteContext,[context]
        invoke  ReleaseDC,[hwndmain],[hdc]
     ret
endp

proc RenderScene
        invoke  glClear,GL_COLOR_BUFFER_BIT
        invoke  glBegin,GL_LINE_LOOP
        invoke  glColor3f, 0.0, 0.0, 0.0
        invoke  glVertex3f, -1.0,  0.0, -2.0
        invoke  glVertex3f,  0.0,  1.0, -2.0
        invoke  glVertex3f,  1.0,  0.0, -2.0
        invoke  glEnd

        invoke  SwapBuffers,[hdc]
   @render_exit:
     ret
endp

section '.data' data readable writeable
        wc              WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_OWNDC, WndProc,0,0,PE_IMAGE_BASE,0,0,0,0,szClassName,0
        pfd             PIXELFORMATDESCRIPTOR sizeof.PIXELFORMATDESCRIPTOR, 1, \
                        PFD_DRAW_TO_WINDOW or PFD_SUPPORT_OPENGL or PFD_TYPE_RGBA or PFD_DOUBLEBUFFER ,\ ;PFD_DOUBLEBUFFER or
                        32,\ ;Select Our Color Depth
                        0, 0, 0, 0, 0, 0,\ ;Color Bits Ignored
                        0,\ ;No Alpha Buffer
                        0,\ ;Shift Bit Ignored
                        0,\          ;No Accumulation Buffer
                        0, 0, 0, 0,\ ;Accumulation Bits Ignored
                        16,\         ;16Bit Z-Buffer (Depth Buffer)
                        0,\          ;No Stencil Buffer
                        0,\          ;No Auxiliary Buffer
                        PFD_MAIN_PLANE,\ ;Main Drawing Layer
                        0,\          ;Reserved
                        0, 0, 0      ;Layer Masks Ignored
        szClassName     TCHAR 'demoOpenGL', 0
        szAppName       TCHAR '[01] Init OpenGL', 0
        szIsFullScreen  TCHAR 'Fullscreen mode ?', 0
        errCreate3D     TCHAR 'OpenGL create context failed !', 0
        hdc             dd ?
        hwndmain        dd ?
        bWindowed       dd ?
        context         dd ?
        aspectRatio     dq ?

        rect            RECT
        msg             MSG
        bReady          dd ?

section '.idata' import data readable writeable
  library  kernel32, 'KERNEL32.DLL',\
           user32,   'USER32.DLL',\
           gdi32,    'GDI32.DLL',\
           opengl32, 'OPENGL32.DLL',\
           glu32,    'GLU32.DLL'

        include  'os_specs/windows/api/x86/kernel32.inc'
        include  'os_specs/windows/api/x86/user32.inc'
        include  'os_specs/windows/api/x86/gdi32.inc'
        include  'os_specs/windows/api/x86/opengl/opengl32.inc'
        include  'os_specs/windows/api/x86/opengl/glu32.inc'    


until opengl3.0 vertex buffer is abstraction that programmer should realize itself.
(due to laziness our own realization of custom vertex buffer dosn`t provided, in this simplest case it is slower and no needance in it) (example is targeted to opengl pre 3.0, so no support of vertex buffer from opengl natively)

But differences on supporting of vertex buffers dosn`t end.
In opengl case we have to place triangle in plane with Z=-2, while plane with Z=2 is unvisible. In case of directX everithing mirrored about Z axis: plane with Z=2 visible, but plane with Z=-2 is unvisible.

One more differences:
default sizing behavior: in case of directX world is scalable
while for opengl case world is fixed sized and anchored to bottom-left corner.

;==================================================================
01 CUBE
dx8:
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

include 'dx8(x32).inc'
WINDOWWIDTH  = 640
WINDOWHEIGHT = 480
D3D81_SDK_VERSION = 220
90° equ 1.5707963267948966192313216916398
sizeof.WORD = 2

section '.text' code readable executable
start:
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClassEx,wc

        invoke  MessageBox, 0, szIsFullScreen, szAppName, MB_YESNO
        xor     eax,IDYES
        mov     [bWindowed],eax
        mov     ecx, WS_POPUP or WS_VISIBLE
        jz      @F
        mov     ecx, WS_OVERLAPPEDWINDOW or WS_VISIBLE
      @@:
        invoke  CreateWindowEx,0,szClassName,szAppName,ecx,100,75,WINDOWWIDTH,WINDOWHEIGHT,NULL,NULL,PE_IMAGE_BASE,NULL
        mov     [hwndmain],eax

        invoke  ShowWindow, [hwndmain], SW_SHOWNORMAL
        invoke  UpdateWindow, [hwndmain]

        stdcall Init3D
        or      eax,eax
        jz      .init_ok
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
        invoke  SendMessage, [hwndmain], WM_CLOSE, 0, 0
        jmp     .msgLoop
      .init_ok:
        inc     [bReady]
      .msgLoop:
        mov     eax,[msg.message]
        cmp     eax, WM_QUIT
        jz      .exitLoop
        invoke  PeekMessage, msg, NULL, 0, 0, PM_REMOVE
        or      eax,eax
        jz      .idleuse
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     .msgLoop
      .idleuse:
        mov     eax, [bReady]
        or      eax,eax
        jz      .msgLoop
        stdcall RenderScene
        jmp     .msgLoop
   .error:
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
   .exitLoop:
        stdcall Free3D
        mov     eax,[msg.wParam]
        invoke  ExitProcess, eax

proc WndProc hWnd, uMsg, wParam, lParam
        push    esi edi ebx
        mov     eax, [uMsg]
        cmp     eax, WM_KEYDOWN
        jz      .wmkeydown
        cmp     eax, WM_SETCURSOR
        jz      .wmsetcursor
        cmp     eax, WM_DESTROY
        jz      .wmdestroy
        cmp     eax, WM_CLOSE
        jnz     .def
        xor     eax, eax
        mov     [bReady], eax
   .def:
        invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
        jmp     .RetProc
   .wmkeydown:
        mov     eax, [wParam]
        cmp     eax, VK_ESCAPE
        jnz     .def
        invoke  SendMessage, [hWnd], WM_CLOSE, NULL, NULL
        jmp     .ExitProc
   .wmsetcursor:
        mov     eax,[bWindowed]
        or      eax, eax
        jnz     .def
        invoke  SetCursor, NULL
        jmp     .ExitProc
   .wmdestroy:
        invoke  PostQuitMessage, NULL
        xor     eax, eax
   .ExitProc:
   .RetProc:
        pop     ebx edi esi
        ret
endp

proc Init3D
        invoke  Direct3DCreate8, D3D81_SDK_VERSION
        or      eax,eax
        jnz     @F
        mov     eax,errCreate3D
        jmp     start.error
   @@:
        mov     [context],eax
        comcall [context],IDirect3D8,GetAdapterDisplayMode, NULL, DisplayMode
        or      eax,eax
        jz     @F
        mov     eax,errGetAdapterDM
        jmp     start.error
   @@:
        mov     eax,[DisplayMode.Format]
        mov     [d3dpp.BackBufferFormat],eax

        mov     eax,[bWindowed]
        or      eax,eax
        jnz     @F
        mov     [d3dpp.SwapEffect], D3DSWAPEFFECT_FLIP
   @@:
        invoke  GetClientRect, [hwndmain], rect
        mov     eax, [rect.right]
        mov     [d3dpp.BackBufferWidth], eax                                          ; ñîõðàíÿåì â ñòðóêòóðå D3DPRESENT_PARAMETERS
        mov     eax, [rect.bottom]
        mov     [d3dpp.BackBufferHeight], eax

        comcall [context],IDirect3D8,GetDeviceCaps, NULL, D3DDEVTYPE_HAL, caps
        mov     eax,[caps.DevCaps]
        and     eax,D3DDEVCAPS_HWTRANSFORMANDLIGHT
        shr     eax,11
        add     eax,D3DCREATE_SOFTWARE_VERTEXPROCESSING

        comcall [context],IDirect3D8,CreateDevice, NULL, D3DDEVTYPE_HAL, [hwndmain], \
                                            eax,d3dpp,device
        or      eax,eax
        jz      @F
        mov     eax,errCreateDevice
        jmp     start.error
   @@:
     comcall [device],IDirect3DDevice8,CreateVertexBuffer, sizeof.D3DVECTOR*8, D3DUSAGE_WRITEONLY, D3DFVF_XYZ, \
                                                           D3DPOOL_MANAGED, vb
        or      eax,eax
        jz     @F
        mov     eax,errCreateVertexBuffer
        jmp     start.error
   @@:
        comcall [device],IDirect3DDevice8,CreateIndexBuffer, 36*sizeof.WORD, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, \
                                                           D3DPOOL_MANAGED, ib
        or      eax,eax
        jz     @F
        mov     eax,errCreateIndexBuffer
        jmp     start.error
   @@:
        comcall [vb],IDirect3DVertexBuffer8,Lock,0,0,vertices,0
        or      eax,eax
        jz     @F
        mov     eax,errTriangleLock
        jmp     start.error
   @@:
        mov     edi, [vertices]
        mov     esi, cube.vtx.data
        mov     ecx, sizeof.D3DVECTOR*8/4
        rep     movsd
        comcall [vb],IDirect3DVertexBuffer8,Unlock

        comcall [ib],IDirect3DIndexBuffer8,Lock,0,0,indices,0
        or      eax,eax
        jz     @F
        mov     eax,errTriangleLock
        jmp     start.error
   @@:
        mov     edi, [indices]
        mov     esi, cube.idx.data
        mov     ecx, 36*sizeof.WORD/4
        rep     movsd
        comcall [ib],IDirect3DIndexBuffer8,Unlock

        invoke  D3DXMatrixLookAtLH, cam.view.matrix, cam.pos, cam.focus, cam.up
        comcall [device],IDirect3DDevice8,SetTransform, D3DTS_VIEW, cam.view.matrix

        finit
        fild    [scr.x]
        fidiv   [scr.y]
        fstp    [scr.x]
        invoke  D3DXMatrixPerspectiveFovLH, cam.proj.matrix, 90°, [scr.x], 1.0, 1000.0
        comcall [device],IDirect3DDevice8,SetTransform, D3DTS_PROJECTION, cam.proj.matrix
        comcall [device],IDirect3DDevice8,SetRenderState, D3DRS_FILLMODE, D3DFILL_WIREFRAME
        ret
endp

proc Free3D
        mov     eax,[vb]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DVertexBuffer8,Release
        xor     eax,eax
        mov     [vb],eax
   @@:
        mov     eax,[ib]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DIndexBuffer8,Release
        xor     eax,eax
        mov     [ib],eax
   @@:
        mov     eax,[device]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice8,Release
        xor     eax,eax
        mov     [device],eax
   @@:
        mov     eax,[context]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice8,Release
        xor     eax,eax
        mov     [context],eax
   @@:
        ret
endp

proc RenderScene
        comcall [device],IDirect3DDevice8,TestCooperativeLevel
        cmp     eax,D3DERR_DEVICELOST                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jz      @render_exit
        cmp     eax, D3DERR_DEVICENOTRESET                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jnz     @reseted
        comcall [device],IDirect3DDevice8,Reset,d3dpp
   @reseted:
        comcall [device],IDirect3DDevice8,Clear,0,NULL,D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER,$808080,1.0,0

        comcall [device],IDirect3DDevice8,SetStreamSource, 0, [vb], sizeof.D3DVECTOR
        comcall [device],IDirect3DDevice8,SetIndices, [ib], 0
        comcall [device],IDirect3DDevice8,SetVertexShader, D3DFVF_XYZ

        comcall [device],IDirect3DDevice8,BeginScene

        comcall [device],IDirect3DDevice8,DrawIndexedPrimitive, D3DPT_TRIANGLELIST, 0, 8, 0, 12

        comcall [device],IDirect3DDevice8,EndScene
        comcall [device],IDirect3DDevice8,Present, NULL, NULL, NULL, NULL
   @render_exit:
        ret
endp

section '.data' data readable writeable
        wc              WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_OWNDC, WndProc,0,0,PE_IMAGE_BASE,0,0,0,0,szClassName,0
        szClassName     TCHAR 'demoD3D', 0
        szAppName       TCHAR '[03] Cube D3D', 0
        szIsFullScreen  TCHAR 'Fullscreen mode ?', 0
        errCreate3D     TCHAR 'Direct3DCreate failed !', 0
        errGetAdapterDM TCHAR 'GetAdapterDisplayMode failed !', 0
        errCreateDevice TCHAR 'CreateDevice failed !', 0
        errCreateVertexBuffer TCHAR 'CreateVertexBuffer failed !', 0
        errCreateIndexBuffer TCHAR 'CreateIndexBuffer failed !', 0
        errTriangleLock TCHAR 'Triangle->Lock failed !', 0
  align              4
  cube.vtx.data:
                        dd -1.0, -1.0, -1.0
                        dd -1.0,  1.0, -1.0
                        dd  1.0,  1.0, -1.0
                        dd  1.0, -1.0, -1.0
                        dd -1.0, -1.0,  1.0
                        dd -1.0,  1.0,  1.0
                        dd  1.0,  1.0,  1.0
                        dd  1.0, -1.0,  1.0
  cube.idx.data:
                        dw 0, 1, 2, 0, 2, 3
                        dw 4, 6, 5, 4, 7, 6
                        dw 4, 5, 1, 4, 1, 0
                        dw 3, 2, 6, 3, 6, 7
                        dw 1, 5, 6, 1, 6, 2
                        dw 4, 0, 3, 4, 3, 7

        cam.pos         dd 0.0, 0.0, -5.0
        cam.focus       dd 0.0, 0.0, 0.0
        cam.up          dd 0.0, 1.0, 0.0

        scr.x           dd 640
        scr.y           dd 480
        ;hdc            dd ?
        d3dpp           D3DPRESENT_PARAMETERS 0,0,0,2,0,D3DSWAPEFFECT_DISCARD,0,0,1,D3DFMT_D16,0,0,0
        DisplayMode     D3DDISPLAYMODE
        caps            D3DCAPS8
        ;projection      D3DMATRIX
        label hwndmain dword at d3dpp.hDeviceWindow ;hwndmain           dd ?
        label bWindowed at d3dpp.Windowed ;bwindowed          dd ?
        context         IDirect3D8
        device          IDirect3DDevice8
        vb              IDirect3DVertexBuffer8
        vertices        dd ?
        ib              IDirect3DIndexBuffer8
        indices         dd ?

        rect            RECT
        msg             MSG
        bReady          dd ?

        rx                      D3DMATRIX
        ry                      D3DMATRIX
        cam.proj.matrix         D3DMATRIX
        cam.view.matrix         D3DMATRIX

section '.idata' import data readable writeable
  library  kernel32, 'KERNEL32.DLL',\
           user32,   'USER32.DLL',\
           gdi32,    'GDI32.DLL',\
           d3d8,     'D3D8.DLL',\
           d3dx8d,   'D3DX8D.DLL'

        include  'os_specs/windows/api/x86/kernel32.inc'
        include  'os_specs/windows/api/x86/user32.inc'
        include  'os_specs/windows/api/x86/gdi32.inc'
        include  'os_specs/windows/api/x86/directx/d3d8.inc'
        include  'os_specs/windows/api/x86/directx/d3dx8d.inc'    


dx9:
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

include 'dx9(x32).inc'
WINDOWWIDTH  = 640
WINDOWHEIGHT = 480
D3D9b_SDK_VERSION = 31
90° equ 1.5707963267948966192313216916398
sizeof.WORD = 2

section '.text' code readable executable
start:
        invoke  LoadIcon,0,IDI_APPLICATION
        mov     [wc.hIcon],eax
        invoke  LoadCursor,0,IDC_ARROW
        mov     [wc.hCursor],eax
        invoke  RegisterClassEx,wc

        invoke  MessageBox, 0, szIsFullScreen, szAppName, MB_YESNO
        xor     eax,IDYES
        mov     [bWindowed],eax
        mov     ecx, WS_POPUP or WS_VISIBLE
        jz      @F
        mov     ecx, WS_OVERLAPPEDWINDOW or WS_VISIBLE
      @@:
        invoke  CreateWindowEx,0,szClassName,szAppName,ecx,100,75,WINDOWWIDTH,WINDOWHEIGHT,NULL,NULL,PE_IMAGE_BASE,NULL
        mov     [hwndmain],eax

        invoke  ShowWindow, [hwndmain], SW_SHOWNORMAL
        invoke  UpdateWindow, [hwndmain]

        stdcall Init3D
        or      eax,eax
        jz      .init_ok
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
        invoke  SendMessage, [hwndmain], WM_CLOSE, 0, 0
        jmp     .msgLoop
      .init_ok:
        inc     [bReady]
      .msgLoop:
        mov     eax,[msg.message]
        cmp     eax, WM_QUIT
        jz      .exitLoop
        invoke  PeekMessage, msg, NULL, 0, 0, PM_REMOVE
        or      eax,eax
        jz      .idleuse
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp     .msgLoop
      .idleuse:
        mov     eax, [bReady]
        or      eax,eax
        jz      .msgLoop
        stdcall RenderScene
        jmp     .msgLoop
   .error:
        invoke  MessageBox, [hwndmain], eax, szAppName, MB_OK
   .exitLoop:
        stdcall Free3D
        mov     eax,[msg.wParam]
        invoke  ExitProcess, eax

proc WndProc hWnd, uMsg, wParam, lParam
        push    esi edi ebx
        mov     eax, [uMsg]
        cmp     eax, WM_KEYDOWN
        jz      .wmkeydown
        cmp     eax, WM_SETCURSOR
        jz      .wmsetcursor
        cmp     eax, WM_DESTROY
        jz      .wmdestroy
        cmp     eax, WM_CLOSE
        jnz     .def
        xor     eax, eax
        mov     [bReady], eax
   .def:
        invoke  DefWindowProc, [hWnd], [uMsg], [wParam], [lParam]
        jmp     .RetProc
   .wmkeydown:
        mov     eax, [wParam]
        cmp     eax, VK_ESCAPE
        jnz     .def
        invoke  SendMessage, [hWnd], WM_CLOSE, NULL, NULL
        jmp     .ExitProc
   .wmsetcursor:
        mov     eax,[bWindowed]
        or      eax, eax
        jnz     .def
        invoke  SetCursor, NULL
        jmp     .ExitProc
   .wmdestroy:
        invoke  PostQuitMessage, NULL
        xor     eax, eax
   .ExitProc:
   .RetProc:
        pop     ebx edi esi
        ret
endp

proc Init3D
        invoke  Direct3DCreate9, D3D9b_SDK_VERSION
        or      eax,eax
        jnz     @F
        mov     eax,errCreate3D
        jmp     start.error
   @@:
        mov     [context],eax
        comcall [context],IDirect3D9,GetAdapterDisplayMode, NULL, DisplayMode
        or      eax,eax
        jz     @F
        mov     eax,errGetAdapterDM
        jmp     start.error
   @@:
        mov     eax,[DisplayMode.Format]
        mov     [d3dpp.BackBufferFormat],eax

        mov     eax,[bWindowed]
        or      eax,eax
        jnz     @F
        mov     [d3dpp.SwapEffect], D3DSWAPEFFECT_FLIP
   @@:
        invoke  GetClientRect, [hwndmain], rect
        mov     eax, [rect.right]
        mov     [d3dpp.BackBufferWidth], eax                                          ; ñîõðàíÿåì â ñòðóêòóðå D3DPRESENT_PARAMETERS
        mov     eax, [rect.bottom]
        mov     [d3dpp.BackBufferHeight], eax

        comcall [context],IDirect3D9,GetDeviceCaps, NULL, D3DDEVTYPE_HAL, caps
        mov     eax,[caps.DevCaps]
        and     eax,D3DDEVCAPS_HWTRANSFORMANDLIGHT
        shr     eax,11
        add     eax,D3DCREATE_SOFTWARE_VERTEXPROCESSING

        comcall [context],IDirect3D9,CreateDevice, NULL, D3DDEVTYPE_HAL, [hwndmain], \
                                            eax,d3dpp,device
        or      eax,eax
        jz      @F
        mov     eax,errCreateDevice
        jmp     start.error
   @@:
     comcall [device],IDirect3DDevice9,CreateVertexBuffer, sizeof.D3DVECTOR*8, D3DUSAGE_WRITEONLY, D3DFVF_XYZ, \
                                                           D3DPOOL_MANAGED, vb, 0
        or      eax,eax
        jz     @F
        mov     eax,errCreateVertexBuffer
        jmp     start.error
   @@:
        comcall [device],IDirect3DDevice9,CreateIndexBuffer, 36*sizeof.WORD, D3DUSAGE_WRITEONLY, D3DFMT_INDEX16, \
                                                           D3DPOOL_MANAGED, ib, 0
        or      eax,eax
        jz     @F
        mov     eax,errCreateIndexBuffer
        jmp     start.error
   @@:
        comcall [vb],IDirect3DVertexBuffer9,Lock,0,0,vertices,0
        or      eax,eax
        jz     @F
        mov     eax,errTriangleLock
        jmp     start.error
   @@:
        mov     edi, [vertices]
        mov     esi, cube.vtx.data
        mov     ecx, sizeof.D3DVECTOR*8/4
        rep     movsd
        comcall [vb],IDirect3DVertexBuffer9,Unlock

        comcall [ib],IDirect3DIndexBuffer9,Lock,0,0,indices,0
        or      eax,eax
        jz     @F
        mov     eax,errTriangleLock
        jmp     start.error
   @@:
        mov     edi, [indices]
        mov     esi, cube.idx.data
        mov     ecx, 36*sizeof.WORD/4
        rep     movsd
        comcall [ib],IDirect3DIndexBuffer9,Unlock

        invoke  D3DXMatrixLookAtLH, cam.view.matrix, cam.pos, cam.focus, cam.up
        comcall [device],IDirect3DDevice9,SetTransform, D3DTS_VIEW, cam.view.matrix

        finit
        fild    [scr.x]
        fidiv    [scr.y]
        fstp    [scr.x]
        invoke  D3DXMatrixPerspectiveFovLH, cam.proj.matrix, 90°, [scr.x], 1.0, 1000.0
        comcall [device],IDirect3DDevice9,SetTransform, D3DTS_PROJECTION, cam.proj.matrix
        comcall [device],IDirect3DDevice9,SetRenderState, D3DRS_FILLMODE, D3DFILL_WIREFRAME
        ret
endp

proc Free3D
        mov     eax,[vb]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DVertexBuffer9,Release
        xor     eax,eax
        mov     [vb],eax
   @@:
        mov     eax,[ib]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DIndexBuffer9,Release
        xor     eax,eax
        mov     [ib],eax
   @@:
        mov     eax,[device]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice9,Release
        xor     eax,eax
        mov     [device],eax
   @@:
        mov     eax,[context]
        or      eax,eax
        jz      @F
        comcall eax,IDirect3DDevice9,Release
        xor     eax,eax
        mov     [context],eax
   @@:
        ret
endp

proc RenderScene
        comcall [device],IDirect3DDevice9,TestCooperativeLevel
        cmp     eax,D3DERR_DEVICELOST                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jz      @render_exit
        cmp     eax, D3DERR_DEVICENOTRESET                                             ; åñëè óñòðîéñòâî ïîòåðÿíî
        jnz     @reseted
        comcall [device],IDirect3DDevice9,Reset,d3dpp
   @reseted:
        comcall [device],IDirect3DDevice9,Clear,0,NULL,D3DCLEAR_TARGET or D3DCLEAR_ZBUFFER,$808080,1.0,0

        comcall [device],IDirect3DDevice9,SetStreamSource, 0, [vb], 0, sizeof.D3DVECTOR
        comcall [device],IDirect3DDevice9,SetIndices, [ib]
        comcall [device],IDirect3DDevice9,SetFVF, D3DFVF_XYZ

        comcall [device],IDirect3DDevice9,BeginScene

        comcall [device],IDirect3DDevice9,DrawIndexedPrimitive, D3DPT_TRIANGLELIST, 0, 0, 8, 0, 12

        comcall [device],IDirect3DDevice9,EndScene
        comcall [device],IDirect3DDevice9,Present, NULL, NULL, NULL, NULL
   @render_exit:
        ret
endp

section '.data' data readable writeable
        wc              WNDCLASSEX sizeof.WNDCLASSEX, CS_HREDRAW or CS_VREDRAW or CS_OWNDC, WndProc,0,0,PE_IMAGE_BASE,0,0,0,0,szClassName,0
        szClassName     TCHAR 'demoD3D', 0
        szAppName       TCHAR '[03] Cube D3D', 0
        szIsFullScreen  TCHAR 'Fullscreen mode ?', 0
        errCreate3D     TCHAR 'Direct3DCreate failed !', 0
        errGetAdapterDM TCHAR 'GetAdapterDisplayMode failed !', 0
        errCreateDevice TCHAR 'CreateDevice failed !', 0
        errCreateVertexBuffer TCHAR 'CreateVertexBuffer failed !', 0
        errCreateIndexBuffer TCHAR 'CreateIndexBuffer failed !', 0
        errTriangleLock TCHAR 'Triangle->Lock failed !', 0
  align              4
  cube.vtx.data:
                        dd -1.0, -1.0, -1.0
                        dd -1.0,  1.0, -1.0
                        dd  1.0,  1.0, -1.0
                        dd  1.0, -1.0, -1.0
                        dd -1.0, -1.0,  1.0
                        dd -1.0,  1.0,  1.0
                        dd  1.0,  1.0,  1.0
                        dd  1.0, -1.0,  1.0
  cube.idx.data:
                        dw 0, 1, 2, 0, 2, 3
                        dw 4, 6, 5, 4, 7, 6
                        dw 4, 5, 1, 4, 1, 0
                        dw 3, 2, 6, 3, 6, 7
                        dw 1, 5, 6, 1, 6, 2
                        dw 4, 0, 3, 4, 3, 7

        cam.pos         dd 0.0, 0.0, -5.0
        cam.focus       dd 0.0, 0.0, 0.0
        cam.up          dd 0.0, 1.0, 0.0

        scr.x           dd 640
        scr.y           dd 480
        ;hdc            dd ?
        d3dpp           D3DPRESENT_PARAMETERS 0,0,0,2,0,0,D3DSWAPEFFECT_DISCARD,0,0,1,D3DFMT_D16,0,0,0
        DisplayMode     D3DDISPLAYMODE
        caps            D3DCAPS9
        ;projection      D3DMATRIX
        label hwndmain dword at d3dpp.hDeviceWindow ;hwndmain           dd ?
        label bWindowed at d3dpp.Windowed ;bwindowed          dd ?
        context         IDirect3D9
        device          IDirect3DDevice9
        vb              IDirect3DVertexBuffer9
        vertices        dd ?
        ib              IDirect3DIndexBuffer9
        indices         dd ?

        rect            RECT
        msg             MSG
        bReady          dd ?

        rx                      D3DMATRIX
        ry                      D3DMATRIX
        cam.proj.matrix         D3DMATRIX
        cam.view.matrix         D3DMATRIX

section '.idata' import data readable writeable
  library  kernel32, 'KERNEL32.DLL',\
           user32,   'USER32.DLL',\
           gdi32,    'GDI32.DLL',\
           d3d9,     'D3D9.DLL',\
           d3dx9_24, 'D3DX9_24.DLL'

        include  'os_specs/windows/api/x86/kernel32.inc'
        include  'os_specs/windows/api/x86/user32.inc'
        include  'os_specs/windows/api/x86/gdi32.inc'
        include  'os_specs/windows/api/x86/directx/d3d9.inc'
        include  'os_specs/windows/api/x86/directx/d3dx9_24.inc'    


I not make CUBE example for opengl

all above https://sourceforge.net/projects/includes-repack-for-fasm1/files/fasmpack/DEMOS/EXECS/WINDOWS/WIN32/GRAPHIC/PSEUDO3D
(includes In Win7 and preWin7 fasmpack works from any directory even with " " in path, In Win10 only in root of disk)

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.


Last edited by ProMiNick on 09 Nov 2020, 05:48; edited 1 time in total
Post 06 Nov 2020, 09:59
View user's profile Send private message Send e-mail Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 510
Ali.Z
off-topic:
do you know whats projection matrix? view matrix? how to xyz coords transform into screen coords? and how camera pitch, yaw, and roll come in place to affect these stuff?

_________________
Asm For Wise Humans
Post 09 Nov 2020, 02:13
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 660
Location: Russian Federation, Sochi
ProMiNick
I can suppose projection matrix in dx is Left handed (I used LH variant of function & it is default for dx):
Code:
invoke  D3DXMatrixPerspectiveFovLH, projection, 90°, [scr.x], 1.0, 1000.0; I don`t enter var aspectRatio but calc its value exact in scr.x    

while in opengl it is right handed (I guess):
Code:
invoke  gluPerspective, qword 90.0, qword [aspectRatio], qword 1.0, qword 1000.0    

all rest are renderers defaults.
I guess View & world matrices are ident matrices
Code:
1.0, 0.0, 0.0, 0.0
0.0, 1.0, 0.0, 0.0
0.0, 0.0, 1.0, 0.0
0.0, 0.0, 0.0, 1.0    
pitch, yaw, and roll I guess zeroes too.
Post 09 Nov 2020, 05:46
View user's profile Send private message Send e-mail Reply with quote
Ali.Z



Joined: 08 Jan 2018
Posts: 510
Ali.Z
ok so i refreshed some of my information by playing with CryEngine little bit, so pitch can go from negative 90 to positive 90, we can imagine pitch like leaning our head forward. (looking down and up at the sky)
yaw goes from negative 180 to positive 180, that is like turning the head from left to right.

also regarding matrices, it looks like opengl is column major and directx is row major, so when it comes to matrix transformation the order matter depending on whether its column or row major.

_________________
Asm For Wise Humans
Post 09 Nov 2020, 13:04
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 227
donn
Cool! Do you have screenshots? If not I can run your examples...
Post 09 Nov 2020, 20:52
View user's profile Send private message Reply with quote
ProMiNick



Joined: 24 Mar 2012
Posts: 660
Location: Russian Federation, Sochi
ProMiNick
In plans provide same examples for dx2 up to dx12(lib support, not OS), ogl1 to ogl3, and ogl in other OSes. (In dx1 too but that would be ddraw emulation of 3D rendering).
Something of evolutiom of renderer engines.
Set of includes currently extending that related to dx in current state to retro dx1,dx2, retained mode of dx2-dx7 - is in progress so not shared.
there already working examples of dx7 INIT & TRIANGLE, but thay looks ... - need time to make everithing in one style.
Post 09 Nov 2020, 22:29
View user's profile Send private message Send e-mail Reply with quote
donn



Joined: 05 Mar 2010
Posts: 227
donn
No problem. I have an old Visual Studio DX11 project (not 100% fasm) and a newer Vulkan project (100% fasm), which works with WINAPI and has a working swap chain if I recall. I'm more into Compute Shaders like AMD APP and the nitty gritty of SPIR-V so my projects are not nearly as focused as yours, but your examples are great and helpful.
Post 10 Nov 2020, 19:31
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 786
Location: Massachusetts, USA
bitshifter
you can setup the projection matrix in GL for top left origin with scale and transform
this may affect normalised lighting but its nice for 2D ortho view
also direct ops like raster position will still origin from bottom left
and yes, DX and GL use opposite handed coordinate systems and matrix order

_________________
Coding a 3D game engine with fasm is like trying to eat an elephant,
you just have to keep focused and take it one 'byte' at a time.
Post 08 Dec 2020, 12:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.