Jump to content
  • Advertisement

jeffreyp23

Member
  • Content Count

    99
  • Joined

  • Last visited

Community Reputation

178 Neutral

About jeffreyp23

  • Rank
    Member
  1. Thanks for all the responses ! A lot of useful information : )
  2.   Thanks for your response.     Isn't naming class members with m_ a bad habit? The reason I'm saying this is because a few months ago I had an internship and I showed some c++ source code and they said that naming c++ class members with m_ is a bad habit from the C language. Just curious : )     Oké, any other reasons I should use void* instead of char *? I saw both when I was googling around so I'm not really sure.   Thanks !
  3.   Oké, thanks for the explanation
  4.   Thanks I will check it out!
  5.   Thanks for the response! Some really informative things in there.       Yes you're right. I read it up on wikipedia and understand it now.       atAmount actually does the same as [source] at + amount > memory + size [/source]   But shouldn't be [source] at + amount > memory + size - 1 [/source]   Because if [source]at + amount == memory + size[/source] it would crash at [source] at+= amount [/source] right?       Actually I don't know how I should implement this method. Can you give me some tips?   Thanks.
  6. Hello,   Today I decided that I want to gain some knowledge about memory management. I don't know much about memory management so i thought it would be a nice "exercise" to try to create a pool allocator. Actually everything is working as expected but I think I did something wrong.   Here's the code :   PoolAllocator.h [source] #pragma once class PoolAllocator { public:     PoolAllocator(void);     ~PoolAllocator(void);     void allocate(const size_t amount);     char *obtain(const size_t amount);     void free(void *mem); private:     char *memory;     char *at;     int atAmount;     int size; };   [/source]   PoolAllocator.cpp [source] #include "PoolAllocator.h" PoolAllocator::PoolAllocator(void) { } PoolAllocator::~PoolAllocator(void) {     delete[] memory;     delete[] at; } void PoolAllocator::allocate(const size_t maxSize) {     memory = new char[maxSize];     at = &memory[0];     atAmount = 0;     size = maxSize; } char *PoolAllocator::obtain(const size_t amount) {     if(atAmount + amount     > size - 1)         return nullptr;     at += amount;     return at; } void PoolAllocator::free(void *mem) { } [/source]   main.cpp [source] #include <Windows.h> #include <iostream> #include "PoolAllocator.h" class A { public:     int val; }; class B { public:     int val; }; int main() {     PoolAllocator allocator;     allocator.allocate(1000);     A *a = (A*)allocator.obtain(sizeof(A));     a->val = 10;     std::cout << "A : " << a->val << std::endl;     B *b = (B*)allocator.obtain(sizeof(B));     b->val = 20;     std::cout << "A : " << a->val << std::endl << "B : " << b->val << std::endl;          system("pause");     return 0; } [/source]   My knowledge in memory management is really limited, so it could be that I made some 'horrible' mistake or something. Basically I just want someone to check this code.   Thanks in advance !
  7. Hi guys, I need help with my shadow mapping because I get incorrect results. I think I calculate my light view and light projection matrix wrong. Because I got a wrong shadow map too. Here is the code : [source] DirectX::XMMATRIX CreateLightViewProjectionMatrix(DirectX::XMFLOAT3 slightPos) { DirectX::BoundingFrustum frustom(DirectX::XMMatrixIdentity()); DirectX::XMVECTOR up = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); DirectX::XMVECTOR lightDir = DirectX::XMLoadFloat3(&slightPos); DirectX::XMMATRIX lightRotation = DirectX::XMMatrixLookAtLH(DirectX::XMVectorZero(), DirectX::XMVectorSet(DirectX::XMVectorGetX(lightDir) * -1.0f, DirectX::XMVectorGetY(lightDir) * -1.0f, DirectX::XMVectorGetZ(lightDir) * -1.0f, DirectX::XMVectorGetW(lightDir) * -1.0f), up); DirectX::XMFLOAT3 *frustumCorners = new DirectX::XMFLOAT3[frustom.CORNER_COUNT]; frustom.GetCorners(frustumCorners); for (int i = 0; i < frustom.CORNER_COUNT; i++) { DirectX::XMVECTOR trans = DirectX::XMLoadFloat3(&frustumCorners); trans = DirectX::XMVector3Transform(trans, lightRotation); DirectX::XMStoreFloat3(&frustumCorners, trans); } DirectX::BoundingBox lightBox; lightBox.CreateFromPoints(lightBox, frustom.CORNER_COUNT, frustumCorners, sizeof(DirectX::XMFLOAT3)); delete[] frustumCorners; DirectX::XMVECTOR lightBoxExtents = DirectX::XMLoadFloat3(&lightBox.Extents); DirectX::XMVECTOR lightBoxCenter = DirectX::XMLoadFloat3(&lightBox.Center); DirectX::XMVECTOR lightBoxMax = DirectX::XMVectorAdd(lightBoxCenter, lightBoxExtents); DirectX::XMVECTOR lightBoxMin = DirectX::XMVectorSubtract(lightBoxCenter, lightBoxExtents); DirectX::XMVECTOR boxSize = DirectX::XMVectorSubtract(lightBoxMax, lightBoxMin); DirectX::XMVECTOR halfBoxSize = DirectX::XMVectorScale(boxSize, 0.5f); DirectX::XMVECTOR lightPosition = DirectX::XMVectorAdd(lightBoxMin, halfBoxSize); DirectX::XMVectorSetZ(lightPosition, DirectX::XMVectorGetZ(lightBoxMin)); DirectX::XMVECTOR det = DirectX::XMVectorSet(-1.0f, -1.0f, -1.0f, -1.0f); lightPosition = DirectX::XMVector3Transform(lightPosition, DirectX::XMMatrixInverse(&det, lightRotation)); DirectX::XMMATRIX lightView = DirectX::XMMatrixLookAtLH(lightPosition, DirectX::XMVectorSubtract(lightPosition, lightDir), up); lightProjection = DirectX::XMMatrixOrthographicLH(DirectX::XMVectorGetX(boxSize), DirectX::XMVectorGetY(boxSize), -DirectX::XMVectorGetZ(boxSize), DirectX::XMVectorGetZ(boxSize)); return lightView * lightProjection; } [/source] This is the same code is used in the msdn shadow mapping example(for XNA). So I don't know what I did wrong. Thanks in advance.
  8. jeffreyp23

    CreateVertexShader fails

    I'm using visual studio 11. So i compile it from there : ) Also the buffer size isn't 0. [/quote] Am I missing something or maybe you don't know that shaders have to be compiled to byte code? What function are you calling to compile the shader into bytecode? [/quote] I found the problem. I did put the hlsl files instead of the cso files at [source] D3DReadFileToBlob [/source] It is working now. Thanks : )
  9. jeffreyp23

    CreateVertexShader fails

    I'm using visual studio 11. So i compile it from there : ) Also the buffer size isn't 0.
  10. Hello, I'm getting some strange error when trying to compile my vertex shader : [source] D3D11: ERROR: ID3D11Device::CreateVertexShader: Encoded Vertex Shader size doesn't match specified size. [ STATE_CREATION ERROR #166: CREATEVERTEXSHADER_INVALIDSHADERBYTECODE ] [/source] I already searched with Google but i couldn't find anything useful. Here is my code : c++ [source] ID3DBlob *VS, *PS; ID3D11VertexShader *m_pVS; ID3D11PixelShader *m_pPS; if(FAILED(D3DReadFileToBlob(pixelShader.c_str(), &PS))) { shader.isValid = false; return; } if(FAILED(D3DReadFileToBlob(vertexShader.c_str(), &VS))) { shader.isValid = false; return; } auto i = VS->GetBufferSize(); if(FAILED(m_pimpl->m_pDevice->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &m_pVS))) { std::cout << std::endl <<"Warning : failed to create vertex shader at file : " << " " << vertexShader.c_str() << std::endl; shader.isValid = false; return; } if(FAILED(m_pimpl->m_pDevice->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &m_pPS))) { std::cout << std::endl <<"Warning : failed to create pixel shader at file : " << " " << pixelShader.c_str() << std::endl; shader.isValid = false; return; } [/source] Vertex shader : [source] cbuffer ConstantBuffer { float4x4 matFinal; } struct VOut { float4 position : SV_POSITION; float4 color : COLOR; }; VOut main(float4 position : POSITION, float4 color : COLOR) { VOut output; output.position = mul(matFinal, position); output.color = color; return output; } [/source] Pixel Shader : [source] float4 main(float4 position : SV_POSITION, float4 color : COLOR) : SV_TARGET { return color; } [/source] I'm using SM 4. Thanks in advance.
  • 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!