• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

chowarth

Members
  • Content count

    15
  • Joined

  • Last visited

Community Reputation

516 Good

About chowarth

  • Rank
    Member

Personal Information

  • Location
    England
  1. From an initial glance at the code you listed you are not setting up the base class that the sprite derives from (or have neglected to include it in the code snippet), so don't shoot me if this is wrong I'm only going off what I can see from the sample code provided.   If the base class is supposed to have a ID3DDevice* m_pDevice3D then you need to ensure that this pointer actually points to the ID3DDevice that you initialised within the Graphics class, otherwise you'll end up with an invalid pointer.   So, you need to pass a pointer to the ID3DDevice over when creating the Sprite object so that you can then instantiate the base class properly.   For example: Sprite::Sprite(     ID3DDevice* pDevice,     std::string            File,     RECT                   SrcRect,     D3DXVECTOR3            Pos,     D3DXVECTOR3            Rot,     int                    Width,     int                    Height,     int                    MoveX,     int                    MoveY,     D3DCOLOR               Color) : BaseClass( pDevice ) { // ...... excluded ...... }
  2.       Two very good points that I had missed, thanks :)
  3. I used the same guide myself when creating mine. Here's my version of getting a string value, if it helps: string CConfig::ReadStringValue( const char* section, const char* key, const char* defaultVal ) { char* temp = new char[255]; GetPrivateProfileString( section, key, defaultVal, temp, 255, mFilename ); string value = temp; delete temp; return value; } But as BitMaster has already said, it would be better if you correct your project settings if you want to use the multi-byte version of GetPrivateProfileString.
  4. I've been trying to implement sprites and read through the RasterTek tutorial on rendering sprites. I got everything working fine but I didn't like the idea of using dynamic vertex buffers to make it possible to move a sprite, so I went about changing them to use a matrix instead.   I have come across a little problem with sprite positions.   I create a few sprites like so: mpScene->AddSprite( "TestSprite1", "alpha.png", 0,    0,    100,    100 ); mpScene->AddSprite( "TestSprite2", "alpha.png", 100,    0,    100,    100 ); mpScene->AddSprite( "TestSprite3", "alpha.png", 0,      100,    100,    100 );   Now my assumption is that if I create a sprite at (0, 0) with dimensions of (100, 100), and then create another at (100, 0) with the same dimensions that the two sprites would be right next to each other, however they seem to be the full width of a sprite apart:       This is how I create my sprite buffers: // Calculate screen space positions of the vertices float left        = ( ( screenWidth * 0.5f ) * -1 ) + posX; float right        = left + width; float top        = ( screenHeight * 0.5f ) + posY; float bottom    = top - height; // Populate vertices. vertices[0].Pos = XMFLOAT3( left, top, 1.0f ); vertices[0].Tex = XMFLOAT2( 0.0f, 0.0f ); vertices[1].Pos = XMFLOAT3( right, top, 1.0f ); vertices[1].Tex = XMFLOAT2( 1.0f, 0.0f ); vertices[2].Pos = XMFLOAT3( right, bottom, 1.0f ); vertices[2].Tex = XMFLOAT2( 1.0f, 1.0f ); vertices[3].Pos = XMFLOAT3( left, bottom, 1.0f ); vertices[3].Tex = XMFLOAT2( 0.0f, 1.0f ); // Create indices array. indices = new USHORT[numIndices]; indices[0] = 0;    // indices[1] = 1;    // Triangle 1 indices[2] = 2;    //___________ indices[3] = 0;    // indices[4] = 2;    // Triangle 2 indices[5] = 3;    //   and how I create the sprite matrix: XMMATRIX p    = XMMatrixTranslation( mPosition.x, mPosition.y, mPosition.z ); XMMATRIX r    = XMMatrixRotationZ( mRotation ); XMMATRIX s    = XMMatrixScaling( mScale.x, mScale.y, 1.0f ); XMStoreFloat4x4( &mMatrix, p * r * s );     and the rendering of the sprites: // Disable depth testing when drawing sprite objects. pDevice->SetDepthStencilState( mpDepthDisabledState ); mpSpriteFX->SetMatrix( "gViewProjMatrix", pCamera->GetOrthoMatrix() ); pDevice->SetInputLayout( mpSpriteFX->GetInputLayout() ); CSprite* pSprite = NULL; pSpriteList->BeginEnumeration(); while( ( pSprite = pSpriteList->EnumAsset() ) != 0 ) {     CTexture* pTexture = pTextureList->GetAsset( pSprite->GetTextureUID() );     mpSpriteFX->SetSRV( "dTexture", pTexture->GetSRV() );     pDevice->SetVertexIndexBuffer( sizeof( SpriteVertex ), pSprite->GetVB(), pSprite->GetIB() );     mpSpriteFX->SetMatrix( "gWorldMatrix", pSprite->GetMatrix() );     UINT numPasses = mpSpriteFX->GetNumPasses();     for( UINT pass = 0; pass < numPasses; pass++ )     {         pDevice->ApplyTechPass( mpSpriteFX->GetTechnique(), pass );         pDevice->DrawIndexed( mNumIndices, 0, 0 );     } } pSpriteList->EndEnumeration();      // Re-enable depth testing for drawing non-sprite objects. pDevice->SetDepthStencilState( NULL );   I'm just wondering if there's something I've done wrong or an explanation as to why the sprites would be positioned the full width of a sprite apart instead of next to each other as I would expect.   Thanks in advance.   Edit: Appears the image wasn't working :( Fixed (I hope).
  5. One instant thing that stands out is that in your pixel shader, you only have one Texture2D defined. If you want to use two textures in the shader then you'll need two Texture2D variables. Following on from this, as you only have one texture, you're only sampling from one texture. If you want a combination of the two textures to be on your mesh, you'll need to blend between the two colours sampled from the two different textures you passed over. Can't think of anything else at the mo, just a quick post while at work ;)
  6. I'm not sure if this is going to be close or not. I'm taking a stab in the dark. If you have already created the menu and got it showing, before adding DirectX then: I remember when I added a status bar to my window for my DirectX11 app I had the problem where when rendering that the status bar was not visible. I found out that when creating your window, you need to specify the flag: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx"]WS_CLIPCHILDREN[/url], which excludes the area occupied by child windows when drawing occurs within the parent window. Hope this is relevant, as you've not given much detail about how you created your window.
  7. I believe the window style might be what is giving the window this appearance. When the CreateWindowEx is called the window style WS_POPUP is given. That gives the window a borderless (including title - so minimize/maximize & close) look. You could try changing it to something like WS_OVERLAPPED. For more info on the window styles: http://msdn.microsoft.com/en-us/library/windows/desktop/ms632600(v=vs.85).aspx
  8. If you're not that clued up/comfortable with DirectX in general I suppose a good place to start would be a combination of: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb219837(v=vs.85).aspx"]http://msdn.microsoft.com/en-us/library/windows/desktop/bb219837(v=vs.85).asp[/url][url="http://www.directxtutorial.com/Tutorial9/tutorials.aspx"]x[/url] & [url="http://www.directxtutorial.com/Tutorial9/tutorials.aspx"]http://www.directxtutorial.com/Tutorial9/tutorials.aspx[/url] If you're at least comfortable with using DirectX then I can suggest: [url="http://www.catalinzima.com/tutorials/deferred-rendering-in-xna/"]http://www.catalinzima.com/tutorials/deferred-rendering-in-xna/[/url] I know this is specifically in XNA, but as you will find, there's not that all of a difference between XNA & DX9. I used this as a guide when doing a deferred renderer myself although in DX10 and found it exceptionally helpful.
  9. The break occurs on the DrawIndexed line when rendering the terrain grid mesh: [code] void CGridMesh::Draw() { g_pd3dDevice->IASetInputLayout( m_VertexLayout ); g_pd3dDevice->IASetPrimitiveTopology( D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST ); UINT stride = sizeof( SGridVertex ); UINT offset = 0; g_pd3dDevice->IASetVertexBuffers( 0, 1, &m_VertexBuffer, &stride, &offset ); g_pd3dDevice->IASetIndexBuffer( m_IndexBuffer, DXGI_FORMAT_R32_UINT, 0 ); g_pd3dDevice->DrawIndexed( m_nFaces*3, 0, 0 ); } [/code]
  10. Yup, I set the texture in slot 2 to NULL right before I change the viewport and render target.
  11. Essentially Im trying to just render a heightmapped terrain, clipping everything above WorldPos.y, for the refraction map. This appears to be fine for the first frame, then on the second it dies. Setting the textures: [code] SetTexture( 0, m_CubeMapSRV ); SetTexture( 1, m_DepthMapSRV ); SetTexture( 2, m_RefracMapSRV );[/code] Corresponding shader textures: [code]TextureCube CubeMap; Texture2D ShadowMap; Texture2D RefractionMap;[/code]
  12. I'm having a bit of a problem trying to setup a render target in order to be able to create a refraction map. I'm getting this error, and I cant narrow it down to any particular piece of code myself: [code]D3D10: ERROR: ID3D10Device::DrawIndexed: The view dimension declared in the shader code does not match the view type bound to slot 0 of the Pixel Shader unit. This is invalid if the shader actually uses the view (e.g. it is not skipped due to shader code branching). [ EXECUTION ERROR #354: DEVICE_DRAW_VIEW_DIMENSION_MISMATCH ][/code] Here is the resource creation: [code] //** Depth stencil D3D10_TEXTURE2D_DESC TEXdesc; TEXdesc.Width = REFRACMAP_SIZE; TEXdesc.Height = REFRACMAP_SIZE; TEXdesc.MipLevels = 1; TEXdesc.ArraySize = 1; TEXdesc.SampleDesc.Count = 1; TEXdesc.SampleDesc.Quality = 0; TEXdesc.Format = DXGI_FORMAT_D32_FLOAT; TEXdesc.Usage = D3D10_USAGE_DEFAULT; TEXdesc.BindFlags = D3D10_BIND_DEPTH_STENCIL; TEXdesc.CPUAccessFlags = 0; TEXdesc.MiscFlags = 0; if( FAILED( g_pd3dDevice->CreateTexture2D( &TEXdesc, NULL, &m_RefracMapDepth ) ) ) { return false; } //** Depth stencil view D3D10_DEPTH_STENCIL_VIEW_DESC DSVdesc; DSVdesc.Format = TEXdesc.Format; DSVdesc.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D; DSVdesc.Texture2D.MipSlice = 0; if( FAILED( g_pd3dDevice->CreateDepthStencilView( m_RefracMapDepth, &DSVdesc, &m_RefracMapDSV ) ) ) { return false; } //** Render target view TEXdesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; TEXdesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; if( FAILED( g_pd3dDevice->CreateTexture2D( &TEXdesc, NULL, &m_RefracMapTexture ) ) ) { return false; } D3D10_RENDER_TARGET_VIEW_DESC RTVdesc; RTVdesc.Format = TEXdesc.Format; RTVdesc.ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D; RTVdesc.Texture2D.MipSlice = 0; if( FAILED( g_pd3dDevice->CreateRenderTargetView( m_RefracMapTexture, &RTVdesc, &m_RefracMapRTV ) ) ) { return false; } //** Shader resource view D3D10_SHADER_RESOURCE_VIEW_DESC SRVdesc; SRVdesc.Format = TEXdesc.Format; SRVdesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D; SRVdesc.Texture2D.MipLevels = 1; SRVdesc.Texture2D.MostDetailedMip = 0; if( FAILED( g_pd3dDevice->CreateShaderResourceView( m_RefracMapTexture, &SRVdesc, &m_RefracMapSRV ) ) ) { return false; }[/code] And setting the render target: [code] D3D10_VIEWPORT newVP; newVP.Width = REFRACMAP_SIZE; newVP.Height = REFRACMAP_SIZE; newVP.MinDepth = 0; newVP.MaxDepth = 1; newVP.TopLeftX = 0; newVP.TopLeftY = 0; g_pd3dDevice->RSSetViewports( 1, &newVP ); float clearColour[4] = { 0.0f, 0.0f, 0.0f, 0.0f }; g_pd3dDevice->ClearRenderTargetView( m_RefracMapRTV, clearColour ); g_pd3dDevice->ClearDepthStencilView( m_RefracMapDSV, D3D10_CLEAR_DEPTH, 1.0f, 0 ); g_pd3dDevice->OMSetRenderTargets( 1, &m_RefracMapRTV, m_RefracMapDSV );[/code]
  13. Got it all working now, it appears the problem was caused by the: float3 LightDir, changed it to a float4 and it works perfectly. Thank you for the earlier pointers, all helped.
  14. Thanks for the pointers. Ok I decided to simplify this all a bit, removed one of the lights and added Light1Dir to the constant buffer, which gets sent in and is set to (0.5f, -0.5f, 0.5f ), but now I'm getting no light at all. /********************************************** DirLight.psh Test file for a directional light ***********************************************/ //----------------------------------------------------------------------------- // Global variables //----------------------------------------------------------------------------- cbuffer cb0 { // Current lighting information - ambient + two point lights float4 AmbientColour; float4 Light1Position; // Point light 1 - position float4 Light1Colour; // Point light 1 - colour float Light1Brightness; // Point light 1 - brightness float3 Light1Dir; // Shininess of material and camera position needed for specular calculation float4 CameraPosition; float SpecularPower; }; // Access to texture 0 Texture2D Texture; SamplerState MeshTextureSampler; //----------------------------------------------------------------------------- // Input / output structures //----------------------------------------------------------------------------- struct PS_Input { float4 Position : SV_Position; // New semantics for DX10 - pixel position from vertex shader - not used in DX9 float2 TexCoord0 : TEXCOORD0; float3 WorldPosition : TEXCOORD1; // The world position of the pixel float3 WorldNormal : TEXCOORD2; // The world normal of the pixel }; struct PS_Output { float4 Colour : SV_Target; // New semantics for DX10 - output to render target -replaces COLOR semantic in DX9 }; //----------------------------------------------------------------------------- // Main function //----------------------------------------------------------------------------- void main( in PS_Input i, out PS_Output o ) { // Renormalise world normal for the pixel as it has been interpolated from the vertex world normals & may not be length 1 float3 WorldNormal = normalize( i.WorldNormal ); // Lighting preparation // Get normalised vector to camera for specular equation (common for all lights) float3 CameraDir = normalize( CameraPosition - i.WorldPosition ); // Accumulate diffuse and specular colour effect from each light float3 TotalDiffuseColour = AmbientColour; float3 TotalSpecularColour = 0; // First light - Point light // Calculate diffuse lighting from the 1st light. Standard equation: Diffuse = light colour * max(0, N.L) //float3 LightDir = Light1Position - i.WorldPosition; float3 LightDir = Light1Dir; //float LightDist = length( LightDir ); //float LightStrength = saturate( Light1Brightness / LightDist ); //LightDir /= LightDist; float diffuseFactor = dot( LightDir, WorldNormal ); if( diffuseFactor > 0.0f ) { float3 DiffuseColour = /*LightStrength * */ Light1Colour * saturate( dot( WorldNormal, LightDir ) ); TotalDiffuseColour += DiffuseColour; // Calculate specular lighting from the 1st light. Standard equation: Specular = light colour * max(0, (N.H)^p) // Slight tweak here: multiply by diffuse colour rather than light colour float3 Halfway = normalize( CameraDir + LightDir ); TotalSpecularColour += DiffuseColour * saturate( pow( dot( WorldNormal, Halfway ), SpecularPower ) ); } // Final blending // Combine lighting colours with texture - alpha channel of texture is a specular map float4 TextureColour = Texture.Sample( MeshTextureSampler, i.TexCoord0 ); o.Colour.rgb = TotalDiffuseColour * TextureColour.rgb + TotalSpecularColour * TextureColour.a; // Set alpha blending to 1 (no alpha available in texture) o.Colour.a = 1.0f; } Sorry if this is sounding a little stupid, but I'm trying get to grips with it all. [Edited by - chowarth on September 24, 2010 12:52:19 PM]
  15. Trying to change one of my lights from a point light to a directional light and getting a little stuck. Wondering if anyone can shed a little light (pardon the pun ^^) into where I'm going wrong. Thanks cbuffer cb0 { // Current lighting information - ambient + two point lights float4 AmbientColour; float4 Light1Position; // Point light 1 - position float4 Light1Colour; // Point light 1 - colour float Light1Brightness; // Point light 1 - brightness float4 Light2Position; // light 2... float4 Light2Colour; float Light2Brightness; // Shininess of material and camera position needed for specular calculation float4 CameraPosition; float SpecularPower; }; // Access to texture 0 Texture2D Texture; SamplerState MeshTextureSampler; //----------------------------------------------------------------------------- // Input / output structures //----------------------------------------------------------------------------- struct PS_Input { float4 Position : SV_Position; // New semantics for DX10 - pixel position from vertex shader - not used in DX9 float2 TexCoord0 : TEXCOORD0; float3 WorldPosition : TEXCOORD1; // The world position of the pixel float3 WorldNormal : TEXCOORD2; // The world normal of the pixel }; struct PS_Output { float4 Colour : SV_Target; // New semantics for DX10 - output to render target -replaces COLOR semantic in DX9 }; //----------------------------------------------------------------------------- // Main function //----------------------------------------------------------------------------- void main( in PS_Input i, out PS_Output o ) { // Renormalise world normal for the pixel as it has been interpolated from the vertex world normals & may not be length 1 float3 WorldNormal = normalize( i.WorldNormal ); // Lighting preparation // Get normalised vector to camera for specular equation (common for all lights) float3 CameraDir = normalize( CameraPosition - i.WorldPosition ); // Accumulate diffuse and specular colour effect from each light float3 TotalDiffuseColour = AmbientColour; float3 TotalSpecularColour = 0; //Light 1 - Point Light // Calculate diffuse lighting from the 1st light. Standard equation: Diffuse = light colour * max(0, N.L) float3 LightDir = Light1Position - i.WorldPosition; float LightDist = length( LightDir ); float LightStrength = saturate( Light1Brightness / LightDist ); LightDir /= LightDist; float3 DiffuseColour = LightStrength * Light1Colour * saturate( dot( WorldNormal, LightDir ) ); TotalDiffuseColour += DiffuseColour; // Calculate specular lighting from the 1st light. Standard equation: Specular = light colour * max(0, (N.H)^p) // Slight tweak here: multiply by diffuse colour rather than light colour float3 Halfway = normalize( CameraDir + LightDir ); TotalSpecularColour += DiffuseColour * saturate( pow( dot( WorldNormal, Halfway ), SpecularPower ) ); // Second light - Directional light // Calculate diffuse lighting from the 2nd light LightDir = Light2Position - i.WorldPosition; LightDist = length( LightDir ); LightStrength = saturate( Light2Brightness / LightDist ); LightDir /= LightDist; //Check if the pixel is in line of sight of the light float diffuseFactor = dot( -LightDir, WorldNormal ); if( diffuseFactor > 0.0f ) { DiffuseColour = LightStrength * Light2Colour * saturate( dot( WorldNormal, LightDir ) ); TotalDiffuseColour += DiffuseColour; // Calculate specular lighting from the 2nd light Halfway = normalize( CameraDir + LightDir ); TotalSpecularColour += DiffuseColour * saturate( pow( dot( WorldNormal, Halfway ), SpecularPower ) ); } // Final blending // Combine lighting colours with texture - alpha channel of texture is a specular map float4 TextureColour = Texture.Sample( MeshTextureSampler, i.TexCoord0 ); o.Colour.rgb = TotalDiffuseColour * TextureColour.rgb + TotalSpecularColour * TextureColour.a; // Set alpha blending to 1 (no alpha available in texture) o.Colour.a = 1.0f; }