For some reason beyond my understanding, my 3D scene disappears when I call
this->sp->Begin(D3DX10_SPRITE_SORT_TEXTURE);
Where this->sp is LPD3DX10SPRITE.
to render my 2D scene. My 3D scene also disappears when I call
RECT rc = {5, 5, 0, 0};
this->TR.Font->DrawText(
NULL,
SS.str().c_str(),
-1,
&rc,
DT_NOCLIP,
D3DXCOLOR(0.0f, 1.0f, 0.0f, 1.0f));
Where this->TR.Font is ID3DX10Font.
Should I be using a ID3D10RenderTargetView for each scene and then combine at the end of my draw function?
If it is any help, here is Draw() function.
void Draw()
{
this->GDM.Clear(Color(100, 149, 237));
this->GDM.Device->RSSetState(this->GDM.RasterizerState);
this->GDM.Device->OMSetBlendState(this->GDM.BlendState, 0, 0xffffffff);
this->GDM.EnableZBuffer(true);
static float r;
D3DXMATRIX w;
D3DXMatrixIdentity(&w);
//D3DXMatrixRotationY(&w, r);
r += 0.01f * (3.14f / 180.0f);// * (float)Time->Scalar;
this->effect.WorldMatrix->SetMatrix(w);
this->effect.ViewMatrix->SetMatrix(viewMatrix);
this->effect.ProjectionMatrix->SetMatrix(projectionMatrix);
Vertex_PosCol * v = NULL;
this->VertexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**) &v);
v[0] = Vertex_PosCol(D3DXVECTOR3(-1,-1,0), D3DXVECTOR4(1,0,0,1));
v[1] = Vertex_PosCol(D3DXVECTOR3(0,1,0), D3DXVECTOR4(0,1,0,1));
v[2] = Vertex_PosCol(D3DXVECTOR3(1,-1,0), D3DXVECTOR4(0,0,1,1));
this->VertexBuffer->Unmap();
this->GDM.Device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP);
//this->GDM.Device->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_LINESTRIP);
D3D10_TECHNIQUE_DESC techDesc;
this->effect.Technique->GetDesc( &techDesc );
for (int p = 0; p < techDesc.Passes; p++)
{
this->effect.Technique->GetPassByIndex( p )->Apply( 0 );
this->GDM.Device->Draw(3, 0);
}
this->GDM.EnableZBuffer(false);
this->sBatch->Begin();
if (loaded)
{
this->sBatch->Draw(
s1,
this->Input->Mouse.Position.x,
this->Input->Mouse.Position.y,
200,
200,
45.0f * (3.14f / 180.0f));
this->sBatch->Draw(s2, x, y, 200, 200);
}
this->sBatch->End();
SS << "Graphics Test And Development" << "\n";
SS << "FPS: " << this->Time->FPS << "\n";
SS << "X: " << x << "\n";
SS << "Y: " << y << "\n";
RECT rc = {5, 5, 0, 0};
this->TR.RenderText(this->SS.str().c_str(), 5, 5, &Color(0.0f, 1.0f, 0.0f, 1.0f));
this->SS.str("");
}
As Mentioned in the comments above, setting the D3DX10_SPRITE_SAVE_STATE solved the problem as far as rendering 2D with 3D. It however did not stop DrawText from removing the 3D scene. Years ago I had this working so i spent hour trying to find my old code. Sadly I could not but i did manage to track down the tutorial I followed at that time.
Here is the solution:
Instead of creating and and discarding the vertices every frame the way I was:
I created a Vertex and Index buffer in the Load() function:
then in my Draw() function I set the vertex and index buffers and the primitive topology as well as the input layout for that specific buffer. Then I draw the 3D scene and then the text. Here is the Draw() function code:
I spent far longer on this than I should have because of stupid mistakes. When i created the bufferes, I created a D3D10_SUBRESOURCE_DATA object for each the vertex and index buffers but I forgot to set them and as a result, I was getting no 3D scene at all.
With the current 3D scene rendering method that I am using, D3DX10_SPRITE_SAVE_STATE as a flag in LPD3DX10SPRITE.Begin() is not necessary as far as I can tell but I am going to keep it regardless unless it happens to bring up any performance issues but I doubt that that would ever be the case.
Anyway, I do realize that a simple "hey, I changed this and it works" may have been enough to suffice as an answer but I wanted to be thorough. Hopes this helps someone!