• Advertisement
Sign in to follow this  

Change image file that LPDIRECT3DTEXTURE9 texture is using

This topic is 2349 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi people!
I'm trying to change the images that LPDIRECT3DTEXTURE9 is pointing to, in a for loop, so I can render them all.

Here's some code:
void InitializeObject(string file) {

D3DXCreateTextureFromFile(D3D_Device, file.c_str(), &Texture);
D3DXCreateSprite(D3D_Device, &g_pSprite);

}



And in my RenderScene() method I'm trying to do the following:
void RenderScene() {

// Clear the screen to black.
D3D_Device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

// Tell Direct 3D we are now going to start drawing.
D3D_Device->BeginScene();

// SetTexture will add the image in the Texture object to all
// things draw after this. To Turn if off send SetTexture(0, NULL);
D3D_Device->SetTexture(0, Texture);
RECT Rect;
Rect.top = 15;
Rect.left = 15;
Rect.bottom = 115;
Rect.right = 115;
D3DXVECTOR3 vCenter (0, 0, 0);
D3DXVECTOR3 vPosition(90, 10, 0);

string files[8] = {
"Square_1.png", "Square_2.png", "Square_3.png", "Square_4.png",
"Square_5.png", "Square_6.png", "Square_7.png", "BlankSquare.png"
};

g_pSprite->Begin(D3DXSPRITE_ALPHABLEND);

for (int k = 0; k < 6; k++) {

for (int i = 0; i < 7; i++) {

if (k == 0)
InitializeObject(files);

g_pSprite->Draw(Texture, &Rect, &vCenter, &vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f));
vPosition.x += 120;

}

if (k == 0)
InitializeObject(files[7]);

// reset for the next row
vPosition.x = 90;
vPosition.y += 120;
}

g_pSprite->End();

// We are done drawing for this scene.
D3D_Device->EndScene();

// Swap the old frame with the new one.
D3D_Device->Present(NULL, NULL, NULL, NULL);
}



It works with multiple images that are the same, but I can't change them.
Can someone help please, I can't find the solution in documentation...
Thank you!

Share this post


Link to post
Share on other sites
Advertisement
Oh, and by the way, in my .txt file the InitialiseDirect3D method's head should look like this:

void InitializeDirect3D(HWND hwnd, bool fullscreen)


was just a typo.



The error says: D3DX: ID3DXSprite::Draw called outside a Begin/End pair,
but my for loop is clearly between g_pSprite->Begin() and g_pSprite->End()

Share this post


Link to post
Share on other sites
Fixed it! The call to InitializeObject() HAD to be outside Begin-End thing...
This is the correct syntax:


for (int k = 0; k < 6; k++) {

for (int i = 0; i < 7; i++) {

if (k == 0)
InitializeObject(files);

g_pSprite->Begin(D3DXSPRITE_ALPHABLEND);

g_pSprite->Draw(Texture, &Rect, &vCenter, &vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f));
vPosition.x += 120;

g_pSprite->End();
}

if (k == 0)
InitializeObject(files[7]);

// reset for the next row
vPosition.x = 90;
vPosition.y += 120;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement