I am currently trying to create a temporary texture, draw to it and then set the texture then to another object.
First I get some render states, reset them and set them back to the original value after rendering to my temporary target.
DWORD fogEnabled = 0;
DWORD zEnable = 0;
m_device->GetRenderState(D3DRS_ZENABLE, &zEnable);
m_device->GetRenderState(D3DRS_FOGENABLE, &fogEnabled);
LPDIRECT3DTEXTURE9 t; // D3DUSAGE_AUTOGENMIPMAP |
m_device->CreateTexture(width, height, 1, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &t, NULL);
t->GetSurfaceLevel(0, &pRenderTargetTemp);
if (!m_device->SetRenderTarget(0, pRenderTargetTemp))
{
m_device->SetRenderState(D3DRS_ZENABLE, FALSE);
m_device->SetRenderState(D3DRS_FOGENABLE, FALSE);
m_device->Clear(0, NULL, 1, 0x000000, 0.0, 0);
if (SUCCEEDED(m_device->BeginScene()))
{
char buffer[100];
list<RPQuadFace*>::iterator i_rp_begin = rpFaces->begin();
for (; i_rp_begin != rpFaces->end(); ++i_rp_begin)
{
RPQuadFace* rp = *i_rp_begin;
if (rp->tex)
hr = m_device->SetTexture(0, rp->tex->GetDDSurface()); // actually sets a LPDIRECT3DTEXTURE9, not a surface
else
hr = m_device->SetTexture(0, NULL);
//sprintf(buffer, "textures/%p.bmp", rp->tex);
//D3DXSaveTextureToFile(buffer, D3DXIFF_BMP, rp->tex->GetDDSurface(), NULL);
//Trace("width=%d, height=%d", width, height);
//Trace("%.0f, %.0f, %.0f, %.0f); // texture=%p", rp->m_verts[0].x, rp->m_verts[0].y, rp->m_verts[1].x, rp->m_verts[1].y, rp->tex);
//Trace("%.0f, %.0f, %.0f, %.0f); // texture=%p", rp->m_verts[2].x, rp->m_verts[2].y, rp->m_verts[3].x, rp->m_verts[3].y, rp->tex);
//Trace("%.0f, %.0f, %.0f, %.0f); // texture=%p", rp->m_verts[0].x, rp->m_verts[0].y, rp->m_verts[2].x, rp->m_verts[2].y, rp->tex);
//Trace("%.0f, %.0f, %.0f, %.0f // texture=%p", rp->m_verts[1].x, rp->m_verts[1].y, rp->m_verts[3].x, rp->m_verts[3].y, rp->tex);
rp->DrawPri(m_device);
}
m_device->EndScene();
//////////////
DrawPri
if (numVerts)
{
device->SetStreamSource(0, mRPF_VB, 0, sizeof(tlvertex3d));
device->SetFVF(GFCFACE);
if (numIndices)
{
device->SetIndices(mPRF_IB);
device->DrawIndexedPrimitive(primType, 0, 0, numVerts, 0, 2);
}
else
{
device->DrawPrimitive(primType, 0, 2);
Sleep(0);
}
}
I got some debug code in there to check if the verts are correct and they reflect the position of the specific tile.
If I dump the single textures (rp→tex) it saves the correct image to the disk. If I try to save the whole surface after drawing my rps to it, it just shows one of the texture but scaled to the whole image size (streched).
I currently have no idea why it is that way and hope someone has an idea on what the issue could be.
![](https://uploads.gamedev.net/forums/monthly_2022_08/cb3dab7d19064a1da97fcdc12f8f2d51.image.png)
This is the log of the positions.
0, 0, 356, 0 // texture=1F4FA8F0 - base image, other icons should get rendered on it
0, 263, 356, 263 // texture=1F4FA8F0
0, 0, 0, 263 // texture=1F4FA8F0
356, 0, 356, 263 // texture=1F4FA8F0
9, 23, 41, 23 // texture=1F4FB520
9, 57, 41, 57 // texture=1F4FB520
9, 23, 9, 57 // texture=1F4FB520
41, 23, 41, 57 // texture=1F4FB520
51, 23, 83, 23 // texture=1F4FAB60
51, 57, 83, 57 // texture=1F4FAB60
51, 23, 51, 57 // texture=1F4FAB60
83, 23, 83, 57 // texture=1F4FAB60
93, 23, 125, 23 // texture=1F4F8F58
93, 57, 125, 57 // texture=1F4F8F58
93, 23, 93, 57 // texture=1F4F8F58
125, 23, 125, 57 // texture=1F4F8F58
135, 23, 167, 23 // texture=1F4FB658
135, 57, 167, 57 // texture=1F4FB658
135, 23, 135, 57 // texture=1F4FB658
167, 23, 167, 57 // texture=1F4FB658
177, 23, 209, 23 // texture=1F4FBA00
177, 57, 209, 57 // texture=1F4FBA00
177, 23, 177, 57 // texture=1F4FBA00
209, 23, 209, 57 // texture=1F4FBA00
9, 66, 41, 66 // texture=1F4FBB38
9, 100, 41, 100 // texture=1F4FBB38
9, 66, 9, 100 // texture=1F4FBB38
41, 66, 41, 100 // texture=1F4FBB38
51, 66, 83, 66 // texture=1F4FBEE0
51, 100, 83, 100 // texture=1F4FBEE0
51, 66, 51, 100 // texture=1F4FBEE0
83, 66, 83, 100 // texture=1F4FBEE0
93, 66, 125, 66 // texture=1F4FBC70
93, 100, 125, 100 // texture=1F4FBC70
93, 66, 93, 100 // texture=1F4FBC70
125, 66, 125, 100 // texture=1F4FBC70
135, 66, 167, 66 // texture=1F4FBDA8
135, 100, 167, 100 // texture=1F4FBDA8
135, 66, 135, 100 // texture=1F4FBDA8
167, 66, 167, 100 // texture=1F4FBDA8
177, 66, 209, 66 // texture=1F4FB790
177, 100, 209, 100 // texture=1F4FB790
177, 66, 177, 100 // texture=1F4FB790
209, 66, 209, 100 // texture=1F4FB790
9, 109, 41, 109 // texture=1F4FB8C8
9, 143, 41, 143 // texture=1F4FB8C8
9, 109, 9, 143 // texture=1F4FB8C8
41, 109, 41, 143 // texture=1F4FB8C8
51, 109, 83, 109 // texture=240F19C0
51, 143, 83, 143 // texture=240F19C0
51, 109, 51, 143 // texture=240F19C0
83, 109, 83, 143 // texture=240F19C0
93, 109, 125, 109 // texture=240F1EA0
93, 143, 125, 143 // texture=240F1EA0
93, 109, 93, 143 // texture=240F1EA0
125, 109, 125, 143 // texture=240F1EA0
135, 109, 167, 109 // texture=240F08B0
135, 143, 167, 143 // texture=240F08B0
135, 109, 135, 143 // texture=240F08B0
167, 109, 167, 143 // texture=240F08B0
177, 109, 209, 109 // texture=240F1000
177, 143, 209, 143 // texture=240F1000
177, 109, 177, 143 // texture=240F1000
209, 109, 209, 143 // texture=240F1000
9, 152, 41, 152 // texture=240F1270
9, 186, 41, 186 // texture=240F1270
9, 152, 9, 186 // texture=240F1270
41, 152, 41, 186 // texture=240F1270
51, 152, 83, 152 // texture=240F1FD8
51, 186, 83, 186 // texture=240F1FD8
51, 152, 51, 186 // texture=240F1FD8
83, 152, 83, 186 // texture=240F1FD8
93, 152, 125, 152 // texture=240F03D0
93, 186, 125, 186 // texture=240F03D0
93, 152, 93, 186 // texture=240F03D0
125, 152, 125, 186 // texture=240F03D0
135, 152, 167, 152 // texture=240F1AF8
135, 186, 167, 186 // texture=240F1AF8
135, 152, 135, 186 // texture=240F1AF8
167, 152, 167, 186 // texture=240F1AF8
177, 152, 209, 152 // texture=240F1C30
177, 186, 209, 186 // texture=240F1C30
177, 152, 177, 186 // texture=240F1C30
209, 152, 209, 186 // texture=240F1C30
9, 195, 41, 195 // texture=240F0508
9, 229, 41, 229 // texture=240F0508
9, 195, 9, 229 // texture=240F0508
41, 195, 41, 229 // texture=240F0508
51, 195, 83, 195 // texture=240F0C58
51, 229, 83, 229 // texture=240F0C58
51, 195, 51, 229 // texture=240F0C58
83, 195, 83, 229 // texture=240F0C58
0, 4, 219, 4 // texture=240F2110
0, 13, 219, 13 // texture=240F2110
0, 4, 0, 13 // texture=240F2110
219, 4, 219, 13 // texture=240F2110
The result should look like
![](https://uploads.gamedev.net/forums/monthly_2022_08/41f72e63501d407eb600c581452e7555.image.png)