Advertisement Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

154 Neutral

About standby01

  • Rank
  1. standby01

    D3DX Font object in C++

    // Create a font array LPD3DXFONT lpD3DXfont[MAX_FONTS] = {NULL}; // then you can create up to MAX_FONTS you like. for (UINT i = 0; i < MAX_FONTS; i++) { D3DXCreateFont(m_pd3dDevice, nHeight, 0, nWeight, 1, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, strFace, &lpD3DXfont ) ); } Error handling omitted.
  2. standby01

    Directx General Questions

    I agree with Starnik, DirectX is a general Grapgics framework, you can use it to develop a game for sure, but you need to manage many issues yourself. XNA is a C# game studio based on DirectX, it is much easier to use for game programming, actually XBox360 and Windows Phone 7 games are developed with it. Here is its official web site. You also can get help from its forum. [Edited by - standby01 on January 4, 2011 6:58:43 PM]
  3. standby01

    D3D11 and font / text

    1) ID3DXFont is still a simple way to use. 2) If you don't like to use it, you can use DXGI/GDI interop feature supported by D3D10.1 and above. Here is a simplified sample code, error handlings ommited. DXGI_SWAP_CHAIN_DESC swapChainDesc; // Specify the swap chain properties. ZeroMemory(&swapChainDesc, sizeof(swapChainDesc)); swapChainDesc.BufferDesc.Width = m_uiTextureWidth; swapChainDesc.BufferDesc.Height = m_uiTextureHeight; swapChainDesc.Windowed = bSCWindowed; swapChainDesc.Flags |= (bSCWindowed? uiSCFlags: DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH | uiSCFlags); swapChainDesc.SampleDesc.Count = uiSCSampleCount; swapChainDesc.SampleDesc.Quality = 0; swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; swapChainDesc.BufferCount = MAX_BUFFER_COUNT; swapChainDesc.OutputWindow = m_hTestWindow; swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL; swapChainDesc.BufferDesc.RefreshRate.Numerator = 0; swapChainDesc.BufferDesc.RefreshRate.Denominator = 1; swapChainDesc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; swapChainDesc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; // Define GDI compatible swaochain swapChainDesc.BufferDesc.Format = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE; Creating swapchain ... // Use GDI to write text out IDXGISurface1 *m_pTexture2DSurface1 = NULL; ID3DTexture2D *m_pTexture2D = NULL; HDC hDC = NULL; RECT nRect = {0, 0, 0, 0}; hrResult = m_pSwapChain->GetBuffer(uiBufferIndex, IID_ID3D10Texture2D, (void**)&m_pTexture2D); hrResult = m_pTexture2D->QueryInterface(__uuidof(IDXGISurface1), (void **)(&m_pTexture2DSurface1)); hrResult = m_pTexture2DSurface1->GetDC(FALSE, &m_hDC); hFont = CreateFont(16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, _T("Times New Roman")); hOldFont = (HFONT)SelectObject(m_hDC, hFont); TextOut(m_hDC, x1, y1, _T("This is a test application, Tomes New Roman font"), 48)) hrResult = m_pTexture2DSurface1->ReleaseDC(&nRect); do D3D rendering ... you must call OMSetRenderTargets() each time after you call GetDC/ReleaseDC(), or you will get an error. 3) you also can use D3D and D2D/DirectWrite interop if you need some of special/fancy fonts and effects. [Edited by - standby01 on January 4, 2011 6:40:36 PM]
  4. in _d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 40, 100), 1.0f, 0); you use D3DCOLOR_XRGB(0, 40, 100) to clean your back buffer. Th is color is not black. try D3DCOLOR_XRGB(0, 0, 0) to see what happened.
  5. For better efficiency and performance usually you need to process WM_SIZE messages when window mode toggled from windowed mode to full screen mode, and from full screen mode to windowed mode. you can simply post ALT+ENTER message again to take advantage of this part of code. [Edited by - standby01 on December 30, 2010 2:05:43 PM]
  6. standby01

    D3DRS_CULLMODE Not Really Working

    Yes, culling is designed for this purpose. In MSDN, it is indicated "To improve rendering performance, you can cull out (or remove) a primitive that faces away from the camera. For single-sided primitives, this saves rendering time because a back-face is not visible. To enable culling, you need to know the winding order of the vertices (typically counter-clockwise)". The code below will remove any primitive whose back face is facing forward (given a counter-clockwise winding order): SetRenderState(D3DRS_CULLMODE, D3DCULL_CCW);
  7. I don't see something wrong in the code you provided. Because I can't see complete source code and fx file, it is difficult to tell what is wrong. Here I give you some suggestions to help you figure it out. 1. Check if you defined at least one Technique and one Pass in your fx file? ================================================================= In a fx file, not only does it contain some constant buffers, shaders, but also need at least one Technique and One pass like this //============================================================================= // color.fx by Frank Luna (C) 2008 All Rights Reserved. // // Transforms and colors geometry. //============================================================================= cbuffer cbPerObject { float4x4 gWVP; }; void VS(float3 iPosL : POSITION, float4 iColor : COLOR, out float4 oPosH : SV_POSITION, out float4 oColor : COLOR) { // Transform to homogeneous clip space. oPosH = mul(float4(iPosL, 1.0f), gWVP); // Just pass vertex color into the pixel shader. oColor = iColor; } float4 PS(float4 posH : SV_POSITION, float4 color : COLOR) : SV_Target { return color; } technique10 ColorTech { pass P0 { SetVertexShader( CompileShader( vs_4_0, VS() ) ); SetGeometryShader( NULL ); SetPixelShader( CompileShader( ps_4_0, PS() ) ); } } 2. Check if you called ID3D10EffectPass::Apply(0) method? ================================================================= This method updates the constant buffers stored in GPU memory, binding the shader programs to the pipeline, and applies any render states the pass sets. Here is some code to explain this, and error hadling code omitted. // set constants ID3D10EffectTechnique* pTech = NULL; pTech = Effect->GetTechniqueByName("YourTechniqueName"); D3D10_TECHNIQUE_DESC techDesc; pTech->GetDesc( &techDesc ); for(UINT p = 0; p < techDesc.Passes; ++p) { D3DXVECTOR4 v( .969f, .765f, .605f, 1.f ); pShader->CustomColors.ptr10->SetFloatVector( (float*)&v ); pTech->GetPassByIndex( p )->Apply(0); ... } [Edited by - standby01 on October 1, 2010 12:03:34 AM]
  8. standby01

    Input Layout Question

    I agree with Demirug. D3D10 and above enhanced Vertext validation. Each input-layout object is created based on a shader signature; this allows the API to validate the input-layout-object elements against the shader-input signature to make sure that there is an exact match of types and semantics. You can create a single input-layout object for many shaders, as long as all of the shader-input SIGNATURES EXACTLY MATCH. In CascadedShadowMaps11 there are two places Input-Layout Objects are created. one is for g_strUIEffectFile(line 628 to 639, DXUTgui.cpp), and the other is for RenderCascadeScene.hlsl(line 233 to 244, CascadedShadowsManager.cpp), while the vertex shader defined in RenderCascadeShadow.hlsl doesn't create primitives, so no D3D11_INPUT_ELEMENT_DESC struct and Input-Layout Object created for it.
  9. It is interesting. It looks like at the original place, the triangle is masked out, and it is displayed(shrunk greatly at the postion circled.
  10. standby01

    render states per target

    IDirect3DDevice9::SetRenderState Method Sets a single device render-state parameter. Syntax CopyHRESULT SetRenderState( [in] D3DRENDERSTATETYPE State, [in] DWORD Value ); Its impact scope is whole device. so I think what you can try is to call SetRenderState before rendering to each render target, i.e. call SetRenderState in your rendering function called periodically. [Edited by - standby01 on September 11, 2010 7:04:02 PM]
  11. standby01

    fullscreen + dual monitor crash

    After a latest driver installed, the bug was not gone. A bug will be filed against AMD. [Edited by - standby01 on September 10, 2010 3:02:17 PM]
  12. standby01

    Fullscreen on Windows 7 with dual monitor

    I'm from Microsoft Graphcs team. If you don't mind sendimg me your source code, or telling me exact steps to reproduce it. I'll have it investigated. If you're interested to know the root cause as I, please contact me at Thanks.
  13. SetViewPort has nothing to do with ShowWindow(). You didn't provide your complete source code, it is difficult to guess what is wrong. Here are some suggestions. 1. Viewport structure for backbuffer, the coordinates for left-top corner of whole backbuffer should be [0, 0], i.e. D3DVIEWPORT9 vp; vp.X = 0; vp.Y = 0; which could be different from viewport structure got from FrontBuffer. 2. SetViewPort must be called after SetRenderTarget, e.g. hr = pd3dDevice->SetRenderTarget( m_pTextureSurface ); ... hr = pd3dDevice->SetViewport( &viewport ); 3. You can use pd3dDevice->GetViewport( &g_ViewportFB ) to get the view port for the front buffer, then set X and Y of the left view port structure for backbuffer to [0, 0]. like this pd3dDevice->GetViewport( &g_ViewportFB ); // Backbuffer viewport is identical to frontbuffer, except starting at 0, 0 g_ViewportOffscreen = g_ViewportFB; g_ViewportOffscreen.X = 0; g_ViewportOffscreen.Y = 0; width divided by 2. You can set and rendering to the left view port first then the right view port. Here is a sample code render to one view port from DirectX SDK 02/2010 for your reference. //-------------------------------------------------------------------------------------- // Render the scene using the D3D9 device //-------------------------------------------------------------------------------------- void CALLBACK OnFrameRender( IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime, void* pUserContext ) { // If the settings dialog is being shown, then // render it instead of rendering the app's scene if( g_SettingsDlg.IsActive() ) { g_SettingsDlg.OnRender( fElapsedTime ); return; } HRESULT hr; UINT iPass, cPasses; // First render the world on the rendertarget g_pFullScreenTexture. if( SUCCEEDED( g_pRenderToSurface->BeginScene( g_pFullScreenTextureSurf, &g_ViewportOffscreen ) ) ) { V( pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, g_dwBackgroundColor, 1.0f, 0 ) ); // Get the view & projection matrix from camera D3DXMATRIXA16 matWorld; D3DXMATRIXA16 matView = *g_Camera.GetViewMatrix(); D3DXMATRIXA16 matProj = *g_Camera.GetProjMatrix(); D3DXMATRIXA16 matViewProj = matView * matProj; // Update focal plane g_pEffect->SetVector( g_hFocalPlane, &g_vFocalPlane ); // Set world render technique V( g_pEffect->SetTechnique( g_hTechWorldWithBlurFactor ) ); // Set the mesh texture LPD3DXMESH pSceneMesh; int nNumObjectsInScene; if( g_nCurrentScene == 1 ) { V( g_pEffect->SetTexture( g_hMeshTexture, g_pScene1MeshTexture ) ); pSceneMesh = g_pScene1Mesh; nNumObjectsInScene = 25; } else { V( g_pEffect->SetTexture( g_hMeshTexture, g_pScene2MeshTexture ) ); pSceneMesh = g_pScene2Mesh; nNumObjectsInScene = 3; } static const D3DXVECTOR3 mScene2WorldPos[3] = { D3DXVECTOR3( -0.5f, -0.5f, -0.5f ), D3DXVECTOR3( 1.0f, 1.0f, 2.0f ), D3DXVECTOR3( 3.0f, 3.0f, 5.0f ) }; for( int iObject = 0; iObject < nNumObjectsInScene; iObject++ ) { // setup the world matrix for the current world if( g_nCurrentScene == 1 ) { D3DXMatrixTranslation( &matWorld, -( iObject % 5 ) * 1.0f, 0.0f, ( iObject / 5 ) * 3.0f ); } else { D3DXMATRIXA16 matRot, matPos; D3DXMatrixRotationY( &matRot, ( float )fTime * 0.66666f ); D3DXMatrixTranslation( &matPos, mScene2WorldPos[iObject].x, mScene2WorldPos[iObject].y, mScene2WorldPos[iObject].z ); matWorld = matRot * matPos; } // Update effect vars D3DXMATRIXA16 matWorldViewProj = matWorld * matViewProj; D3DXMATRIXA16 matWorldView = matWorld * matView; V( g_pEffect->SetMatrix( g_hWorld, &matWorld ) ); V( g_pEffect->SetMatrix( g_hWorldView, &matWorldView ) ); V( g_pEffect->SetMatrix( g_hWorldViewProjection, &matWorldViewProj ) ); // Draw the mesh on the rendertarget V( g_pEffect->Begin( &cPasses, 0 ) ); for( iPass = 0; iPass < cPasses; iPass++ ) { V( g_pEffect->BeginPass( iPass ) ); V( pSceneMesh->DrawSubset( 0 ) ); V( g_pEffect->EndPass() ); } V( g_pEffect->End() ); } V( g_pRenderToSurface->EndScene( 0 ) ); } // Clear the backbuffer V( pd3dDevice->Clear( 0L, NULL, D3DCLEAR_TARGET, 0x00000000, 1.0f, 0L ) ); // Begin the scene, rendering to the backbuffer if( SUCCEEDED( pd3dDevice->BeginScene() ) ) { pd3dDevice->SetViewport( &g_ViewportFB ); // Set the post process technique switch( g_nShowMode ) { case 0: V( g_pEffect->SetTechnique( g_hTech[g_TechniqueIndex] ) ); break; case 1: V( g_pEffect->SetTechnique( g_hTechShowBlurFactor ) ); break; case 2: V( g_pEffect->SetTechnique( g_hTechShowUnmodified ) ); break; } // Render the fullscreen quad on to the backbuffer V( g_pEffect->Begin( &cPasses, 0 ) ); for( iPass = 0; iPass < cPasses; iPass++ ) { V( g_pEffect->BeginPass( iPass ) ); V( pd3dDevice->SetFVF( VERTEX::FVF ) ); V( pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, g_Vertex, sizeof( VERTEX ) ) ); V( g_pEffect->EndPass() ); } V( g_pEffect->End() ); V( g_HUD.OnRender( fElapsedTime ) ); V( g_SampleUI.OnRender( fElapsedTime ) ); // Render the text RenderText(); // End the scene. pd3dDevice->EndScene(); } } [Edited by - standby01 on September 9, 2010 4:21:09 PM]
  14. Quote:Original post by ET3D You can use a viewport (set using IDirect3DDevice9::SetViewport) which covers only part of the window. Another way is to use IDirect3DDevice9::SetScissorRect. The different is that the viewport affects scaling of the image (it sets the full rendering area to a specific sub-rectangle of the window) while the scissor rect just prevent drawing outside it. I think using view port is the best.
  15. You could consider to use XNA Game Studio, which is a programming environment that allows you to use Visual Studio to create games for Windows Phone, the Xbox 360 console, and Windows-based computers. XNA Game Studio includes the XNA Framework, which is a set of managed libraries designed for game development based on Microsoft .NET Framework 2.0. This documentation collection contains technology overviews, tutorials, and reference material related to XNA Game Studio. Here is a good book for XNA 3.0. You also can find some books on 4.0 either on Amazon. This is an excellent site for XNA, and you can downlaod XNA Game Studio 4.0 beta from it.
  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!