Jump to content
  • Advertisement

Kyle Corver

  • Content Count

  • Joined

  • Last visited

Community Reputation

138 Neutral

About Kyle Corver

  • Rank

Personal Information

  • Role
  • Interests
  1.   Your guess was right. I forgot to put the shader files into the release folder. That's why it always stopped working ...   Yeah I just wondered. I copied nearly all the code exactly out of my tutorial book, so it should have worked. My code wasn't working but the exact program did work. Finally I found the error: I used the wrong format for the colorlayout. I fixed it and now my triangle is showing properly   So all my problems seem to have disappeared. Thanks
  2. Hey guys, got two 'little' Problems with my current Project: The first is: When I start my Project (simple Win32 Application) wihin Visual Studio in Release/Debug Mode it is showing me the normal Window I'd like to have. When I compile the Release Version and start the .exe in the Release Folder, the Window is closing immediately. I just have no Idea why that happens and I have no idea how I can create any output. But I identified the not-working function. It is CompileShader(...) in class Game.   The second thing is, that I'm trying to show a simple primitive like in the book i'm currently reading.Initialisation of DirectX is working proper without any exceptions, but the triangle is simply not showing :(   The Code is seperated in class Game and class MyGame, which inherits from Game and overwrites the Methods of Game. Game: void Game::Initialize(HWND _hwnd) { hwnd = _hwnd; RECT dim; GetClientRect(hwnd, &dim); width = dim.right-dim.left; height = dim.bottom-dim.top; D3D_DRIVER_TYPE driverTypes[] = { D3D_DRIVER_TYPE_HARDWARE, D3D_DRIVER_TYPE_WARP, D3D_DRIVER_TYPE_SOFTWARE }; int numDriverTypes = ARRAYSIZE(driverTypes); D3D_FEATURE_LEVEL featureLevels [] = { D3D_FEATURE_LEVEL_11_0, D3D_FEATURE_LEVEL_10_1, D3D_FEATURE_LEVEL_10_0, D3D_FEATURE_LEVEL_9_3, D3D_FEATURE_LEVEL_9_2, D3D_FEATURE_LEVEL_9_1 }; int numFeatureLevels = ARRAYSIZE(featureLevels); DXGI_SWAP_CHAIN_DESC swapChainDesc; ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); swapChainDesc.BufferCount = 1; swapChainDesc.BufferDesc.Width = width; swapChainDesc.BufferDesc.Height = height; swapChainDesc.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; swapChainDesc.BufferDesc.RefreshRate.Numerator = 60; swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.OutputWindow = hwnd; swapChainDesc.Windowed = true; swapChainDesc.SampleDesc.Count = 1; swapChainDesc.SampleDesc.Quality = 0; HRESULT hr; D3D_FEATURE_LEVEL featureLevel; for(int i=0; i<numDriverTypes; i++) { hr = D3D11CreateDeviceAndSwapChain(0, driverTypes[i], 0, 0, featureLevels, numFeatureLevels, D3D11_SDK_VERSION, &swapChainDesc, &swapchain, &device, &featureLevel, &context); if(SUCCEEDED(hr)) break; } if(FAILED(hr)) throw BasicException(typeid(this).name(), "Could not create device and swapchain", hr); ID3D11Texture2D* backBufferTexture; hr = swapchain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&backBufferTexture); if(FAILED(hr)) throw BasicException(typeid(this).name(), "failed to get swapchain backbuffer", hr); hr = device->CreateRenderTargetView(backBufferTexture, 0, &backBufferTarget); if(backBufferTexture) backBufferTexture->Release(); if(FAILED(hr)) throw BasicException(typeid(this).name(), "failed to create render target view", hr); context->OMSetRenderTargets(1, &backBufferTarget, 0); viewport.Width = static_cast<float>(width); viewport.Height = static_cast<float>(height); viewport.MinDepth = 0.0f; viewport.MaxDepth = 1.0f; viewport.TopLeftX = 0.0f; viewport.TopLeftY = 0.0f; context->RSSetViewports(1, &viewport); } void Game::CompileShader(char* filePath, char* entry, char* shaderModel, ID3DBlob** buffer) { DWORD shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS; ID3DBlob* errorBuffer = 0; HRESULT hr; hr = D3DX11CompileFromFile(filePath, 0, 0, entry, shaderModel, shaderFlags, 0, 0, buffer, &errorBuffer, 0); if(FAILED(hr)) { if(errorBuffer!=0) throw BasicException(typeid(this).name(), (char*)errorBuffer->GetBufferPointer(), hr); throw BasicException(typeid(this).name(), "failed loading shader", hr); } if(errorBuffer!=0) errorBuffer->Release(); } void Game::LoadContent() {} void Game::Draw() {} void Game::Begin() { float color[4] = {1.0f, 1.0f, 1.0f, 1.0f}; context->ClearRenderTargetView(backBufferTarget, color); } void Game::End() { swapchain->Present(0, 0); } MyGame: struct VertexPos { XMFLOAT3 pos; }; void MyGame::Initialize(HWND _hwnd) { Game::Initialize(_hwnd); ID3DBlob* vsBuffer = 0; ID3DBlob* psBuffer = 0; HRESULT hr; try { CompileShader("VertexShader.hlsl", "main", "vs_4_0", &vsBuffer); //here is the error, when i start the .exe outside of Visual Studio } catch(BasicException be) { throw be; } hr = device->CreateVertexShader(vsBuffer->GetBufferPointer(), vsBuffer->GetBufferSize(), 0, &vshader); if(FAILED(hr)) { throw BasicException(typeid(this).name(), "failed creating vertexshader", hr); vsBuffer->Release(); } D3D11_INPUT_ELEMENT_DESC colorLayout[] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0} }; int numLayouts = ARRAYSIZE(colorLayout); hr = device->CreateInputLayout(colorLayout, numLayouts, vsBuffer->GetBufferPointer(), vsBuffer->GetBufferSize(), &ilayout); vsBuffer->Release(); if(FAILED(hr)) throw BasicException(typeid(this).name(), "failed creating input layout", hr); CompileShader("PixelShader.hlsl", "main", "ps_4_0", &psBuffer); hr = device->CreatePixelShader(psBuffer->GetBufferPointer(), psBuffer->GetBufferSize(), 0, &pshader); psBuffer->Release(); if(FAILED(hr)) throw BasicException(typeid(this).name(), "failed creating pixelshader", hr); } void MyGame::LoadContent() { Game::LoadContent(); HRESULT hr; VertexPos vertices[] = { XMFLOAT3(0.5f, 0.5f, 0.5f), XMFLOAT3(0.5f, -0.5f, 0.5f), XMFLOAT3(-0.5f, -0.5f, 0.5f) }; D3D11_BUFFER_DESC vertexDesc; ZeroMemory(&vertexDesc, sizeof(vertexDesc)); vertexDesc.Usage = D3D11_USAGE_DEFAULT; vertexDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexDesc.ByteWidth = sizeof(VertexPos)*3; D3D11_SUBRESOURCE_DATA rcData; ZeroMemory(&rcData, sizeof(rcData)); rcData.pSysMem = vertices; hr = device->CreateBuffer(&vertexDesc, &rcData, &vBuffer); if(FAILED(hr)) throw BasicException(typeid(this).name(), "failed creating vertexbuffer", hr); } void MyGame::Draw() { Game::Draw(); unsigned int stride = sizeof(VertexPos); unsigned int offset = 0; context->IASetInputLayout(ilayout); context->IASetVertexBuffers(0, 1, &vBuffer, &stride, &offset); context->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); context->VSSetShader(vshader, 0, 0); context->PSSetShader(pshader, 0, 0); context->Draw(3, 0); } //are those shader codes correct? VertexShader.hlsl float4 main( float4 pos : POSITION ) : SV_POSITION { return pos; } PixelShader.hlsl: float4 main() : SV_TARGET { return float4(0.0f, 1.0f, 1.0f, 1.0f); } I hope that Code is enough. Without drawing anything and just clearing the Backbuffer and presenting (Game::Begin(), Game::End()) I can see the whole window in color of the clearcolor, so I guess this is alright.   I hope I've got everything and anyone knows what to do.   Thanks 4 Help!   Kyle
  3. Kyle Corver

    XNA inherit from model and load

    Oh how embarassing ... finally I see it. Just turned around the logic ^^ Okay guys thanks a lot for helping ^^
  4. Kyle Corver

    XNA inherit from model and load

    Hmm okay writing a custom importer would probably be too much :D   But I'm confused: Is it generally in c# not porrible to cast from the inheritor to the base class? Just: class Base {...} class Inheritor : Base {....} int main() { Inheritor val = new Inheritor(); Base b = (Base)val; } That's the thing I'm trying to do.
  5. Kyle Corver

    XNA inherit from model and load

    I want some extra Attributes for My personal modelclass ^^ and trying to do it that way.   Yeah sorry forgot to describe the Error: It's a System.InvalidCastException that appears when I start the program.
  6. Hey guys,   just started programming with XNA an already the first Problem appeared: I wrote my own Model class MyModel that inherits from XNA Model class. class MyModel : Model The next Step is to load that Model from Content: private MyModel Model1; ... Model1 = (MyModel)Content.Load<Model>("leuchtturm"); Unfortunately that Code doesn't work. I just don't know why. Is there any chance to get that Code running? Otherwise I have to put the Model inside the MyModel class.   Thanks 4 Help!
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!