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[i]); trans = DirectX::XMVector3Transform(trans, lightRotation); DirectX::XMStoreFloat3(&frustumCorners[i], 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. After some long time i decided to try this again(that is why i bumped this thread) and i only get this error when i run 2instances of my application. I can't figure out what is wrong. Maybe this has something to do with visual studio 11?
  9. DirectXTex question

    [quote name='kubera' timestamp='1346734396' post='4976306'] Please consider asking here: [url="http://xboxforums.create.msdn.com/forums/default.aspx?GroupID=7"]http://xboxforums.cr....aspx?GroupID=7[/url] [/quote] Thanks. I posted there and i got the anwser. For people who are looking for this too : [url="http://directxtex.codeplex.com/discussions/369966"]link[/url]
  10. Hello, I have a question about loading multiple images and combine them into a texture array. Since the D3DX library is deprecated i use the DirectXTex library to load textures, but i can't find a way to load multiple jpg files and combine them into a texure array(I have no problem with DDS files). I searched the internet but i couldn't find anything useful. Any help will be appreciated.
  11. Good DirectX 11 tutorial/book?

    If you really want an in depth book of directX 11 i recommend [url="http://www.amazon.com/Introduction-3D-Game-Programming-DirectX/dp/1936420228/ref=sr_1_1?ie=UTF8&qid=1344974658&sr=8-1&keywords=directx+11"]Introduction to 3D Game Programming with DirectX 11[/url]. I own it and it is really good. You also got [url="http://www.amazon.com/Practical-Rendering-Computation-Direct3D-11/dp/1568817207/ref=sr_1_3?ie=UTF8&qid=1344974658&sr=8-3&keywords=directx+11"]Practical Rendering and Computation with Direct3D 11[/url]. I heard it is good but i don't own it so i can't make a judgement. If you are not looking for a book but for a website i can recommend www.directxtutorial.com. I got a membership there and he explains it very well but the site isn't updated very often. Rastertek is a nice free website which got a lot of tutorials. But in my opinion he doesn't explain it very well. But it is a really good website because it is free. I hope this helps you : )
  12. Heey guys, I got a question about running(in visual studio) multiple(2) direct x applications on the same computer. When i do this i get a warning : [source] D3D11: WARNING: ID3D11DeviceContext::Draw: Vertex Buffer at the input vertex slot 0 is not big enough for what the Draw*() call expects to traverse. This is OK, as reading off the end of the Buffer is defined to return 0. However the developer probably did not intend to make use of this behavior. [ EXECUTION WARNING #356: DEVICE_DRAW_VERTEX_BUFFER_TOO_SMALL ] [/source] I already debugged my code but this only happens when i try to debug 2 instances.\ My guess would be that the slot is already in use by the other app and that's why it throws this error. Thanks in advance.
  13. CreateVertexShader fails

    [quote name='Hornsj3' timestamp='1341064189' post='4954312'] [quote name='Jeffreyp' timestamp='1341060941' post='4954299'] [quote name='Hornsj3' timestamp='1341058590' post='4954293'] It doesn't look like you are compiling it anywhere. Check out D3DCompileFromFile. [/quote] 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 : )
  14. CreateVertexShader fails

    [quote name='Hornsj3' timestamp='1341058590' post='4954293'] It doesn't look like you are compiling it anywhere. Check out D3DCompileFromFile. [/quote] I'm using visual studio 11. So i compile it from there : ) Also the buffer size isn't 0.
  15. 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.