Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Directx 网格图案精灵表有问题_Directx_Directx 11 - Fatal编程技术网

Directx 网格图案精灵表有问题

Directx 网格图案精灵表有问题,directx,directx-11,Directx,Directx 11,在DirectX 11中显示简单的网格模式时遇到一些问题。所有内容都正确加载,没有任何错误或返回,但实际上没有显示任何内容 在DrawGridSquare函数中放置一个断点可以显示SpritePtr变量中的所有设置都是正确的,但是我仍然没有在屏幕上显示任何内容 因此,我相当确定我的问题在于我在下面提供的Render()或LoadContent()函数 以下是相关来源: /*** * Load simple shaders and other necessary components ***/

在DirectX 11中显示简单的网格模式时遇到一些问题。所有内容都正确加载,没有任何错误或返回,但实际上没有显示任何内容

在DrawGridSquare函数中放置一个断点可以显示SpritePtr变量中的所有设置都是正确的,但是我仍然没有在屏幕上显示任何内容

因此,我相当确定我的问题在于我在下面提供的Render()或LoadContent()函数

以下是相关来源:

/***
  * Load simple shaders and other necessary components
***/
bool AStarDemo::LoadContent(){
    ID3DBlob* vsBuffer = 0;
    bool compileResult = CompileD3DShader("TextureMap.hlsl", "VS_Main", "vs_4_0", &vsBuffer);

    if(compileResult == false){
        DXTRACE_MSG("Error compiling vertex shader");
        return false;
    }

    HRESULT d3dResult;

    d3dResult = d3dDevice->CreateVertexShader(vsBuffer->GetBufferPointer(),
        vsBuffer->GetBufferSize(), 0, &returnColorVS);

    if(FAILED(d3dResult)){
        if(vsBuffer){
            vsBuffer->Release();
        }

        return false;
    }

    D3D11_INPUT_ELEMENT_DESC solidColorLayout[] ={
        { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
        { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }
    };

    unsigned int totalLayoutElements = ARRAYSIZE(solidColorLayout);

    d3dResult = d3dDevice->CreateInputLayout(solidColorLayout, totalLayoutElements,
        vsBuffer->GetBufferPointer(), vsBuffer->GetBufferSize(), &inputLayout);

    vsBuffer->Release();

    if(FAILED(d3dResult)){
        return false;
    }

    ID3DBlob* psBuffer = 0;
    compileResult = CompileD3DShader("TextureMap.hlsl", "PS_Main", "ps_4_0", &psBuffer);

    if(compileResult == false){
        DXTRACE_MSG("Error loading pixel shader!");
        return false;
    }

    d3dResult = d3dDevice->CreatePixelShader(psBuffer->GetBufferPointer(),
        psBuffer->GetBufferSize(), 0, &returnColorPS);

    psBuffer->Release();

    if(FAILED(d3dResult)){
        DXTRACE_MSG( "Error creating pixel shader!" );
        return false;
    }

    //*** LOAD DDS FILE ***//
    d3dResult = D3DX11CreateShaderResourceViewFromFile(d3dDevice, "tiles.dds", 0, 0, &colorMap, 0);

    if(FAILED(d3dResult)){
        DXTRACE_MSG( "Error loading textures!" );
        return false;
    }

    D3D11_SAMPLER_DESC colorMapDesc;
    ZeroMemory(&colorMapDesc, sizeof(colorMapDesc));
    colorMapDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
    colorMapDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
    colorMapDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
    colorMapDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
    colorMapDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
    colorMapDesc.MaxLOD = D3D11_FLOAT32_MAX;

    d3dResult = d3dDevice->CreateSamplerState(&colorMapDesc, &colorMapSampler);
    if(FAILED(d3dResult)){
        DXTRACE_MSG( "Failed to create color map sampler state!" );
        return false;
    }

    ID3D11Resource* colorTex;
    colorMap->GetResource(&colorTex);

    D3D11_TEXTURE2D_DESC colorTexDesc;
    ((ID3D11Texture2D*)colorTex)->GetDesc(&colorTexDesc);
    colorTex->Release();

    float halfWidth = (float)colorTexDesc.Width / 2.0f;
    float halfHeight = (float)colorTexDesc.Height / 2.0f;


    vertices = new Vertex[6 * TOTAL_NUMBER_GRID_SQUARES];
    gridSquares = new GridSquare[TOTAL_NUMBER_GRID_SQUARES];
    //for each grid square
    for(int i = 0; i < TOTAL_NUMBER_GRID_SQUARES; i++){

        //create a grid square object
        GridSquare gs;
        gs.type = ((i%2) == 0) ? prey : hunter;

        gs.BottomRight     = Vertex( XMFLOAT3( halfWidth + (halfWidth * (i % GRID_WIDTH)), 
                                            halfHeight + (halfHeight * (i / GRID_WIDTH)), 
                                            Z_LEVEL),
                            //XMFLOAT2(1.0f + gs.position.x, 0.0f + gs.position.y));
                            XMFLOAT2(1.0f, 0.0f));
        gs.BottomCorner    = Vertex( XMFLOAT3(  halfWidth + (halfWidth * (i % GRID_WIDTH)), 
                                            -halfHeight + (halfHeight * (i / GRID_WIDTH)), 
                                            Z_LEVEL),
                            //XMFLOAT2(1.0f + gs.position.x, 1.0f + gs.position.y));
                            XMFLOAT2(1.0f, 1.0f));
        gs.BottomLeft     = Vertex( XMFLOAT3( -halfWidth + (halfWidth * (i % GRID_WIDTH)), 
                                              -halfHeight + (halfHeight * (i / GRID_WIDTH)), 
                                            Z_LEVEL),
                            //XMFLOAT2(0.0f + gs.position.x, 1.0f + gs.position.y));
                            XMFLOAT2(0.0f, 1.0f));
        gs.TopLeft = Vertex( XMFLOAT3( -halfWidth + (halfWidth * (i % GRID_WIDTH)),   
                                            -halfHeight + (halfHeight * (i / GRID_WIDTH)),         
                                            Z_LEVEL),
                            //XMFLOAT2(0.0f + gs.position.x, 1.0f + gs.position.y));
                            XMFLOAT2(0.0f, 1.0f));
        gs.TopCorner  = Vertex( XMFLOAT3( -halfWidth + (halfWidth * (i % GRID_WIDTH)),    
                                            halfHeight + (halfHeight * (i / GRID_WIDTH)), 
                                            Z_LEVEL),
                            //XMFLOAT2(0.0f + gs.position.x, 0.0f + gs.position.y));
                            XMFLOAT2(0.0f, 0.0f));
        gs.TopRight = Vertex( XMFLOAT3(  halfWidth + (halfWidth * (i % GRID_WIDTH)),   
                                            halfHeight + (halfHeight * (i / GRID_WIDTH)), 
                                            Z_LEVEL),
                            //XMFLOAT2(1.0f + gs.position.x, 0.0f + gs.position.y));
                            XMFLOAT2(1.0f, 0.0f));      

        gridSquares[i] = gs;
        vertices[6*i]     = gs.BottomRight;
        vertices[(6*i)+1] = gs.BottomCorner;
        vertices[(6*i)+2] = gs.BottomLeft;
        vertices[(6*i)+3] = gs.TopLeft;
        vertices[(6*i)+4] = gs.TopCorner;
        vertices[(6*i)+5] = gs.TopRight;
    }

    D3D11_BUFFER_DESC vertexDesc;
    ZeroMemory(&vertexDesc, sizeof(vertexDesc));
    vertexDesc.Usage = D3D11_USAGE_DYNAMIC;
    vertexDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
    vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
    vertexDesc.ByteWidth = 6 * sizeof(Vertex) * TOTAL_NUMBER_GRID_SQUARES; //num vertices * size of single vertex

    d3dResult = d3dDevice->CreateBuffer(&vertexDesc, 0, &vertexBuffer);

    if(FAILED(d3dResult)){
        return false;
    }

    return true;
}

void AStarDemo::Render(){
    if(d3dContext == 0)
        return;

    float clearColor[4] = {0.0f, 0.0f, 0.25f, 1.0f};
    d3dContext->ClearRenderTargetView(backBuffTarget, clearColor);

    unsigned int stride = sizeof(Vertex);
    unsigned int offset = 0;

    d3dContext->IASetInputLayout(inputLayout);
    d3dContext->IASetVertexBuffers(0, 1, &vertexBuffer, &stride, &offset);
    d3dContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    //actually set the vertex shader
    d3dContext->VSSetShader(returnColorVS, 0, 0);
    //actually set the pixel shader
    d3dContext->PSSetShader(returnColorPS, 0, 0);

    //set shader resources & sampler
    d3dContext->PSSetShaderResources(0, 1, &colorMap);
    d3dContext->PSSetSamplers(0, 1, &colorMapSampler);

    //update grid squares
    //   A* alg steped in built-in Update()
    for(int i = 0; i < 1/*TOTAL_NUMBER_GRID_SQUARES*/; i+=6){
        //update the squares
        DrawGridSquare(i);
    }

    swapChain->Present(0, 0);
}
/***
*加载简单着色器和其他必要组件
***/
bool AStarDemo::LoadContent(){
ID3DBlob*vsBuffer=0;
bool compileResult=CompileD3DShader(“TextureMap.hlsl”、“VS_Main”、“VS_4_0”和&vsBuffer);
if(compileResult==false){
DXTRACE_MSG(“编译顶点着色器时出错”);
返回false;
}
HRESULT d3dResult;
d3dResult=d3dDevice->CreateVertexShader(vsBuffer->GetBufferPointer(),
vsBuffer->GetBufferSize()、0和returnColorVS);
如果(失败(d3dResult)){
if(vsBuffer){
vsBuffer->Release();
}
返回false;
}
D3D11_输入_元素_描述solidColorLayout[]={
{“位置”,0,DXGI_格式_R32G32B32_浮点,0,0,D3D11_输入_逐顶点_数据,0},
{“TEXCOORD”,0,DXGI_格式_R32G32_浮点,0,12,D3D11_输入_逐顶点_数据,0}
};
unsigned int totalayoutelements=ARRAYSIZE(solidColorLayout);
d3dResult=d3dDevice->CreateInputLayout(solidColorLayout,TotalayOutElements,
vsBuffer->GetBufferPointer(),vsBuffer->GetBufferSize(),&inputLayout);
vsBuffer->Release();
如果(失败(d3dResult)){
返回false;
}
ID3DBlob*psBuffer=0;
compileResult=CompileD3DShader(“TextureMap.hlsl”、“PS_Main”、“PS_4_0”和&psBuffer);
if(compileResult==false){
DXTRACE_MSG(“加载像素着色器时出错!”);
返回false;
}
d3dResult=d3dDevice->CreatePixelShader(psBuffer->GetBufferPointer(),
psBuffer->GetBufferSize(),0和&returnColorPS);
psBuffer->Release();
如果(失败(d3dResult)){
DXTRACE_MSG(“创建像素着色器时出错!”);
返回false;
}
//***加载DDS文件***//
d3dResult=D3DX11CreateShaderResourceViewFromFile(d3dDevice,“tiles.dds”,0,0和colorMap,0);
如果(失败(d3dResult)){
DXTRACE_MSG(“加载纹理时出错!”);
返回false;
}
D3D11_采样器_DESC colorMapDesc;
零内存(&colorMapDesc,sizeof(colorMapDesc));
colorMapDesc.AddressU=D3D11_纹理_地址_包裹;
colorMapDesc.AddressV=D3D11_纹理_地址_包裹;
colorMapDesc.AddressW=D3D11\u纹理\u地址\u包裹;
colorMapDesc.ComparisonFunc=D3D11\u比较\u从不;
colorMapDesc.Filter=D3D11\u Filter\u MIN\u MAG\u MIP\u LINEAR;
colorMapDesc.MaxLOD=D3D11_FLOAT32_MAX;
d3dResult=d3dDevice->CreateSamplerState(&colorMapDesc,&colorMapSampler);
如果(失败(d3dResult)){
DXTRACE_MSG(“未能创建颜色贴图采样器状态!”);
返回false;
}
ID3D11Resource*colorTex;
colorMap->GetResource(&colorTex);
D3D11_纹理2D_描述颜色描述;
((ID3D11Texture2D*)colorTex)->GetDesc(&colorTexDesc);
colorTex->Release();
浮动半宽度=(浮动)colortextdesc.Width/2.0f;
浮动半高=(浮动)colortextdesc.Height/2.0f;
顶点=新顶点[6*总网格数\方格];
gridSquares=新的gridSquares[总网格数\网格平方];
//对于每个网格正方形
对于(int i=0;i