precious roy

  • Content count

  • Joined

  • Last visited

Community Reputation

156 Neutral

About precious roy

  • Rank
  1. Game Timer problems

    Tanks for the help. (Nfries88) I am indeed making a very small game 192x192 pixels and i do mind the truncation.  the timer was indeed working but i was having a truncation error. where moving right = to 2 pixels moved and right 1 pixel. when in fact i was moving 1.5 in ether direction. all fixed now. thanks for your help
  2. Hello all,   I have been working on a small 2d rpg game, i am at the point where i need to use my game timer but it seems there is a problem with it and i can not figure out what it is. i have a fire ball that gets spawned and moves in a certain direction and continues untill outside of screen. void FireBall::FireBall() { //set movement switch (Direction) { case AD_Up: Acceleration.Y -= speed; // speed = 0.05 break; case AD_Down: Acceleration.Y += speed; break; case AD_Left: Acceleration.X -= speed; break; case AD_Right: Acceleration.X += speed; break; } } void FireBall::Update() { double dt = ThePrecisionDeltaTime::Instance().GetDt(); Velocity += Acceleration * dt; Acceleration = 0; Location += Velocity * dt; } void FireBall::Draw(Camera* camera) { Vector2F camtrans = Location - Vector2F(camera->Screen.Location()); mFireBallSheet->Draw(animation.GetAnimationFrame(), camtrans); } and my timer:  Windows_PrecisionDeltaTime::Windows_PrecisionDeltaTime() { LARGE_INTEGER Frequency; QueryPerformanceFrequency(&Frequency); m_Frequency = double(Frequency.QuadPart) / 1000.0; } double Windows_PrecisionDeltaTime::GetTicks() const { return m_CurrentTick; } double Windows_PrecisionDeltaTime::GetDt() const { return m_DeltaTime; } void Windows_PrecisionDeltaTime::Update() { LARGE_INTEGER CurrentTick; QueryPerformanceCounter(&CurrentTick); m_CurrentTick = double(CurrentTick.QuadPart) / m_Frequency; m_DeltaTime = m_CurrentTick - m_LastTick; m_LastTick = m_CurrentTick; } The problem is when i play the game in release or debug the fireball will fly at different speeds, also in release if i shoot them in close proximity some fireballs go faster than other fireballs when the speed should be a constant.   do any of you know what i am doing wrong here. i can record a vid if that will help illustratie the problem more.  
  3. DX11 Pixel shader does not seem to run.

    I guess this problem is a little harder than i expected. maybe the msdn forums will have better luck. if i ever fix this problem i will mention it here.
  4. DX11 Pixel shader does not seem to run.

    Jason Z: i am setting up "debug device"  UINT createDeviceFlags = 0; #ifdef _DEBUG createDeviceFlags |= D3D11_CREATE_DEVICE_DEBUG; #endif I am pretty sure that is what you mean. and i am not getting any errors.   the only message i am getting is  D3D11 WARNING: ID3D11DeviceContext::Draw: The Pixel Shader unit expects a Sampler to be set at Slot 0, but none is bound. This is perfectly valid, as a NULL Sampler maps to default Sampler state. However, the developer may not want to rely on the defaults.  [ EXECUTION WARNING #352: DEVICE_DRAW_SAMPLER_NOT_SET]   but it should still work.
  5. DX11 Pixel shader does not seem to run.

    That would be awsome, thanks.
  6. DX11 Pixel shader does not seem to run.

    thats the thing it is the same code. i even tried just outputting a color but still nothing. i can add my whole vs project if that will help?   It should compile if you have the windows sdk installed.    TestGameState.cpp is where all the magic happens 
  7. Hello,   I am new to directx programming and i am having some problems drawing my models to screen.   i am trying to impliment the DrawInstanced tutorial from rastertek : into my game engine. but i am having trouble where the model is not being drawn to my screen. in the image below you can see that it is calling the vertex shader but not the pixel shader.   The pixel shader is not set to null so it should be called but as far as i can see it is not.   the code below is my messy attempt to go as bare bones as possible and no other calls ar made any ware else other than the usual clear screen stuff. #include "TestGameState.h" #include "DirectX\DX_ScreenHandler.h" #include "DirectX\Texture\DX_Texture.h" #include "DirectX\Shader\DX_Shader.h" //just the load (LoadShaderFile) function is used #include <DirectXMath.h> using namespace DirectX; //model ID3D11Buffer* m_vertexBuffer; ID3D11Buffer* m_instanceBuffer; int m_vertexCount; int m_instanceCount; DX_Texture* m_Texture; //shader ID3D11InputLayout* InputLayout; // the pointer to the input layout //ID3D11Buffer* ConstantBuffer; = m_matrixBuffer // the constant buffer interface ID3D11VertexShader* VertexShader; // the pointer to the vertex shader ID3D11PixelShader* PixelShader; // the pointer to the pixel shader ID3D11Buffer* m_matrixBuffer; ID3D11SamplerState* m_sampleState; D3D11_INPUT_ELEMENT_DESC polygonLayout[3]; unsigned int numElements; D3D11_BUFFER_DESC matrixBufferDesc; D3D11_SAMPLER_DESC samplerDesc; struct VertexType { XMFLOAT3 position; XMFLOAT2 texture; }; struct InstanceType { XMFLOAT3 position; }; struct MatrixBufferType { XMMATRIX world; XMMATRIX view; XMMATRIX projection; }; bool InitModel() { ID3D11Device* device = TheDXScreen::Instance().GetDevice(); VertexType* vertices; InstanceType* instances; D3D11_BUFFER_DESC vertexBufferDesc, instanceBufferDesc; D3D11_SUBRESOURCE_DATA vertexData, instanceData; HRESULT result; // Set the number of vertices in the vertex array. m_vertexCount = 3; // Create the vertex array. vertices = new VertexType[m_vertexCount]; if (!vertices) { return false; } // Load the vertex array with data. vertices[0].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); // Bottom left. vertices[0].texture = XMFLOAT2(0.0f, 1.0f); vertices[1].position = XMFLOAT3(0.0f, 1.0f, 0.0f); // Top middle. vertices[1].texture = XMFLOAT2(0.5f, 0.0f); vertices[2].position = XMFLOAT3(1.0f, -1.0f, 0.0f); // Bottom right. vertices[2].texture = XMFLOAT2(1.0f, 1.0f); // Set up the description of the static vertex buffer. vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT; vertexBufferDesc.ByteWidth = sizeof(VertexType) * m_vertexCount; vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; vertexBufferDesc.CPUAccessFlags = 0; vertexBufferDesc.MiscFlags = 0; vertexBufferDesc.StructureByteStride = 0; // Give the subresource structure a pointer to the vertex data. vertexData.pSysMem = vertices; vertexData.SysMemPitch = 0; vertexData.SysMemSlicePitch = 0; // Now create the vertex buffer. result = device->CreateBuffer(&vertexBufferDesc, &vertexData, &m_vertexBuffer); if (FAILED(result)) { return false; } // Release the vertex array now that the vertex buffer has been created and loaded. delete[] vertices; vertices = 0; // Set the number of instances in the array. m_instanceCount = 4; // Create the instance array. instances = new InstanceType[m_instanceCount]; if (!instances) { return false; } // Load the instance array with data. instances[0].position = XMFLOAT3(-1.5f, -1.5f, 5.0f); instances[1].position = XMFLOAT3(-1.5f, 1.5f, 5.0f); instances[2].position = XMFLOAT3(1.5f, -1.5f, 5.0f); instances[3].position = XMFLOAT3(1.5f, 1.5f, 5.0f); // Set up the description of the instance buffer. instanceBufferDesc.Usage = D3D11_USAGE_DEFAULT; instanceBufferDesc.ByteWidth = sizeof(InstanceType) * m_instanceCount; instanceBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER; instanceBufferDesc.CPUAccessFlags = 0; instanceBufferDesc.MiscFlags = 0; instanceBufferDesc.StructureByteStride = 0; // Give the subresource structure a pointer to the instance data. instanceData.pSysMem = instances; instanceData.SysMemPitch = 0; instanceData.SysMemSlicePitch = 0; // Create the instance buffer. result = device->CreateBuffer(&instanceBufferDesc, &instanceData, &m_instanceBuffer); if (FAILED(result)) { return false; } // Release the instance array now that the instance buffer has been created and loaded. delete[] instances; instances = 0; return true; } bool Shader() { ID3D11Device* device = TheDXScreen::Instance().GetDevice(); byte* VSData = nullptr; int VSSize = 0; byte* PSData = nullptr; int PSSize = 0; bool VSCompiled = DX_Shader::LoadShaderFile("InstancedVertexShader.cso", VSData, VSSize); bool PSCompiled = DX_Shader::LoadShaderFile("InstancedPixelShader.cso", PSData, PSSize); if (!VSCompiled || !PSCompiled) return false; // encapsulate both shaders into shader objects device->CreateVertexShader(VSData, VSSize, NULL, &VertexShader); device->CreatePixelShader(PSData, PSSize, NULL, &PixelShader); // Create the vertex input layout description. // This setup needs to match the VertexType stucture in the ModelClass and in the shader. polygonLayout[0].SemanticName = "POSITION"; polygonLayout[0].SemanticIndex = 0; polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; polygonLayout[0].InputSlot = 0; polygonLayout[0].AlignedByteOffset = 0; polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[0].InstanceDataStepRate = 0; polygonLayout[1].SemanticName = "TEXCOORD"; polygonLayout[1].SemanticIndex = 0; polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT; polygonLayout[1].InputSlot = 0; polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; polygonLayout[1].InstanceDataStepRate = 0; polygonLayout[2].SemanticName = "TEXCOORD"; polygonLayout[2].SemanticIndex = 1; polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT; polygonLayout[2].InputSlot = 1; polygonLayout[2].AlignedByteOffset = 0; polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_INSTANCE_DATA; polygonLayout[2].InstanceDataStepRate = 1; // Get a count of the elements in the layout. numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]); HRESULT result = device->CreateInputLayout(polygonLayout, numElements, VSData, VSSize, &InputLayout); if (FAILED(result)) { return false; } // Release the vertex shader buffer and pixel shader buffer since they are no longer needed. delete VSData; VSData = nullptr; delete PSData; PSData = nullptr; // Setup the description of the dynamic matrix constant buffer that is in the vertex shader. matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC; matrixBufferDesc.ByteWidth = sizeof(MatrixBufferType); matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; matrixBufferDesc.MiscFlags = 0; matrixBufferDesc.StructureByteStride = 0; // Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class. result = device->CreateBuffer(&matrixBufferDesc, NULL, &m_matrixBuffer); if (FAILED(result)) { return false; } // Create a texture sampler state description. samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP; samplerDesc.MipLODBias = 0.0f; samplerDesc.MaxAnisotropy = 1; samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; samplerDesc.BorderColor[0] = 0; samplerDesc.BorderColor[1] = 0; samplerDesc.BorderColor[2] = 0; samplerDesc.BorderColor[3] = 0; samplerDesc.MinLOD = 0; samplerDesc.MaxLOD = D3D11_FLOAT32_MAX; // Create the texture sampler state. result = device->CreateSamplerState(&samplerDesc, &m_sampleState); if (FAILED(result)) { return false; } return true; } void TestGameState::Initialize() { TheDXScreen::Instance().SetBackBufferColor("#6495ED"); //init model & texture bool res = InitModel(); if (res == false) throw "whaa epic fail"; m_Texture = new DX_Texture(); res = m_Texture->Initialize(L"roguelikeSheet_transparent.png"); if (res == false) throw "whaa epic fail"; //shader res = Shader(); if (res == false) throw "whaa epic fail"; } void TestGameState::Destroy() { } void TestGameState::Pause() { } void TestGameState::Resume() { } void TestGameState::Update() { } // Camera rotation static float lookatZ = 0; static float lookatY = 0; static float Zoom = 10; void TestGameState::Draw() { ID3D11Device* device = TheDXScreen::Instance().GetDevice(); ID3D11DeviceContext* deviceContext = TheDXScreen::Instance().GetContext(); lookatZ += 0.0001f; //camera // calculate the world matrices XMMATRIX worldMatrix = DirectX::XMMatrixIdentity();//DirectX::XMMatrixRotationY(Time); // calculate the view transformation //XMVECTOR vecCamPosition = DirectX::XMVectorSet(0, 0, -10, 0); XMVECTOR vecCamPosition = DirectX::XMVectorSet((cosf(lookatZ) * Zoom), sinf(lookatY) * Zoom, (sinf(lookatZ) * Zoom), 0); XMVECTOR vecCamLookAt = XMVectorSet(0, 0, 0, 0); XMVECTOR vecCamUp = XMVectorSet(0, 1, 0, 0); XMMATRIX viewMatrix = XMMatrixLookAtLH(vecCamPosition, vecCamLookAt, vecCamUp); // calculate the projection transformation //CoreWindow^ Window = CoreWindow::GetForCurrentThread(); // get the window pointer XMMATRIX projectionMatrix = XMMatrixPerspectiveFovLH( XMConvertToRadians(45), // the field of view (FLOAT)TheDXScreen::Instance().GetScreenSize().Width / (FLOAT)TheDXScreen::Instance().GetScreenSize().Height, // aspect ratio 1, // the near view-plane 100); //do stuff // Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing. unsigned int strides[2]; unsigned int offsets[2]; ID3D11Buffer* bufferPointers[2]; // Set the buffer strides. strides[0] = sizeof(VertexType); strides[1] = sizeof(InstanceType); // Set the buffer offsets. offsets[0] = 0; offsets[1] = 0; // Set the array of pointers to the vertex and instance buffers. bufferPointers[0] = m_vertexBuffer; bufferPointers[1] = m_instanceBuffer; // Set the vertex buffer to active in the input assembler so it can be rendered. deviceContext->IASetVertexBuffers(0, 2, bufferPointers, strides, offsets); // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles. deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST); // Render the model using the texture shader. // Set the shader parameters that it will use for rendering. { HRESULT result; D3D11_MAPPED_SUBRESOURCE mappedResource; MatrixBufferType* dataPtr; unsigned int bufferNumber; // Lock the constant buffer so it can be written to. result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); if (FAILED(result)) { int fail = 0;//break point } // Get a pointer to the data in the constant buffer. dataPtr = (MatrixBufferType*)mappedResource.pData; // Copy the matrices into the constant buffer. dataPtr->world = worldMatrix; dataPtr->view = viewMatrix; dataPtr->projection = projectionMatrix; // Unlock the constant buffer. deviceContext->Unmap(m_matrixBuffer, 0); // Set the position of the constant buffer in the vertex shader. bufferNumber = 0; // Now set the constant buffer in the vertex shader with the updated values. deviceContext->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer); // Set shader texture resource in the pixel shader. m_Texture->SetTexture(); } // Now render the prepared buffers with the shader. { // Set the vertex and pixel shaders that will be used to render this triangle. deviceContext->VSSetShader(VertexShader, nullptr, 0); deviceContext->PSSetShader(PixelShader, nullptr, 0); // Set the vertex input layout. deviceContext->IASetInputLayout(InputLayout); // Set the sampler state in the pixel shader. deviceContext->PSSetSamplers(0, 1, &m_sampleState); // Render the triangle. deviceContext->DrawInstanced(m_vertexCount, m_instanceCount, 0, 0); } } if you need any more information please let me know, thanks for the help.   Edit:  i had a look at microsofts attempt to help but i am pretty sure this is not my problem.   and this seems to be the problem i am having but i do not understand the solution "OMSetBlendState" i am not using that
  8. Directx11 Sprite class

    Hmm interesting. i will have a look at it. thanks
  9. Hello,   I am pretty new with working with directx and i cant seem to think of a good way to set up my vertex buffer. so my problem i have a sprite sheet with different size sprites on it. what is the best way to make my vertex buffer so that i don't care about the size of my sprite.   should i make a vertex buffer for each sprite? or cal i pass in vertex information into the shader and do stuff in their.   greetings, Roy   Edit: would Instancing mentioned in the below article be what i am looking for? this is the first time i am reading about it, but seems to be what i am looking for but i still dont fully understand how the vertex buffer would work. do i have 1 with 4 verts and just draw that at different positions?
  10. Visual studio 2013 HLSL compiler Question

    After doing a lot of testing it seems that the settings were right, but just does not work for me in vs2013 i did however install vs2015 yesterday and it does compile just fine in 2015 so its ether a bug or i broke vs2013 when installing vs2015.
  11. Hello,   I am struggling to set the shader version, i have a pixel shader and a vertex shader in the properties of that file i tell it to use 5_0, but when i compile and run the program the visual studio graphics analyzer tells me i am using 4_0_level_9_1. this is a problem because i want to access my position data in my pixel shader but it tells me i can when i am using 4_0_level_9_1. i get the error: error X4502: Shader model ps_4_0_level_9_1 doesn't allow reading from position semantics.     i think i am missing a setting but i have no idea what it is.
  12. XNA + Camera2D + PerPixelCollision

    Hello Plutonium,   i haven't looked at your code but have you tried calculating the collusion before you draw everything zoomed in?   so after calculating you do the math for the zoom.
  13. Ok after a long search i managed to find out how to fix the problem.   i ended up making it like this.   if(tempMaterials[i].pTextureFilename != NULL) { DWORD dwNum = MultiByteToWideChar (CP_ACP, 0, tempMaterials[i].pTextureFilename, -1, NULL, 0); wchar_t *pwText; pwText = new wchar_t[dwNum]; if(!pwText) { delete []pwText; } MultiByteToWideChar (CP_ACP, 0, tempMaterials[i].pTextureFilename, -1, pwText, dwNum ); std::wstring TextureName = FileLocation; TextureName.append(pwText); //if there is a texture to load, load it if(FAILED(D3DXCreateTextureFromFile(d3ddev, TextureName.c_str(), &texture[i]))) texture[i] = NULL; // if there is no texture, set the texture to NULL delete []pwText; } else texture[i] = NULL;       Thanks Chris!
  14. Hello,   i  have been looking for an answer to this question for the past 2 days and have only been able to find one that sometimes works. i will start by showing my code. the code in this case loads a model and continues to load the materials and textures.   void LoadModel(LPWSTR FileName, LPWSTR FileLocation) { LPD3DXBUFFER bufShipMaterial; D3DXLoadMeshFromX((std::wstring(FileLocation) + FileName).c_str(), // load this file D3DXMESH_SYSTEMMEM, // load the mesh into system memory d3ddev, // the Direct3D Device NULL, // we aren't using adjacency &bufShipMaterial, // put the materials here NULL, // we aren't using effect instances &numMaterials, // the number of materials in this model &ModelMesh); // put the mesh here // retrieve the pointer to the buffer containing the material information D3DXMATERIAL* tempMaterials = (D3DXMATERIAL*)bufShipMaterial->GetBufferPointer(); // create a new material buffer for each material in the mesh material = new D3DMATERIAL9[numMaterials]; texture = new LPDIRECT3DTEXTURE9[numMaterials]; for(DWORD i = 0; i < numMaterials; i++) // for each material... { material[i] = tempMaterials[i].MatD3D; // get the material info material[i].Ambient = material[i].Diffuse; // make ambient the same as diffuse //if there is a texture to load, load it if(FAILED(D3DXCreateTextureFromFileA(d3ddev, tempMaterials[i].pTextureFilename,&texture[i]))) texture[i] = NULL; // if there is no texture, set the texture to NULL } } The code above works fine to a point. when the texture is not in the same folder as the executable it will not lode it. you can see that when i load the texture i add the FileLocation to the Filename and this works like a charm. but now i want to do the same when loading my textures and this is where the problem start. i wiped up this, it probably well i know its not the best way of doing this because this gives me an error 2 out of the 3 times running the program   if(tempMaterials[i].pTextureFilename != NULL) { //converting the lpstw from pTextureFilename to lpwstr char* convertMe = new char[sizeof(tempMaterials[i].pTextureFilename)]; strcpy(convertMe,tempMaterials[i].pTextureFilename); int buffSize = (int)strlen(convertMe) + 1; LPWSTR TestureName = new wchar_t[buffSize]; MultiByteToWideChar(CP_ACP, 0, convertMe, buffSize, TestureName, buffSize); std::wstring test = (std::wstring(FileLocation) + TestureName); //if there is a texture to load, load it if(FAILED(D3DXCreateTextureFromFile(d3ddev, test.c_str(), &texture[i]))) texture[i] = NULL; // if there is no texture, set the texture to NULL } else texture[i] = NULL;     the error that it gives is "Attempted to read or write protected memory. This is often an indication that other memory is corrupt.". anyways what i'm doing here is converting a LPSTR string to LPWSTR and then combine them, just like i did withe the model file.   now i know that the problem is somewhere in the converting of the string, i guess my question is how am i supposed to do this ?
  15. Basic networking question.

    Quote:Original post by Anntor Using just the database without precached player data in RAM would be a huge performance hit for any MMO, which needs to update player state a lot per second. Well that actually sounds logical. Thanks for the info I think I will do some brainstorming on this. I will post my results. When I’m finished :}