Jump to content
  • Advertisement

sriam

Member
  • Content Count

    12
  • Joined

  • Last visited

Community Reputation

100 Neutral

About sriam

  • Rank
    Member
  1. My XML is something like: <Object> <Transform x=0 y=0></Transform> <Physics accel=1></Physics> </Object> What I can't figure out is how to get the name of tags "Transform" & "Physics" using the TiXmlElement and this code: TiXmlElement * element; TiXmlNode * iter; TiXmlDocument xml = TiXmlDocument(strFileName); xml.LoadFile(); iter = xml.FirstChild( "Object" ); for( iter; iter; iter = iter->NextSibling()) { element = iter->FirstChildElement(); Debug::PrintF("%s\n", element->WHATGOESHERE?); } Should print "Transform" and then "Physics" ...much obliged
  2. sriam

    id

  3. To answer my own question, apparently DX resets settings during the Draw phases. So I had: mDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); at the beginning of the app, and nowhere else, hoping that it would be persistent. But I have to call that every draw phase.
  4. If I use my World, View & Proj matrices in C++ via d3d_device->SetTransform() and then run my results though Pix, CCW ordered triangles become CW ordered and are rendered. If I use the exact same matrices in a VertexShader, the CCW triangles remain CCW but they are not drawn. Same results with D3DCULL_CW or D3DCULL_CCW What am I missing there? Do I need to invert one of my matrices?
  5. I have an object, it's position is (100, 100, 0). If I use the regular calls to d3d_device->SetMatrix() for View, Proj & World (meaning no shaders) , it renders it on the view port, but Pix tells me the co-ordinates are (-0.8, 0.8, 0); If I pass the same matrices to a Vertex Shader, it yields the point (241, 241, 0) which is very much off the Normalized Device Co-ordinates of the Viewport and not rendered. I multiplied my World matrix by a scalar matrix: D3DXMatrixScaling(&mScaleMatrix, 1.0f / (float)vp.Width, 1.0f / (float)vp.Height, 1.0f); Now Pix tells me I am getting normalized viewport values but still nothing is rendered on the Viewport What am I doing wrong? I pass the View & Projection matrices to a shader and do the matrix math there, do I still need to call d3d_device->SetMatrix() ?
  6. I have a better idea! I think DX moves the vertices into 3d space differently when you translate in C++ using d3d_device->SetTransform() (which works) then if you translate using a shader. I'll go back and make sure the ViewPort and Camera are set for 3d. Thanks for your help.
  7. same thing... Here it is now: // globals, set via constant table uniform extern float4x4 MatWorld; sampler2D TexSampler; struct VS_VERTEX { float4 Position : POSITION; float2 Texture : TEXCOORD0; }; // **** VERTEX SHADER **** VS_VERTEX vs_main( VS_VERTEX vsIn ) { VS_VERTEX Out = (VS_VERTEX)0; //float4x4 mat = mul(MatProj, MatView); //mat = mul(MatWorld, mat); Out.Position = mul(vsIn.Position, MatWorld); Out.Texture = vsIn.Texture; return Out; } // **** PIXEL SHADER **** float4 ps_main( VS_VERTEX vsIn ) : COLOR0 { float4 Color; Color = tex2D( TexSampler, vsIn.Texture.xy); return Color; } technique fx_technique { pass P0 { VertexShader = compile vs_2_0 vs_main(); PixelShader = compile ps_2_0 ps_main(); FillMode = Solid; } } If I set VertexShader = null; in the technique it renders, but no transform. If I debug the Vertex Shader in Pix, it gives me the correct values, but nothing is drawn.
  8. Here is my sooper awesomer shader: // globals, set via constant table uniform extern float4x4 MatWorld; sampler2D TexSampler; // Vertex shader input structure // using a 2d engine so Position is float3 struct VS_INPUT { float4 Position : POSITION; float2 Texture : TEXCOORD0; }; // Vertex shader output structure // Position converted to float4 for DX struct VS_OUTPUT { float4 Position : POSITION; float2 Texture : TEXCOORD0; }; // **** VERTEX SHADER **** VS_OUTPUT vs_main( in VS_INPUT In ) { VS_OUTPUT Out = (VS_OUTPUT)0; Out.Position = In.Position; Out.Texture = In.Texture; //copy original texcoords return Out; } // **** PIXEL SHADER **** float4 ps_main( float2 Tex : TEXCOORD0 ) : COLOR0 { float4 Color; Color = tex2D( TexSampler, Tex.xy); return Color; } technique fx_technique { pass P0 { VertexShader = compile vs_2_0 vs_main(); PixelShader = compile ps_2_0 ps_main(); FillMode = Solid; } } It takes any textured quad I give it and renders NOTHING! w00t! BUT! If I change the technique to: technique fx_technique { pass P0 { VertexShader = null; PixelShader = compile ps_2_0 ps_main(); FillMode = Solid; } } It renders my textures. I've debugged the Shader with Pix and it says the the VertexShader is doing what it's supposed to, but it doesn't draw anything and I think for some reason that when vs_main() is called ps_main() isn't. Any clues are greatly appreciated.
  9. I've got my 2d engine working fine with drawing textured quads, but when I moved the matrix math into a Vertex Shader, it stops drawing them. I've gone through and debugged the values in Pix, they are correct. Do I need to change a SetTextureStageState() value when I use Shaders? Shader: // globals, set via constant table float4x4 MatWorld; sampler2D TexSampler; // Vertex shader input structure // using a 2d engine so Position is float3 struct VS_INPUT { float3 Position : POSITION; float2 Texture : TEXCOORD0; }; // Vertex shader output structure // Position converted to float4 for DX struct VS_OUTPUT { float4 Position : POSITION; float2 Texture : TEXCOORD0; }; // **** VERTEX SHADER **** // Vertex transformation and texture coord pass-through VS_OUTPUT vs_main( in VS_INPUT In ) { VS_OUTPUT Out = (VS_OUTPUT)0; Out.Position = mul(float4(In.Position.xyz, 1.0f), MatWorld); Out.Texture = In.Texture; //copy original texcoords return Out; } // **** PIXEL SHADER **** // Fetch texture color float4 ps_main( in VS_OUTPUT In ) : COLOR { return tex2D( TexSampler, In.Texture ); //return output pixel }
  10. Hi, I've been using Pix's Shader debugger to step through my HLSL code and realized that it won't let me watch variables as well as VS does. Many times it does not place local variables into the Variables window. Are there any tricks to force a variable to be placed into Pix's Variables windows so I may see the values? Particularly I want to watch a float4x4 variable and have yet to find a neat way to do it. Thanks in advance.
  11. Hi, I have something going on with my DirectX Shader. When I replace the call (at the end of the code list) of DrawPrimitive() with DrawPrimitiveUP() it renders triangles. But not with the Shader and DrawPrimitive() Here is the code (you can assume any variables not declared here were set up elsewhere): Vertex vertices[] = { {20, 40, 1, D3DCOLOR_RGBA(0, 255, 255, 255)}, {40, 20, 1, D3DCOLOR_RGBA(255, 0, 0, 255)}, {60, 60, 1, D3DCOLOR_RGBA(0, 255, 255, 255)}, {20, 40, 1, D3DCOLOR_RGBA(0, 255, 255, 255)}, }; void * pVertices; const char * strShader = "vs_1_1 \n" "dcl_position v0 \n" "dcl_color v1 \n" "m4x4 oPos, v0, c0 \n" "mov oD0, v1 \n" ""; int result; // for test create vertex buffer // create a pixel shader result = mDevice->CreateVertexBuffer( 4 * sizeof(Vertex), 0, 0, D3DPOOL_DEFAULT, &mVertexBuffer, 0); // lock the buffer to prepare for copying info into shader mVertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertices, 0); memcpy(pVertices, vertices, sizeof(vertices)); mVertexBuffer->Unlock(); // Create the vertex declaration D3DVERTEXELEMENT9 decl[]= { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() }; result = mDevice->CreateVertexDeclaration( decl, &mVertexDeclaration); // now we are ready to assemble the shader result = D3DXAssembleShader( strShader, (UINT)strlen(strShader), 0, 0, D3DXSHADER_DEBUG, &mShader, 0 ); if(result != 0) { Debug::PrintF("ERROR: Shader::loadString D3DXAssembleShader failed error code %d\n", result); } // create a vertex shader result = mDevice->CreateVertexShader( (DWORD*) mShader->GetBufferPointer(), &mVertexShader ); if(result != 0) { Debug::PrintF("ERROR: Shader::loadString CreateVertexShader failed error code %d\n", result); } D3DXMATRIX mMatWorld; mDevice->SetFVF(D3DFVF_XYZRHW | D3DFVF_DIFFUSE); D3DXMatrixIdentity( &mMatWorld ); result = mDevice->SetVertexShaderConstantF( 0, (float *)&mMatWorld, 4 ); result = mDevice->SetVertexDeclaration( mVertexDeclaration ); result = mDevice->SetVertexShader( mVertexShader ); result = mDevice->SetStreamSource(0, mVertexBuffer, 0, sizeof(Vertex)); // now we get the magic list of triangles back from the shader! result = mDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 1); mDevice->SetVertexShader( 0 ); mDevice->SetTexture(0, NULL);
  12. Hi, My DirectX C++ engine works fine with Sprites, Textures, etc. And this call to DrawPrimitiveUP works fine too: device->DrawPrimitiveUP(D3DPT_LINESTRIP, 3, vertices, sizeof(Vertex)); So my next step is to use a shader, which I got out of a book: const char * strShader = "vs_1_1 \n" "dcl_position v0 \n" "dcl_color v1 \n" "m4x4 oPos, v0, c0 \n" "mov oD0, v1 \n" ""; Here are my vertices: Vertex vertices[] = { {20, 40, 0, D3DCOLOR_RGBA(0, 255, 255, 255)}, {40, 20, 0, D3DCOLOR_RGBA(255, 0, 0, 255)}, {60, 60, 0, D3DCOLOR_RGBA(0, 255, 255, 255)}, {20, 40, 0, D3DCOLOR_RGBA(0, 255, 255, 255)}, }; Using that Shader I attempt this code: result = device->CreateVertexBuffer( 4 * sizeof(Vertex), 0, 0, D3DPOOL_DEFAULT, &mVertexBuffer, 0); // lock the buffer to prepare for copying info into shader mVertexBuffer->Lock(0, sizeof(vertices), (void**)&pVertices, 0); memcpy(pVertices, vertices, sizeof(vertices)); mVertexBuffer->Unlock(); // Create the vertex declaration D3DVERTEXELEMENT9 decl[]= { {0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 }, {0, 12, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 }, D3DDECL_END() }; result = device->CreateVertexDeclaration( decl, &mVertexDeclaration); // ready to assemble the shader result = D3DXAssembleShader( strShader, (UINT)strlen(strShader), 0, 0, D3DXSHADER_DEBUG, &mShader, 0 ); // create a vertex shader result = device->CreateVertexShader( (DWORD*) mShader->GetBufferPointer(), &mVertexShader ); D3DXMatrixIdentity( &mMatWorld ); result = device->SetVertexShaderConstantF( 0, (float *)&mMatWorld, 4 ); result = device->SetVertexDeclaration( mVertexDeclaration ); result = device->SetVertexShader( mVertexShader ); result = device->SetStreamSource(0, mVertexBuffer, 0, sizeof(Vertex)); // now we get the magic list of triangles back from the shader! result = device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 1); device->SetVertexShader( 0 ); device->SetTexture(0, NULL); I check the result and it's fine all the way through, but my screen is empty! Any clues?
  13. How do you z buffer a LPD3DXLINE->Draw() ?
  • 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!