Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Everything posted by benp444

  1. benp444

    D3D11CreateDevice failed

    My solution was to uninstall the update and now everything works fine:   How to uninstall update 2670838 To uninstall update 2670838, follow these steps: Click Start, click Control Panel, click Programs, and then click Programs and Features. Click View installed updates. Click Update for Microsoft Windows (KB 2670838), and then click Uninstall.
  2. Yup - thats it. KB 2670838 has stopped debug mode working. The link you pasted above leads on to a more detailed debate, but my solution was to uninstall this update and now everything works fine.   Going to switch off automatic updates from now on.   Thanks,   Ben.
  3. For a few weeks I have been developing only in release mode. I recently switched back to debug mode and found my previously working code failed. I have narrowed down the issue but have found it is not only present in the code I was working on, but all code (test code, old projects, sample code etc) on my machine.   The problem is that when D3D10CreateDeviceAndSwapChain is called in debug mode I get an E_FAIL error code (see error box attached). I.e. the code below (taken from a Frank Luna sample) fails:         HR( D3D10CreateDeviceAndSwapChain(             0,                 //default adapter             md3dDriverType,             0,                 // no software device             D3D10_CREATE_DEVICE_DEBUG,             D3D10_SDK_VERSION,             &sd,             &mSwapChain,             &md3dDevice) );   However if I change the 4th argument to 0 everything works.   I can only think that either my graphics card is broken or the Direct X SDK or Direct X runtime is somehow corrupt. Has anyone got any suggestions as to what should be my next steps?   Ben.
  4. I have gone through the GSParticles demo that comes with the DirectX SDK and studied Frank Lunas chapter on particles in his DirectX 10 book. I can get particles working and have no problem understanding the basics however I am struggling to come up with a good solution or class design such that I can create (e.g.) explosions whenever I want. Here is a basic requirement that I want: 1) Create a particle explosion on the GPU using a geometry shader - similar to the GSParticle but the explosion will start and then complete. Lets say the explosion lasts for 3 seconds. 2) be able to create an arbitrary amount of explosions within in reason (e.g. 5) without disrupting the existing ones. 3) be able to create these explosions during any game frame I choose. 4) An example of the above would be explosion a) at t=0 secs, explosion b) at t=0.5, c) at t=2.5, d) at t=360 etc. The pseudo code looks at bit like this: [source lang="cpp"] class Particle { void init(); void render(); //this actually takes the elapsed and totalTime as well } Particle::init(){ m_fXPosition= m_pEffect10->GetVariableByName( "g_position" )->AsVector(); } Particle::render() { //update pass m_fXPosition->SetFloatVector((float*)&m_position); if(firstTime) Draw(); else DrawAuto(); //render pass, passes in elapsed time //etc... } [/source] This class currently works in my game as it stands e.g: [source lang="cpp"]onDeviceInit() { m_explosion=new Particle(); m_explosion.init(); } onFrameUpdate() { //an explosion event occurred so m_explosion.reset(); //sets first time to true; } onFrameRender() { //this is continually called whether there are particles alive or not. m_explosion.render(); } [/source] The above however fails requirement 2. If a second explostion event occurs before the existing one is complete then the existing particles will be destroyed because firstTime will be true and Draw() will be called. My shader is very similar to GSParticles.fx and for the sake of this topic consider it the same. I appreciate that seeding particles might be the way to go and of course GSParticle has a single seed (PT_LAUNCHER), but I can't see how I can inject seeds to an already running shader. Bearing in mind that I don't want to create a new Particle class and call init() everytime I want an explosion, The only way I can see of doing this would be to create (e.g.) 5 particle instances and store them in an array. Then when I want an explosion I get the next instance set its position. This would allow me a maximum of 5 explosions at any given time (a 6th explosion would kill all particles in the 1st explosion). Can anyone give me some hint as to how to create a simple particle framework using Geometry shaders in DirectX 10?
  5. benp444

    GPU Particle Class Design

    Sorry, solved it. I have created a shader variable (g_createExplosion). On each frame if this is set to true it will kick off another cycle of particles without effecting the existing ones.
  6. Firstly sorry for yet another newby post regarding quaternions but I have scoured the forums for hours without any luck. Secondly I have posted this in the Direct X section as I am hoping to get answers in the form of D3DXQuaternion... method calls rather than a load of maths which may only hinder my progression. Anyhow my problem is fairly straightforward. I have a simple model viewer which shows my model in the middle of the screen. When I press the keys X,Y or Z the model should rotate in MODEL coordinates. I am trying to use Quaternions to do this. The results are that I can only get a single axis to rotate in model space, the other two will subsequently rotate in world space. My code is: D3DXQUATERNION qZ; D3DXQUATERNION qY; D3DXQUATERNION qX; D3DXQUATERNION qOrient; D3DXQUATERNION qTotal; D3DXQuaternionIdentity(&qZ); D3DXQuaternionIdentity(&qY); D3DXQuaternionIdentity(&qX); D3DXQuaternionIdentity(&qOrient); D3DXVECTOR3 axisZ(0,0,1); D3DXVECTOR3 axisY(0,1,0); D3DXVECTOR3 axisX(1,0,0); D3DXQuaternionRotationAxis(&qZ,&axisZ,ga->getRotation().z); D3DXQuaternionRotationAxis(&qY,&axisY,ga->getRotation().y); D3DXQuaternionRotationAxis(&qX,&axisX,ga->getRotation().x); //I am not sure if this is neccessary. D3DXQuaternionNormalize(&qZ,&qZ); D3DXQuaternionNormalize(&qY,&qY); D3DXQuaternionNormalize(&qX,&qX); //The first quat will rotate correctly in model space, the latter 2 will rotate in world space. qTotal=qY*qX*qZ; D3DXMATRIX rotation; D3DXMatrixRotationQuaternion(&rotation,&qTotal); world=scale*rotation*move; Note that ga is an instance of GameActor and ga->getRotation() returns a D3DXVECTOR3 containing x,y and z rotations in radians. I would be grateful if anyone could give me a high level approach to solve my problem? Ben.
  7. benp444

    Quaternion x,y,z rotation

    Thanks for you help. It has taken me a day of playing with a toy aeroplane to work it out, but I have got it working and the resulting code is posted below. The major problem was that I needed to maintain state of my complete model transform and the 3 axis. My game actor now has a stateful tranformation matrix (m_transform) and 3 stateful axis (m_XAxis, m_YAxis and m_ZAxis). [source lang="cpp"]void GameActor::VUpdate(float elapsedTime){ D3DXQUATERNION qX; D3DXQUATERNION qY; D3DXQUATERNION qZ; D3DXMATRIX matRotX; D3DXMATRIX matRotY; D3DXMATRIX matRotZ; D3DXMATRIX rotation; //calculate incremental change for 3 axis D3DXQuaternionRotationAxis(&qX,&m_Xaxis,m_rotation.x); D3DXQuaternionRotationAxis(&qY,&m_Yaxis,m_rotation.y); D3DXQuaternionRotationAxis(&qZ,&m_Zaxis,m_rotation.z); //get matix rotations for each axis. D3DXMatrixRotationQuaternion(&matRotX,&qX); D3DXMatrixRotationQuaternion(&matRotY,&qY); D3DXMatrixRotationQuaternion(&matRotZ,&qZ); //calculate final rotation. This will still have slight errors as the axis were //not recalculated between calls to D3DXMatrixRotationQuaternion above, but //the are insignificant. rotation=matRotX*matRotY*matRotZ; //modify the stateful transform m_transform=m_transform*rotation; //will add scale and move later. These will both need to be stateless. //modify the stateful axis D3DXVECTOR4 vec4X; D3DXVec3Transform(&vec4X, &m_Xaxis, &rotation); m_Xaxis=D3DXVECTOR3(vec4X.x,vec4X.y,vec4X.z); //realign Y axis D3DXVECTOR4 vec4Y; D3DXVec3Transform(&vec4Y, &m_Yaxis, &rotation); m_Yaxis=D3DXVECTOR3(vec4Y.x,vec4Y.y,vec4Y.z); //realign Z axis D3DXVECTOR4 vec4Z; D3DXVec3Transform(&vec4Z, &m_Zaxis, &rotation); m_Zaxis=D3DXVECTOR3(vec4Z.x,vec4Z.y,vec4Z.z); }[/source] I still may still be able to make this faster and with less lines of code. Perhaps use QuaternionRotationYawPitchRoll. If anyone can see how to do this in a better way then please say. Ben.
  8. benp444

    Quaternion x,y,z rotation

    In answer to 'what I am expecting': I have a model of an aircraft. I am looking down on it sitting on the runway. the z axis points out of the screen, the y axis points up and the x axis off to the right. The aircraft is pointing up at the top of the screen. If I press the Y key I expect it to rotate along the planes fuselage (roll), if I press the X key I expect pitch and Z yaw. I get all these actions if I only press a single key - this is because model space and world space are initially aligned. The GameActor class is mine and is very transient at the moment. I can/will add any members and methods which enable me to provide motion. Note that the GameActor code only provides accessors so I seen no point in posting it. The meat of what I am trying to do is posted in my code above. I sort of understand where you are coming from, and I have read elsewhere that you cannot simply convert Euler angles to quats like this. OK so if I can't rotate around X, then Y, then Z what should my approach be? +1 for that. Do I need to do something with my axis vectors (axisX/Y/Z in the code above)? Is it wrong to specify them the way I have? Should I store a single quat as a member of my GameActor class and apply rotations on this - I have read this somewhere, but I cannot see how a single quat would work.
  9. benp444

    Quaternion x,y,z rotation

    Thanks, but I already tried that: D3DXQuaternionRotationYawPitchRoll(&qOrient,ga->getRotation().y,ga->getRotation().x,ga->getRotation().z); D3DXMatrixRotationQuaternion(&rotation,&qOrient); world=scale*rotation*move; The results are similar in that one axis rotates in model coords and the rest in world coords. Note in this case it is Z that always rotates in model space and X and Y that rotate in world space.
  10. I have created a tetrahedron using 4 vertices and 12 indices. I have then calculated the normals for each vertex and passed it to the shader to do ambient and diffuse lighting. The results are shown in the picture below and as you can see I get dark sections where I expected lit sections: [attachment=9981:tetra bad shade.png] I am assuming that this is because of interpolation of normals. As I say my approach to create this tetrahedron was to use only 4 vertices and let the indices do the rest. Should I actually define 4 faces (12 vertices) and define the normals for each face. I know this latter approach would work but my question is should the former approach also work, or should I reserve the low vertex count solution only for high polygon count objects? My code for defining the vertices, indices and normal is below: PrimitiveVertexStruct vertices[]= { { D3DXVECTOR3(0.0f,1.0f,0.0f), WHITE_VECTOR, ZERO_VECTOR3 }, //1 { D3DXVECTOR3(1.0f,-1.0f,0.0f), RED_VECTOR, ZERO_VECTOR3 }, //2 { D3DXVECTOR3(-1.0f,-1.0f,0.0f),BLUE_VECTOR, ZERO_VECTOR3 }, //3 { D3DXVECTOR3(0.0f,0.0f,2.0f), BLACK_VECTOR, ZERO_VECTOR3 }, //4 }; m_numTetraVertices = sizeof(vertices) / sizeof(PrimitiveVertexStruct); m_numTetraIndices=12; DWORD indices[] = { 0,1,3, //1,2,4 1,2,3, //2,3,4 2,0,3, //3,1,4 0,2,1 //1,3,2 }; //compute average normals for(int i=0;i<m_numTetraVertices;i++) { //indices of triangle int i0=indices[i*3+0]; int i1=indices[i*3+1]; int i2=indices[i*3+2]; //vertices of triangle D3DXVECTOR3 v0=vertices[i0].Pos; D3DXVECTOR3 v1=vertices[i1].Pos; D3DXVECTOR3 v2=vertices[i2].Pos; //compute face normal D3DXVECTOR3 e0=v1 - v0; D3DXVECTOR3 e1=v2 - v0; D3DXVECTOR3 normal; D3DXVECTOR3 cross; D3DXVec3Cross(&normal, &e0, &e1); //add to any existing normals for that vertex vertices[i0].Normal+=normal; vertices[i1].Normal+=normal; vertices[i2].Normal+=normal; }
  11. Thanks, I was actually re-normalizing (in c++, not shader) I just didn't paste the code. Anyhow you have answered my question and I will now define the full faces for all my low polygon shapes.
  12. Hi, I am trying to draw both sprites and 2d primitives on the screen at the same time and am having problems with the depth. The primitives are created using D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP. There are two situations that I can have. Note that the rectangles have a depth of 0.5, the left hand ball of 0.2 and the two balls on the right 0.6: 1) Depth Enabled: the sprites render correctly based on the assigned depth. However the alpha channels of the sprite show up. [attachment=9834:DepthEnabled.png] 2) Depth Disabled: the primitives and sprites do not render correctly on depth. If the sprites are the last group to be drawn the they will be on top and visa versa [attachment=9833:DepthDisabled.png] During initialisation have created two depth stencils: [source lang="cpp"]//Create a disabled depth state SAFE_RELEASE(m_pDepthDisabledState); D3D10_DEPTH_STENCIL_DESC depthStencilDesc; ZeroMemory(&depthStencilDesc, sizeof(depthStencilDesc)); depthStencilDesc.DepthEnable = false; depthStencilDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL; depthStencilDesc.DepthFunc = D3D10_COMPARISON_LESS; depthStencilDesc.StencilEnable = false; depthStencilDesc.StencilReadMask = 0xFF; depthStencilDesc.StencilWriteMask = 0xFF; depthStencilDesc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_INCR; depthStencilDesc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP; depthStencilDesc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS; depthStencilDesc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_DECR; depthStencilDesc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP; depthStencilDesc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS; hr = DXUTGetD3D10Device()->CreateDepthStencilState(&depthStencilDesc, &m_pDepthDisabledState); //Create an enabled depth state SAFE_RELEASE(m_pDepthEnabledState); depthStencilDesc.DepthEnable = true; //the only difference hr = DXUTGetD3D10Device()->CreateDepthStencilState(&depthStencilDesc, &m_pDepthEnabledState); //set to disabled by default. DXUTGetD3D10Device()->OMSetDepthStencilState(m_pDepthDisabledState, 0); //DXUTGetD3D10Device()->OMSetDepthStencilState(m_pDepthEnabledState, 0); [/source] I have tried switching between depth enabled/disabled during the rendering of either the primitives or the sprites but it seems and cannot mix and match the two. Has anyone any ideas what approach I should take to solve this? Thanks, Ben.
  13. OK. So for sprites the following line sorts the buffer: m_pSpriteObject->Begin(D3DX10_SPRITE_SORT_DEPTH_BACK_TO_FRONT); I will however have to ensure that no two sprites have the same depth; in image 1) both sprites were 0.6. Thats fine I can write a trivial bit of code that takes the user defined depth and adds 0.0001 to it so that it is highly unlikely two sprites will have the same depth. I was going to say that I still had a problem with the primitives (which are drawn at a depth of 0.5). However I found that if I draw the primitives before the sprites (which may be shallower or deeper than sprites) then there is no clipping and all the depth is correct. I can't quite understand why this works as the ordering is not as discussed but it does. Successful depth enabled sprites and primitives below: [attachment=9847:DepthEnabledWorks.png] Thanks both for you help. Ben.
  14. Thanks for your response. My calls to draw may not come in an order based on depth so I really want to keep depth testing on. However this approach results in image 1) shown in my original post. I don't know much about the alpha blending. I have posted my code below that handles the alpha channel. Again looking at image 1); are you suggesting that this problem may have nothing to do with depth testing and that I should be looking at my alpha code? Apart from the initialisation code below and the rendering code that follows I don't touch the alpha set up. Perhaps my Alpha setup is wrong? More initialisation code wrt alpha: [source lang="cpp"] D3D10_BLEND_DESC StateDesc; ZeroMemory(&StateDesc, sizeof(D3D10_BLEND_DESC)); StateDesc.AlphaToCoverageEnable = TRUE; //changed from FALSE 040712 StateDesc.BlendEnable[0] = TRUE; StateDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA; StateDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; StateDesc.BlendOp = D3D10_BLEND_OP_ADD; StateDesc.SrcBlendAlpha = D3D10_BLEND_ZERO; StateDesc.DestBlendAlpha = D3D10_BLEND_ZERO; StateDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; StateDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL; hr=pD3DDevice->CreateBlendState(&StateDesc, &m_pBlendState10);[/source] And the code that renders the sprites: [source lang="cpp"]hr = m_pSpriteObject->SetProjectionTransform(&(g_pGameManager->m_pMatProjection)); // start drawing the sprites hr=m_pSpriteObject->Begin(D3DX10_SPRITE_SORT_DEPTH_BACK_TO_FRONT); //D3DX10_SPRITE_SORT_DEPTH_FRONT_TO_BACK,D3DX10_SPRITE_SORT_DEPTH_BACK_TO_FRONT //Save the current blend state ID3D10BlendState* pOrigBlendState; DXUTGetD3D10Device()->OMGetBlendState(&pOrigBlendState, OriginalBlendFactor, &OriginalSampleMask); // Draw all the sprites in the pool hr=m_pSpriteObject->DrawSpritesBuffered(&(m_spritePool[0]), m_spritePoolIdx); // Set the blend state for alpha drawing if(m_pBlendState10) { FLOAT NewBlendFactor[4] = {1,1,1,1}; DXUTGetD3D10Device()->OMSetBlendState(m_pBlendState10, NewBlendFactor, 0xffffffff); } // Finish up and send the sprites to the hardware hr=m_pSpriteObject->Flush(); hr=m_pSpriteObject->End(); DXUTGetD3D10Device()->OMSetBlendState(m_pBlendState10, OriginalBlendFactor, OriginalSampleMask); [/source] Note: I am checking all my Direct X calls. I have just removed them for clarity.
  15. Hi All, I have built a simple library which worked perfectly for 2D sprites. However when I ported this over to DXUT I am getting strange blending problems. At first everything seemed fine as the alpha channels for the sprites were transparent against the background, but when the sprites crossed each other the bounding box of the sprite became visible. See file attached. I have created the simplest piece of code I can to demonstrate how I am doing things. I have based this on EmptyProject10.cpp that is comes with the DirectX SDK: ..\MicrosoftDirectXSDKJune2010\Samples\C++\Direct3D10\EmptyProject10 within this there are only two callback functions that I use OnD3D10ResizedSwapChain() and OnD3D10FrameRender(). All the code and the variables are below. Any help would be greatly appreciated as I have been stuck on this for a long time. Edit: I have also just realised that the colours are washed out when I am using DXUT. I have read somewhere that this is related to DXUT using DXGI_FORMAT_R8G8B8A8_UNORM_SRGB. However I have already spent ages tinkering with either trying to get DXUT to use DXGI_FORMAT_R8G8B8A8_UNORM or to get my textures to be DXGI_FORMAT_R8G8B8A8_UNORM_SRGB. #define NUM_POOL_SPRITES 32 D3DX10_SPRITE spritePool[NUM_POOL_SPRITES]; ID3DX10Sprite *pSpriteObject = NULL; ID3D10ShaderResourceView *gSpriteTextureRV = NULL; #define MAX_SPRITES 4 // Sprite structure typedef struct { // sprite details float width; float height; // sprite position float posX; float posY; // sprite movement float moveX; float moveY; BOOL visible; }GameSprite2; GameSprite2 sprites[MAX_SPRITES] = {0}; // the number of active sprites int numActiveSprites = 0; HRESULT CALLBACK GameApplication::OnD3D10ResizedSwapChain( ID3D10Device* pd3dDevice, IDXGISwapChain* pSwapChain, const DXGI_SURFACE_DESC* pBackBufferSurfaceDesc, void* pUserContext ) { // create and set the viewport D3D10_VIEWPORT viewPort; viewPort.Width = DXUTGetWindowHeight(); viewPort.Height = DXUTGetWindowWidth(); viewPort.MinDepth = 0.0f; viewPort.MaxDepth = 1.0f; viewPort.TopLeftX = 0; viewPort.TopLeftY = 0; DXUTGetD3D10Device()->RSSetViewports(1, &viewPort); // Create the default projection matrix D3DXMatrixOrthoOffCenterLH(&matProjection, (float)viewPort.TopLeftX, (float)viewPort.Width, (float)viewPort.TopLeftY, (float)viewPort.Height, 0.1f, 10); ID3D10Texture2D* texture = NULL; ID3D10Resource* pRes = NULL; //HRESULT hr = D3DX10CreateTextureFromFile(DXUTGetD3D10Device(), TEXT("./brick.bmp"), NULL, NULL, &pRes, NULL); HRESULT hr = D3DX10CreateTextureFromFile(DXUTGetD3D10Device(), TEXT("./bitmaps/spheremapsmall.png"), NULL, NULL, &pRes, NULL); testHr("OnD3D10ResizedSwapChain:D3DX10CreateTextureFromFile",hr); // Translates the ID3D10Resource object into a ID3D10Texture2D object pRes->QueryInterface(__uuidof( ID3D10Texture2D ), (LPVOID*)&texture); pRes->Release(); if (texture == NULL) { CLogger::WriteInfoLog("failed to create texture"); return false; } // Get the texture details D3D10_TEXTURE2D_DESC desc; texture->GetDesc(&desc); // Create a shader resource view of the texture D3D10_SHADER_RESOURCE_VIEW_DESC SRVDesc; ZeroMemory(&SRVDesc, sizeof(SRVDesc)); SRVDesc.Format = desc.Format; SRVDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; SRVDesc.Texture2D.MipLevels = desc.MipLevels; hr=DXUTGetD3D10Device()->CreateShaderResourceView(texture, &SRVDesc, &gSpriteTextureRV); testHr("OnD3D10ResizedSwapChain:CreateShaderResourceView",hr); // release the texture texture->Release(); // Create the Sprite Batch, all sprite drawing is done through // this object hr = D3DX10CreateSprite(DXUTGetD3D10Device(), 0, &pSpriteObject); testHr("OnD3D10ResizedSwapChain:D3DX10CreateSprite",hr); // Initialize the blend state for alpha drawing D3D10_BLEND_DESC StateDesc; ZeroMemory(&StateDesc, sizeof(D3D10_BLEND_DESC)); StateDesc.AlphaToCoverageEnable = FALSE; StateDesc.BlendEnable[0] = TRUE; StateDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA; StateDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA; StateDesc.BlendOp = D3D10_BLEND_OP_ADD; StateDesc.SrcBlendAlpha = D3D10_BLEND_ZERO; StateDesc.DestBlendAlpha = D3D10_BLEND_ZERO; StateDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD; StateDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL; hr=DXUTGetD3D10Device()->CreateBlendState(&StateDesc, &pBlendState10); testHr("OnD3D10ResizedSwapChain:CreateBlendState",hr); // Loop through and set the defaults for the // sprites in the pool for (int i = 0; i < NUM_POOL_SPRITES; i++) { // Texture for this sprite to use spritePool.pTexture = gSpriteTextureRV; spritePool.TextureIndex = 0; // top-left location in U,V coords spritePool.TexCoord.x = 0; spritePool.TexCoord.y = 0; // Determine the texture size in U,V coords spritePool.TexSize.x = 1; spritePool.TexSize.y = 1; spritePool.ColorModulate = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f); } // Create a diagonal line of overlapping sprites for (int curSprite = 0; curSprite < MAX_SPRITES-1; curSprite++) { // Set the width and height of the sprite sprites[curSprite].width = 64.0f; sprites[curSprite].height = 64.0f; // position in a diagonal so you can see overlap sprites[curSprite].posX = 300+(curSprite*15); sprites[curSprite].posY = 100+(curSprite*15); sprites[curSprite].moveX = 0; sprites[curSprite].moveY = 0; // This sprite is visible sprites[curSprite].visible = TRUE; } //create a single sprite on its own sprites[MAX_SPRITES-1].width = 64.0f; sprites[MAX_SPRITES-1].height = 64.0f; sprites[MAX_SPRITES-1].posX = 100; sprites[MAX_SPRITES-1].posY = 100; sprites[MAX_SPRITES-1].visible = TRUE; D3DXMATRIX matScaling; D3DXMATRIX matTranslation; int curPoolIndex = 0; // Loop through the sprites for (int i = 0; i < MAX_SPRITES; i++) { // only update visible sprites if (sprites.visible) { CLogger::WriteInfoLog("OnFrameMove: moving sprites"); // set the proper scale for the sprite D3DXMatrixScaling(&matScaling, sprites.width, sprites.height, 1.0f); // Move the sprite to spritePosX, spritePosY // SpriteWidth and SpriteHeight are divided by 2 to move the // translation point to the top-left sprite corner instead of // the center of the sprite. D3DXMatrixTranslation(&matTranslation, (float)sprites.posX + (sprites.width/2), (float)(DXUTGetWindowHeight() - sprites.posY - (sprites.height/2)), 0.1f); // Update the sprites position and scale spritePool[curPoolIndex].matWorld = matScaling * matTranslation; // Increment the pool index curPoolIndex++; } } // set the number of active sprites numActiveSprites = curPoolIndex; return S_OK; } void CALLBACK GameApplication::OnD3D10FrameRender( ID3D10Device* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { float ClearColor[4] = { 0.176f, 0.196f, 0.667f, 0.0f }; pd3dDevice->ClearRenderTargetView( DXUTGetD3D10RenderTargetView(), ClearColor ); //pd3dDevice->ClearRenderTargetView( DXUTGetD3D10RenderTargetView(), D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f) ); pd3dDevice->ClearDepthStencilView( DXUTGetD3D10DepthStencilView(), D3D10_CLEAR_DEPTH, 1.0, 0 ); FLOAT OriginalBlendFactor[4]; UINT OriginalSampleMask = 0; if (DXUTGetD3D10Device() != NULL) { // clear the target buffer //pD3DDevice->ClearRenderTargetView(pRenderTargetView, D3DXCOLOR(0.0f, 0.0f, 0.0f, 0.0f)); if (pSpriteObject != NULL) { HRESULT hr = pSpriteObject->SetProjectionTransform(&matProjection); testHr("OnD3D10FrameRender:SetProjectionTransform",hr); // start drawing the sprites hr=pSpriteObject->Begin(D3DX10_SPRITE_SORT_TEXTURE); testHr("OnD3D10FrameRender:Begin",hr); // Draw all the sprites in the pool hr=pSpriteObject->DrawSpritesBuffered(spritePool, numActiveSprites); testHr("OnD3D10FrameRender:DrawSpritesBuffered",hr); // Save the current blend state DXUTGetD3D10Device()->OMGetBlendState(&pOriginalBlendState10, OriginalBlendFactor, &OriginalSampleMask); // Set the blend state for alpha drawing if(pBlendState10) { FLOAT NewBlendFactor[4] = {0,0,0,0}; DXUTGetD3D10Device()->OMSetBlendState(pBlendState10, NewBlendFactor, 0xffffffff); } // Finish up and send the sprites to the hardware hr=pSpriteObject->Flush(); testHr("OnD3D10FrameRender:Flush",hr); hr=pSpriteObject->End(); testHr("OnD3D10FrameRender:End",hr); } // Restore the previous blend state DXUTGetD3D10Device()->OMSetBlendState(pOriginalBlendState10, OriginalBlendFactor, OriginalSampleMask); } }
  16. benp444

    2D blending not work with DXUT

    Great! and the solution to the washed out colour is to create a new SRGB texture in memory (not from file), copy the non-SRGB texture (from file) into it and use that to create the texture resource. See method below. Now my balls are perfect! ID3D10Texture2D* GameManager::convertTextureToSRGB(ID3D10Texture2D* srcTexture){ if(srcTexture==NULL) { throw GameException(E_POINTER,"GameManager::convertTextureToSRGB: srcTexture was null"); } D3D10_TEXTURE2D_DESC origDesc; srcTexture->GetDesc(&origDesc); D3D10_TEXTURE2D_DESC srgbDesc; ZeroMemory( &srgbDesc, sizeof(srgbDesc)); srgbDesc.Width = origDesc.Width; srgbDesc.Height = origDesc.Height; srgbDesc.MipLevels = 1; srgbDesc.ArraySize = 1; srgbDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; srgbDesc.SampleDesc.Count = 1; srgbDesc.Usage = D3D10_USAGE_DYNAMIC; srgbDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE; srgbDesc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE; ID3D10Texture2D *pSRGBTexture = NULL; HRESULT hr=DXUTGetD3D10Device()->CreateTexture2D( &srgbDesc, NULL, &pSRGBTexture ); testHr("CreateTexture2D:CreateTexture2D",hr); //copy the original texture in the into the SRGB texture D3D10_BOX sourceRegion; sourceRegion.left = 0; sourceRegion.right = origDesc.Width; sourceRegion.top = 0; sourceRegion.bottom = origDesc.Height; sourceRegion.front = 0; sourceRegion.back = 1; DXUTGetD3D10Device()->CopySubresourceRegion(pSRGBTexture, 0, 0, 0, 0, srcTexture, 0,&sourceRegion); return pSRGBTexture; }
  17. benp444

    2D blending not work with DXUT

    Thanks Niko for your help. I have disabled the depth and the the bounding boxes are no longer visible. To fix the issue I have added the following code to the OnD3D10ResizedSwapChain() method: //START NEW CODE D3D10_DEPTH_STENCIL_DESC depthDisabledStencilDesc; ZeroMemory(&depthDisabledStencilDesc, sizeof(depthDisabledStencilDesc)); depthDisabledStencilDesc.DepthEnable = false; depthDisabledStencilDesc.DepthWriteMask = D3D10_DEPTH_WRITE_MASK_ALL; depthDisabledStencilDesc.DepthFunc = D3D10_COMPARISON_LESS; depthDisabledStencilDesc.StencilEnable = true; depthDisabledStencilDesc.StencilReadMask = 0xFF; depthDisabledStencilDesc.StencilWriteMask = 0xFF; depthDisabledStencilDesc.FrontFace.StencilFailOp = D3D10_STENCIL_OP_KEEP; depthDisabledStencilDesc.FrontFace.StencilDepthFailOp = D3D10_STENCIL_OP_INCR; depthDisabledStencilDesc.FrontFace.StencilPassOp = D3D10_STENCIL_OP_KEEP; depthDisabledStencilDesc.FrontFace.StencilFunc = D3D10_COMPARISON_ALWAYS; depthDisabledStencilDesc.BackFace.StencilFailOp = D3D10_STENCIL_OP_KEEP; depthDisabledStencilDesc.BackFace.StencilDepthFailOp = D3D10_STENCIL_OP_DECR; depthDisabledStencilDesc.BackFace.StencilPassOp = D3D10_STENCIL_OP_KEEP; depthDisabledStencilDesc.BackFace.StencilFunc = D3D10_COMPARISON_ALWAYS; hr = DXUTGetD3D10Device()->CreateDepthStencilState(&depthDisabledStencilDesc, &g_pDepthDisabledStencilState); DXUTGetD3D10Device()->OMSetDepthStencilState(g_pDepthDisabledStencilState, 1); testHr("CreateDepthStencilState",hr); //END NEW CODE The colours are still washed out, but this is a separate issue may raise seperately. Cheers, Ben.
  18. benp444

    2D blending not work with DXUT

    Thanks for your response. I changed the code above from hr=pSpriteObject->Begin(D3DX10_SPRITE_SORT_TEXTURE); to hr=pSpriteObject->Begin(D3DX10_SPRITE_SORT_DEPTH_BACK_TO_FRONT); However this hasn't changed the result in any way. I still get the image attached to the OP. Is there something else I need to be doing?
  19. I have been scouring this board and the rest of the internet for a few days now trying to get per-pixed collision detection working in DirectX 10. but without success. My starting point was this post here: http://www.gamedev.n...ks-directx-9-c/ However the problems is that I am using DX 10 (D3D10) not 9 so e.g. pTexture->LockRect doesn't work. I read that I need to use ID3D10Texture2D::Map instead. I ran into all sorts of issues with calling this could not call it without getting E_INVALIDARG. The internet suggested that I hadn't called the upstream function D3DX10CreateTextureFromFile() correctly and I started playing around with the D3DX10_IMAGE_LOAD_INFO with a number of different permuatations but again all to no avail. This function always told me D3DERR_INVALIDCALL if I tried to call it. Now before I start talking about my code I want to go back to my initial requirement and check that I am using the right approach. Basically I want to be able to test if parts of a sprite are overlapping parts of another sprite based on the non-alpha channels. I know that there are more peformant ways of collision detection but please humour me. So question A) is: A) What is the high level approach to doing per-pixel sprite collision detection in Direct X 10. Any assistance would be greatly appreciated.
  20. Its been 12 years since I programmed c++ so I am a bit rusty. I am not sure that I am using the debugging tools correctly anyhow I now link to d3dx10d.lib. And I have set the configuration to debug in numerous locations in VS Express 2010. I click the little green 'play' button and when it hits my exception I have a look at the debugger window. The only additional line is First-chance exception at 0x7510b9bc in DXSpriteWrapper.exe: Microsoft C++ exception: GameException at memory location 0x0043e7d0.. This is the line caused by the exception that I have built and thrown due to the D3DERR_INVALIDCALL error I mentioned previously. I could not see any other information that might help me. It does not seem to go into the D3DX10CreateTextureFromFile method and report anything useful. This is what my creation of the pD3DDevice looks like: HRESULT hr = D3D10CreateDeviceAndSwapChain(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, D3D10_CREATE_DEVICE_DEBUG, D3D10_SDK_VERSION, &swapChainDesc, &pSwapChain, &pD3DDevice);
  21. OK, I think I understand. My problem then becomes the fact that I cannot call D3DX10CreateTextureFromFile and specify a D3DX10_IMAGE_LOAD_INFO. See code below: // This is valid - if I call D3DX10CreateTextureFromFile without the D3DX10_IMAGE_LOAD_INFO param (i.e. passing null) then my sprites bounce around the screen. ID3D10Device* pD3DDevice=GameManager::get_instance().getD3DDevice(); D3DX10_IMAGE_LOAD_INFO loadInfo; ZeroMemory(&loadInfo,sizeof(D3DX10_IMAGE_LOAD_INFO)); // I have played around with a number of permutations of this. Sometimes using default settings or simply not specifiying a particular D3DX10_IMAGE_LOAD_INFO field //loadInfo.Width = 300; //loadInfo.Height = 300; loadInfo.Depth = D3DX10_DEFAULT; loadInfo.BindFlags = 0; loadInfo.pSrcInfo = NULL; loadInfo.CpuAccessFlags = D3D10_CPU_ACCESS_READ; loadInfo.MiscFlags = 0; loadInfo.Filter = D3DX10_FILTER_NONE; loadInfo.MipFilter = D3DX10_FILTER_NONE; loadInfo.FirstMipLevel = D3DX10_DEFAULT; loadInfo.Usage = D3D10_USAGE_STAGING; loadInfo.MipLevels = D3DX10_DEFAULT; // Loads the texture into a temporary ID3D10Resource object. filename.c_str() is valid. hr = D3DX10CreateTextureFromFile(pD3DDevice, filename.c_str(), &loadInfo, NULL, &pRes, NULL); // I then check hr The above code always results in D3DERR_INVALIDCALL the descriptions of which is "Invalid call". If I make the call using: hr = D3DX10CreateTextureFromFile(pD3DDevice, filename.c_str(),NULL , NULL, &pRes, NULL); Then everything works, but I cannot then call the ID3D10Texture2D::Map function later. Can anyone see anything wrong with my D3DX10CreateTextureFromFile call? Addtionally this is the image I am using, but the same problem occurs on any image I try and use: http://www.axialis.com/tutorials/sample/logo-ps.png
  • 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!