flat assembler
Message board for the users of flat assembler.

Index > Windows > Directx 11 programming problem.

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 11 Jan 2021, 15:50
I tried to convert an online tutorial about displaying 3 vertices(directx 11), written in C++ to FASM. But resulting FASM executable not displaying the vertices(triangle) where as C++ one working well.(all files attached -.exe file is not a virus). Please someone kind enough to help? Sad
c++,
Code:

//Include and link appropriate libraries and headers//
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "C:\\Program Files (x86)\\Microsoft DirectX SDK (June 2010)\\Lib\\x86\\d3dx11.lib")
//#pragma comment(lib, "C:\\Program Files (x86)\\Microsoft DirectX SDK (June 2010)\\Lib\\x86\\d3dx10.lib")

#include <windows.h>
#include <d3d11.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\d3dx11.h>
//#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\D3DX10.h>
#include <C:\Program Files (x86)\Microsoft DirectX SDK (June 2010)\Include\xnamath.h>

//Global Declarations - Interfaces//
IDXGISwapChain* SwapChain;
ID3D11Device* d3d11Device;
ID3D11DeviceContext* d3d11DevCon;
ID3D11RenderTargetView* renderTargetView;

///////////////**************new**************////////////////////
ID3D11Buffer* triangleVertBuffer;
ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3D10Blob* VS_Buffer;
ID3D10Blob* PS_Buffer;
ID3D11InputLayout* vertLayout;
///////////////**************new**************////////////////////

//Global Declarations - Others//
LPCTSTR WndClassName = "firstwindow";
HWND hwnd = NULL;
HRESULT hr;

const int Width  = 300;
const int Height = 300;

//Function Prototypes//
bool InitializeDirect3d11App(HINSTANCE hInstance);
void CleanUp();
bool InitScene();
void UpdateScene();
void DrawScene();

bool InitializeWindow(HINSTANCE hInstance,
    int ShowWnd,
    int width, int height,
    bool windowed);
int messageloop();

LRESULT CALLBACK WndProc(HWND hWnd,
    UINT msg,
    WPARAM wParam,
    LPARAM lParam);

///////////////**************new**************////////////////////
//Vertex Structure and Vertex Layout (Input Layout)//
struct Vert  //Overloaded Vertex Structure
{
   
    Vert(float x, float y, float z)
        : pos(x,y,z){}

    XMFLOAT3 pos;
};

D3D11_INPUT_ELEMENT_DESC layout[] =
{
    { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },  
};
UINT numElements = ARRAYSIZE(layout);
///////////////**************new**************////////////////////

int WINAPI WinMain(HINSTANCE hInstance,    //Main windows function
    HINSTANCE hPrevInstance, 
    LPSTR lpCmdLine,
    int nShowCmd)
{

    if(!InitializeWindow(hInstance, nShowCmd, Width, Height, true))
    {
        MessageBox(0, "Window Initialization - Failed",
            "Error", MB_OK);
        return 0;
    }

    if(!InitializeDirect3d11App(hInstance))    //Initialize Direct3D
    {
        MessageBox(0, "Direct3D Initialization - Failed",
            "Error", MB_OK);
        return 0;
    }

    if(!InitScene())    //Initialize our scene
    {
        MessageBox(0, "Scene Initialization - Failed",
            "Error", MB_OK);
        return 0;
    }

    messageloop();

    CleanUp();    

    return 0;
}

bool InitializeWindow(HINSTANCE hInstance,
    int ShowWnd,
    int width, int height,
    bool windowed)
{
    typedef struct _WNDCLASS {
        UINT cbSize;
        UINT style;
        WNDPROC lpfnWndProc;
        int cbClsExtra;
        int cbWndExtra;
        HANDLE hInstance;
        HICON hIcon;
        HCURSOR hCursor;
        HBRUSH hbrBackground;
        LPCTSTR lpszMenuName;
        LPCTSTR lpszClassName;
    } WNDCLASS;

    WNDCLASSEX wc;

    wc.cbSize = sizeof(WNDCLASSEX);
    wc.style = CS_HREDRAW | CS_VREDRAW;
    wc.lpfnWndProc = WndProc;
    wc.cbClsExtra = NULL;
    wc.cbWndExtra = NULL;
    wc.hInstance = hInstance;
    wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    wc.hCursor = LoadCursor(NULL, IDC_ARROW);
    wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 2);
    wc.lpszMenuName = NULL;
    wc.lpszClassName = WndClassName;
    wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);

    if (!RegisterClassEx(&wc))
    {
        MessageBox(NULL, "Error registering class",    
            "Error", MB_OK | MB_ICONERROR);
        return 1;
    }

    hwnd = CreateWindowEx(
        NULL,
        WndClassName,
        "Lesson 4 - Begin Drawing",
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, CW_USEDEFAULT,
        width, height,
        NULL,
        NULL,
        hInstance,
        NULL
        );

    if (!hwnd)
    {
        MessageBox(NULL, "Error creating window",
            "Error", MB_OK | MB_ICONERROR);
        return 1;
    }

    ShowWindow(hwnd, ShowWnd);
    UpdateWindow(hwnd);

    return true;
}

bool InitializeDirect3d11App(HINSTANCE hInstance)
{
    //Describe our Buffer
    DXGI_MODE_DESC bufferDesc;

    ZeroMemory(&bufferDesc, sizeof(DXGI_MODE_DESC));

    bufferDesc.Width = Width;
    bufferDesc.Height = Height;
    bufferDesc.RefreshRate.Numerator = 60;
    bufferDesc.RefreshRate.Denominator = 1;
    bufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
    bufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
    bufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

    //Describe our SwapChain
    DXGI_SWAP_CHAIN_DESC swapChainDesc; 

    ZeroMemory(&swapChainDesc, sizeof(DXGI_SWAP_CHAIN_DESC));

    swapChainDesc.BufferDesc = bufferDesc;
    swapChainDesc.SampleDesc.Count = 1;
    swapChainDesc.SampleDesc.Quality = 0;
    swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
    swapChainDesc.BufferCount = 1;
    swapChainDesc.OutputWindow = hwnd; 
    swapChainDesc.Windowed = TRUE; 
    swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;


    //Create our SwapChain
    hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, NULL, NULL, NULL,
        D3D11_SDK_VERSION, &swapChainDesc, &SwapChain, &d3d11Device, NULL, &d3d11DevCon);

    //Create our BackBuffer
    ID3D11Texture2D* BackBuffer;
    hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );

    //Create our Render Target
    hr = d3d11Device->CreateRenderTargetView( BackBuffer, NULL, &renderTargetView );
    BackBuffer->Release();

    //Set our Render Target
    d3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, NULL );

    return true;
}

void CleanUp()
{
    //Release the COM Objects we created
    SwapChain->Release();
    d3d11Device->Release();
    d3d11DevCon->Release();
    renderTargetView->Release();
///////////////**************new**************////////////////////
    triangleVertBuffer->Release();
    VS->Release();
    PS->Release();
    VS_Buffer->Release();
    PS_Buffer->Release();
    vertLayout->Release();
///////////////**************new**************////////////////////
}

///////////////**************new**************////////////////////
bool InitScene()
{
    //Compile Shaders from shader file
    hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "VS", "vs_4_0", 0, 0, 0, &VS_Buffer, 0, 0);
    hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_4_0", 0, 0, 0, &PS_Buffer, 0, 0);

    //Create the Shader Objects
    hr = d3d11Device->CreateVertexShader(VS_Buffer->GetBufferPointer(), VS_Buffer->GetBufferSize(), NULL, &VS);
    hr = d3d11Device->CreatePixelShader(PS_Buffer->GetBufferPointer(), PS_Buffer->GetBufferSize(), NULL, &PS);

    //Set Vertex and Pixel Shaders
    d3d11DevCon->VSSetShader(VS, 0, 0);
    d3d11DevCon->PSSetShader(PS, 0, 0);

    //Create the vertex buffer
    Vert v[] =
    {
        Vert( 0.0f, 0.5f, 0.5f ),
        Vert( 0.5f, -0.5f, 0.5f ),
        Vert( -0.5f, -0.5f, 0.5f ),
    };

    D3D11_BUFFER_DESC vertexBufferDesc;
    ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );

    vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
    vertexBufferDesc.ByteWidth = sizeof( Vert ) * 3;
    vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vertexBufferDesc.CPUAccessFlags = 0;
    vertexBufferDesc.MiscFlags = 0;

    D3D11_SUBRESOURCE_DATA vertexBufferData; 

    ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
    vertexBufferData.pSysMem = v;
    hr = d3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &triangleVertBuffer);

    //Set the vertex buffer
    UINT stride = sizeof( Vert );
    UINT offset = 0;
    d3d11DevCon->IASetVertexBuffers( 0, 1, &triangleVertBuffer, &stride, &offset );

    //Create the Input Layout
    d3d11Device->CreateInputLayout( layout, numElements, VS_Buffer->GetBufferPointer(), 
        VS_Buffer->GetBufferSize(), &vertLayout );

    //Set the Input Layout
    d3d11DevCon->IASetInputLayout( vertLayout );

    //Set Primitive Topology
    d3d11DevCon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );

    //Create the Viewport
    D3D11_VIEWPORT viewport;
    ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));

    viewport.TopLeftX = 0;
    viewport.TopLeftY = 0;
    viewport.Width = Width;
    viewport.Height = Height;

    //Set the Viewport
    d3d11DevCon->RSSetViewports(1, &viewport);

    return true;
}
///////////////**************new**************////////////////////

void UpdateScene()
{

}

///////////////**************new**************////////////////////
void DrawScene()
{
    //Clear our backbuffer
    float bgColor[4] = {(0.0f, 0.0f, 0.0f, 0.0f)};
    d3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);

    //Draw the triangle
    d3d11DevCon->Draw( 3, 0 );

    //Present the backbuffer to the screen
    SwapChain->Present(0, 0);
}
///////////////**************new**************////////////////////

int messageloop(){
    MSG msg;
    ZeroMemory(&msg, sizeof(MSG));
    while(true)
    {
        BOOL PeekMessageL( 
            LPMSG lpMsg,
            HWND hWnd,
            UINT wMsgFilterMin,
            UINT wMsgFilterMax,
            UINT wRemoveMsg
            );

        if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
        {
            if (msg.message == WM_QUIT)
                break;
            TranslateMessage(&msg);    
            DispatchMessage(&msg);
        }
        else{
            // run game code            
            UpdateScene();
            DrawScene();
        }
    }
    return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd,
    UINT msg,
    WPARAM wParam,
    LPARAM lParam)
{
    switch( msg )
    {
    case WM_KEYDOWN:
        if( wParam == VK_ESCAPE ){
            DestroyWindow(hwnd);
        }
        return 0;

    case WM_DESTROY:
        PostQuitMessage(0);
        return 0;
    }
    return DefWindowProc(hwnd,
        msg,
        wParam,
        lParam);
}
    


FASM,
Code:

 format PE GUI 4.0
 entry start


 include 'WIN32AX.inc'
 include 'DxIncld/d3d11.inc'
 include 'win32errNmbrRet.inc'

 SCREEN_WIDTH        equ  300;1920
 SCREEN_HEIGHT       equ  300;



section '.code' code readable executable



  start:
      invoke            GetModuleHandle,0
      mov               [hInst],eax
      invoke            GetCommandLine
      mov               [cmdLine],eax
      stdcall           InitializeWindow,[hInst],[cmdLine]

      stdcall           InitializeDirect3d11App
      stdcall           InitScene
      stdcall           messegeLoop
      stdcall           CleanUp

      invoke          ExitProcess,eax


;------------------------------------------------------------------
    proc       InitializeWindow       hInstance:DWORD,commandLine:DWORD

    ;----declare window struct----------------------------
                push            [hInstance]
                pop             [wc.hInstance]
                mov             [wc.cbSize], sizeof.WNDCLASSEX
                mov             [wc.style], CS_HREDRAW or CS_VREDRAW
                mov             [wc.lpfnWndProc],WindowProc
                xor             eax,eax
                mov             [wc.cbClsExtra],eax
                mov             [wc.cbWndExtra],eax
                mov             [wc.hbrBackground],COLOR_WINDOW + 2
                mov             [wc.lpszMenuName], eax
                mov             [wc.lpszClassName],ClassName
                invoke          LoadIcon, NULL, IDI_APPLICATION
                mov             [wc.hIcon], eax
                mov             [wc.hIconSm], eax
                invoke          LoadCursor, NULL, IDC_ARROW
                mov             [wc.hCursor], eax

    ;----Registering window class----------
                invoke          RegisterClassEx, wc
                or              eax,eax
                jz              err1


                invoke          CreateWindowEx,0,ClassName,AppName,WS_VISIBLE+WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,SCREEN_WIDTH,SCREEN_HEIGHT,0,0,[wc.hInstance],0
                or              eax,eax
                jz              err2
                mov             [hwnd],eax

                ;-----Update window---------------------
                invoke          UpdateWindow, [hwnd]
                jmp             end_WinMain


                ;----errors------------------------------------------------------------------------
        err1:
                invoke          MessageBox, 0,ErrTxt1,ErrMsgBoxCaption, MB_OK
                jmp             end_WinMain
        err2:
                invoke          MessageBox, 0,ErrTxt2,ErrMsgBoxCaption, MB_OK
                jmp             end_WinMain

    ;----------------------------------------------------------------------------------

        end_WinMain:
                ret
    endp

;----------------------------------------------------------------------------------------------------------
;------------------------------------InitializeDirect3d11App procedure------------------------------------------------------
  proc       InitializeDirect3d11App
                push            ebx esi edi

                mov             ecx,sizeof.DXGI_SWAP_CHAIN_DESC
                mov             eax,swapChainDesc
                stdcall         ClearStructr,eax,ecx

                mov             [swapChainDesc.SampleDesc.Quality], 0
                mov             [swapChainDesc.SampleDesc.Count],1
                mov             [swapChainDesc.BufferUsage],DXGI_USAGE_RENDER_TARGET_OUTPUT    ;    how swap chain is to be used
                mov             [swapChainDesc.BufferCount],1                                  ;    one back buffer
                mov             eax,[hwnd]
                mov             [swapChainDesc.OutputWindow],eax                               ;  the window to be used
                mov             [swapChainDesc.Windowed],TRUE                                 ;  windowed/full-screen mode
                mov             [swapChainDesc.SwapEffect],DXGI_SWAP_EFFECT_DISCARD

                mov             [swapChainDesc.BufferDesc.Format],DXGI_FORMAT_R8G8B8A8_UNORM   ;    use 32-bit color
                mov             [swapChainDesc.BufferDesc.Width], SCREEN_WIDTH
                mov             [swapChainDesc.BufferDesc.Height], SCREEN_HEIGHT
                mov             [swapChainDesc.BufferDesc.RefreshRate.Numerator],60
                mov             [swapChainDesc.BufferDesc.RefreshRate.Denominator],1
                mov             [swapChainDesc.BufferDesc.ScanlineOrdering],DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
                mov             [swapChainDesc.BufferDesc.Scaling],DXGI_MODE_SCALING_UNSPECIFIED;

                mov             [swapChainDesc.Flags],DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH


                invoke          D3D11CreateDeviceAndSwapChain,NULL,D3D_DRIVER_TYPE_HARDWARE,NULL,NULL,NULL,NULL,D3D11_SDK_VERSION,addr swapChainDesc,addr SwapChain,addr d3d11Device,NULL,addr d3d11DevCon
                or              eax,eax
                jz              InitD3D_errorChk2

                mov             eax,DxErrStr1
                jmp             InitD3D_error

        InitD3D_errorChk2:
                cmp             [SwapChain],NULL
                jne             InitD3D_errorChk3

                mov             eax,DxErrStr2
                jmp             InitD3D_error

        InitD3D_errorChk3:
                cmp             [d3d11Device],NULL
                jne             InitD3D_errorChk4
                mov             eax,DxErrStr3
                jmp             InitD3D_error

        InitD3D_errorChk4:
                cmp             [d3d11DevCon],NULL
                jne             ctInitD3D
                mov             eax,DxErrStr4
                jmp             InitD3D_error


        ctInitD3D:
                cominvk         SwapChain,GetBuffer,0, IID_ID3D11Texture2D,BackBuffer
                or              eax,eax
                jnz             BackBuffObjErr

                cominvk         d3d11Device,CreateRenderTargetView,[BackBuffer], NULL,renderTargetView
                or              eax,eax
                jnz             rndrtrgtVwObjErr

                ;pusha
                ;call        HxDcValtostr
                ;popa

                cominvk         d3d11DevCon, OMSetRenderTargets,1,renderTargetView, NULL

                cominvk         BackBuffer,Release


                jmp             end_InitD3D

    ;----errors------------------------------------------------------------------------
        BackBuffObjErr:
                mov             eax,DxErrStr5
                jmp             InitD3D_error

        rndrtrgtVwObjErr:
                mov             eax,DxErrStr6
                jmp             InitD3D_error

        InitD3D_error:
                invoke          MessageBox, 0,eax,ErrMsgBoxCaption, MB_OK
                invoke          PostQuitMessage, 0
    ;----------------------------------------------------------------------------------
        end_InitD3D:
                pop             ebx esi edi

                ret
 endp
;----------------------------------------------------------------------------------------------------------
;----------------------------CleanUp--------------close and release all existing COM objects--------------

    proc     CleanUp
                push            ebx esi edi                          ;
                ;cominvk         swapchain,SetFullscreenState,FALSE, NULL

                cominvk         SwapChain,Release
                ;mov             [swapchain], 0
                cominvk         d3d11Device, Release
                ;mov             [dev], 0
                cominvk         d3d11DevCon,Release

                cominvk         renderTargetView,Release
                ;mov             [devCntxt], 0
                cominvk         triangleVertBuffer,Release
                cominvk         VS,Release
                cominvk         PS,Release
                cominvk         VS_Buffer,Release
                cominvk         PS_Buffer,Release
                cominvk         vertLayout,Release

        end_CleanD3D:
                pop             ebx esi edi

                ret
endp
;----------------------------------------------------------------------------------------------------------

;------------------------------------InitScene procedure------------------------------------------------------
    proc       InitScene
                push            ebx esi edi

    ;----------------------Load and compile the two shaders from the .shader file and save compiled shaders in blob objects
                invoke          D3DX11CompileFromFile,Effects, 0, 0, VSdr, vs_4_0, 0, 0, 0, VS_Buffer, 0, 0;
                invoke          D3DX11CompileFromFile,Effects, 0, 0, PSdr, ps_4_0, 0, 0, 0, PS_Buffer, 0, 0;
                ;pusha
                ;call        HxDcValtostr
                ;popa
     ;---------------encapsulate compiled shaders to com objects-----------------------------------------------------------
                cominvk         VS_Buffer,GetBufferPointer
                mov             ecx,eax
                push            ecx
                cominvk         VS_Buffer,GetBufferSize
                pop             ecx
                cominvk         d3d11Device,CreateVertexShader,ecx,eax,NULL, VS   ;/**


                cominvk         PS_Buffer,GetBufferPointer
                mov             ecx,eax
                push            ecx
                cominvk         PS_Buffer,GetBufferSize
                pop             ecx
                cominvk         d3d11Device,CreatePixelShader,ecx,eax,NULL, PS   ;/**

    ;----------------------Set both shaders to be the active-------------------------------------
                cominvk         d3d11DevCon,VSSetShader, VS,0,0

                cominvk         d3d11DevCon,PSSetShader, PS,0,0


                cominvk         VS_Buffer,GetBufferPointer
                mov             ecx,eax
                push            ecx
                cominvk         VS_Buffer,GetBufferSize
                pop             ecx
                cominvk         d3d11Device,CreateInputLayout, layout,1, ecx,eax, vertLayout;
                ;pusha
                ;call        HxDcValtostr
                ;popa

                cominvk         d3d11DevCon,IASetInputLayout,[vertLayout];


    ;--------------------------------------------------------------------------------------------
                mov             ecx,sizeof.D3D11_BUFFER_DESC
                mov             eax,vertexBufferDesc
                stdcall         ClearStructr,eax,ecx

                mov             [vertexBufferDesc.Usage],D3D11_USAGE_DEFAULT;
                mov             [vertexBufferDesc.ByteWidth],sizeof.Vertex * 3;
                mov             [vertexBufferDesc.BindFlags],D3D11_BIND_VERTEX_BUFFER;
                mov             [vertexBufferDesc.CPUAccessFlags],0;
                mov             [vertexBufferDesc.MiscFlags],0;


                mov             ecx,sizeof.D3D11_SUBRESOURCE_DATA
                mov             eax,vertexBufferData
                ;stdcall         ClearStructr,eax,ecx
                ;mov             edi,v
                mov             [vertexBufferData.pSysMem],v;


                cominvk         d3d11Device,CreateBuffer, vertexBufferDesc, vertexBufferData, triangleVertBuffer;

                mov             [stride],sizeof.Vertex;
                mov             [offset],0;
                cominvk         d3d11DevCon,IASetVertexBuffers, 0, 1, triangleVertBuffer,addr stride,addr offset;
      ;--------------------------------------------------------------------------------------------

                cominvk         d3d11DevCon,IASetPrimitiveTopology, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
      ;--------------------------------------------------------------------------------------------

                mov             ecx,sizeof.D3D11_VIEWPORT
                mov             eax,viewport
                stdcall         ClearStructr,eax,ecx

                mov             [viewport.TopLeftX],0;
                mov             [viewport.TopLeftY],0;
                mov             [viewport.Width],800;
                mov             [viewport.Height],600;

                cominvk         d3d11DevCon,RSSetViewports,1, viewport;

                xor             eax,eax
                pop             edi esi ebx

                ret
    endp
;----------------------------------------------------------------------------------------------------------

;///////////////**************new**************////////////////////

 proc      UpdateScene
;{
;
    ret
 endp

;///////////////**************new**************////////////////////

;------------------------------------DrawScene procedure------------------------------------------------------
    proc       DrawScene
                push            ebx esi edi

                cominvk         d3d11DevCon,ClearRenderTargetView,[renderTargetView],  bgColor;
                cominvk         d3d11DevCon,Draw,3, 0;
                cominvk         SwapChain,Present,0, 0;

                pop             edi esi ebx

                ret
    endp
;----------------------------------------------------------------------------------------------------------

;----------------------------------------------------------------------------------------------------------
    proc       messegeLoop
                mov             ecx,sizeof.MSG
                mov             eax,msg
                stdcall         ClearStructr,eax,ecx


        msg_loop:
                invoke          PeekMessage,msg,NULL,0, 0, PM_REMOVE
                or              eax,eax
                jz              dxProgrmng      ;no masseges

                cmp             [msg.message],WM_QUIT            ;if messages present
                je              end_loop

                invoke          TranslateMessage,msg
                invoke          DispatchMessage,msg



                jmp             msg_loop


        dxProgrmng:

    ;--game code---------------------------------------
                stdcall         UpdateScene
                stdcall         DrawScene;
                jmp             msg_loop


    ;---------------------------------------------------
        end_loop:
                mov             eax,[msg.wParam]
                ret
    endp

;----------------------------------------------------------------------------------------------------------

;------------------------------------window procedure------------------------------------------------------
    proc       WindowProc hwnd,umsg:DWORD,wParam:DWORD,lparam:DWORD

                push            ebx esi edi
                cmp             [umsg],WM_DESTROY
                je              wmdestroy
                cmp             [umsg],WM_CLOSE
                je              close
                cmp             [umsg],WM_KEYDOWN
                je              checkKeys

        defwndproc:
                invoke          DefWindowProc,[hwnd],[umsg],[wParam],[lparam]
                jmp             end_WindowProc


        checkKeys:
                cmp             [wParam],VK_ESCAPE
                je              close

                xor             eax,eax
                jmp             end_WindowProc

        close:
                invoke          DestroyWindow,[hwnd]

        wmdestroy:
                invoke          PostQuitMessage,0
                xor             eax,eax

        end_WindowProc:
                pop             edi esi ebx
                ret
    endp
;----------------------------------------------------------------------------------------------------------

;------------------------------------ClearStructr-----------------------------------------------------------
    proc       ClearStructr strucName,strucSize

                pusha
                mov             edi,[strucName]
                mov             ecx,[strucSize]
                mov             al,0
                cld
                rep             stosb

                popa
                ret
    endp
;----------------------------------------------------------------------------------------------------------

 section '.data' data readable writeable
;========================================================================================================

;//Global Declarations - Others//
 ClassName           db 'MNSwndClass',0
 AppName             db 'Direct3d11 sample',0
 position            db "POSITION",0
 ErrTxt1             db 'Registering window class Failed',0
 ErrTxt2             db 'Fail to create a window using MNSwndClass',0
 ErrMsgBoxCaption    db 'Program Error ',0

 DxErrStr1           db 'Error in the D3D11CreateDeviceAndSwapChain',0
 DxErrStr2           db 'Error in creating swapchain object',0
 DxErrStr3           db 'Error in creating device object',0
 DxErrStr4           db 'Error in creating device context object',0
 DxErrStr5           db 'Error in creating swapchain backbuffer object',0
 DxErrStr6           db 'Error in creating render-target view object',0
 Effects             db 'Effects.fx',0
 VSdr                db 'VS',0
 PSdr                db 'PS',0
 vs_4_0              db 'vs_4_0',0
 ps_4_0              db 'ps_4_0',0
;========================================================================================================


 section '.bss' readable writeable
 ;=======================================================================================================
             ;//Global Declarations - Interfaces//

 layout    D3D11_INPUT_ELEMENT_DESC     position, 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0


 struct    Vertex
                 dd       ?,?,?

       ;color     D3DXCOLOR
ends


 hwnd                dd ?
 hr                  dd ?
 hInst               dd ?
 cmdLine             dd ?

 msg                 MSG
 wc                  WNDCLASSEX
 vertexBufferDesc    D3D11_BUFFER_DESC ;
 swapChainDesc       DXGI_SWAP_CHAIN_DESC
 vertexBufferData    D3D11_SUBRESOURCE_DATA ;
 viewport            D3D11_VIEWPORT ;



 SwapChain             IDXGISwapChain
 d3d11Device           ID3D11Device
 d3d11DevCon           ID3D11DeviceContext
 renderTargetView      ID3D11RenderTargetView

 triangleVertBuffer     ID3D11Buffer
 VS                     ID3D11VertexShader
 PS                     ID3D11PixelShader
 VS_Buffer              ID3D10Blob
 PS_Buffer              ID3D10Blob
 vertLayout             ID3D11InputLayout
 BackBuffer             ID3D11Texture2D


  stride              dd ?
 offset              dd ?

 bgColor             dd 0.0,0.0, 0.0, 0.0


v      Vertex  < 0.0, 0.5, 0.5 >
        Vertex < 0.5, -0.5, 0.5 >
        Vertex < -0.5, -0.5, 0.5 >


;=======================================================================================================



 section '.idata' import data readable
;=======================================================================================================
         library         kernel32,'KERNEL32.DLL',\
                         user32,'USER32.DLL',\
                         d3d11,'D3D11.dll',\
                         d3dx11,'d3dx11_43.dll';,\
                         ;d3dx10,'D3DX10_43.DLL'
                         ;msvcrt, 'msvcrt.dll'

         ;include 'api/msvcrt.inc'
         ;include 'api/COMDLG32.inc'
         include 'api/kernel32.inc'
         include 'api/USER32.inc'
         include 'DxIncld/Api/d3d11Api.inc'
         include 'DxIncld/Api/D3DX11Api.inc'
         ;include 'DxIncld/Api/D3DX10Api.inc'
;=======================================================================================================

    


Description:
Download
Filename: direct3d_4d.zip
Filesize: 40.96 KB
Downloaded: 711 Time(s)

Post 11 Jan 2021, 15:50
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 11 Jan 2021, 16:34
Interesting style to separate procs using ;===
Cool.
Post 11 Jan 2021, 16:34
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 11 Jan 2021, 17:13
Thanks Roman. I think I've got it from someone.(may be from this board or some where in the internet).
Post 11 Jan 2021, 17:13
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 11 Jan 2021, 17:14
Why in section '.bss' readable writeable you write vertex ?
Vertex < 0.0, 0.5, 0.5 >
Vertex < 0.5, -0.5, 0.5 >
Vertex < -0.5, -0.5, 0.5 >


All values in section '.bss' readable writeable empty.
And this increase exe size !
In section '.bss' readable writeable must write:
Some rd 1000
AllTextures rd 2000 ;4 bytes for one texture.

This needed write in section '.data' data readable writeable
layout D3D11_INPUT_ELEMENT_DESC position, 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0
Vertex < 0.0, 0.5, 0.5 >
Vertex < 0.5, -0.5, 0.5 >
Vertex < -0.5, -0.5, 0.5 >
Post 11 Jan 2021, 17:14
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 11 Jan 2021, 17:41
I tried but there is a strange error in resulting exe, where it doesn't even show the colour(specified by "bgColor dd 0.0,0.0, 0.0, 0.0 " in the code) and the window closes within few seconds.
Post 11 Jan 2021, 17:41
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 11 Jan 2021, 18:09
Yes.
You need in render write
Code:
cominvk         d3d11DevCon,IASetInputLayout,[vertLayout];
cominvk         d3d11DevCon,ClearRenderTargetView,[renderTargetView],  bgColor;
cominvk         d3d11DevCon,OMSetRenderTargets, 1, renderTargetView, NULL
cominvk         d3d11DevCon,IASetPrimitiveTopology, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST
cominvk         d3d11DevCon,VSSetShader, [VS],0,0
cominvk         d3d11DevCon,PSSetShader, [PS],0,0
cominvk         d3d11DevCon,IASetVertexBuffers, 0, 1, triangleVertBuffer,stride,offset
cominvk         d3d11DevCon,Draw,3, 0
cominvk         SwapChain,Present,1,0
    
Post 11 Jan 2021, 18:09
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 11 Jan 2021, 18:13
Whear is shader from c++ tutorial ?
I want look.
Post 11 Jan 2021, 18:13
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 11 Jan 2021, 18:20
Thank you Roman for the response. the shader file is "Effects.fx" which is in inside of the zip file I have attached above.
Post 11 Jan 2021, 18:20
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 11 Jan 2021, 18:25
Post 11 Jan 2021, 18:25
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 11 Jan 2021, 18:43
How?? can you attach your asm files?
Post 11 Jan 2021, 18:43
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20343
Location: In your JS exploiting you and your system
revolution 11 Jan 2021, 20:00
Roman wrote:
All values in section '.bss' readable writeable empty.
That isn't correct. You can add sections with any arbitrary name, and populate them with any arbitrary data. It will all work fine.
Post 11 Jan 2021, 20:00
View user's profile Send private message Visit poster's website Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 11 Jan 2021, 20:58
Thanks revolution. Hope you can help me to solve my original problem. Confused
(Although Roman claims he managed to solve it he haven't said how he did it.)
Post 11 Jan 2021, 20:58
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 12 Jan 2021, 04:12
Ye.
Revolution please help us Smile


Last edited by Roman on 12 Jan 2021, 05:01; edited 1 time in total
Post 12 Jan 2021, 04:12
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 12 Jan 2021, 04:17
Roman
Quote:

Ye.
Revolution please help us.

????
Roman you said you have done it?
Confused
Post 12 Jan 2021, 04:17
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 12 Jan 2021, 04:22
Did you looked my video ?
Post 12 Jan 2021, 04:22
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 12 Jan 2021, 04:25
yes several times.
Post 12 Jan 2021, 04:25
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 12 Jan 2021, 04:35
I gave you all hints.
Take a good look and you get you want.

PS: Your example is very simple 3D level Directx 11 ! If you want render shadows and animation , you should be more attentive and persistent.
https://www.youtube.com/watch?v=UOSKDi05AcQ&ab_channel=Roman8139
Post 12 Jan 2021, 04:35
View user's profile Send private message Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 12 Jan 2021, 05:01
OK Thank you very much Roman for your help.
(I have changed the things in the viewport as your video, but no luck.)
may be I am not smart as you. But I will try again to solve the riddle you made(video), to find the solution. Mad

Anyway, Thank you again. Smile
Post 12 Jan 2021, 05:01
View user's profile Send private message Send e-mail Reply with quote
mns



Joined: 20 Dec 2007
Posts: 150
Location: Piliyandala,Sri lanka
mns 12 Jan 2021, 05:28
Roman, with your help(video) found the problem.
it's the
SCREEN_WIDTH equ 300;
SCREEN_HEIGHT equ 300;
it should equal to viewport width and height,
so it should be
SCREEN_WIDTH equ 800;
SCREEN_HEIGHT equ 600;

also,
according to your post I changed this,
cominvk d3d11DevCon,VSSetShader, VS,0,0
cominvk d3d11DevCon,PSSetShader, PS,0,0
to
cominvk d3d11DevCon,VSSetShader, [VS],0,0
cominvk d3d11DevCon,PSSetShader, [PS],0,0

Thank you very much Very Happy

(And there were unrelated problems in the code(that I could find). So in case someone needs, I'm attaching the corrected source.)


Description:
Download
Filename: direct3d_4d.ASM
Filesize: 20.41 KB
Downloaded: 441 Time(s)

Post 12 Jan 2021, 05:28
View user's profile Send private message Send e-mail Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1796
Roman 12 Jan 2021, 05:50
Read msdn.
https://docs.microsoft.com/en-us/windows/win32/api/d3d11/ns-d3d11-d3d11_viewport

And remember.
Windows size as Integer.
Viewport as float !
Post 12 Jan 2021, 05:50
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.