Sign in to follow this  

[SOLVED] Drawing a textured square - sprite issue

This topic is 3719 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

Why is it that in order for me to see the texture of a square I have defined using an FVF and vertices, I need to call Sprite->Begin and Sprite->End surrounding my SetTexture() call?
	sdd3d->BeginSprite();
	d3d->SetTransform(D3DTS_VIEW, &cam->GetView());
	d3d->SetTransform(D3DTS_PROJECTION, &cam->GetProjection());
	d3d->SetFVF(MENUFVF);
	d3d->SetStreamSource(0, menu_buffer, 0, sizeof(MENUVERTEX));
	d3d->SetTexture(0, menu_texture);

	if (FAILED(d3d->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2)))
		ERR("SD_MENU::Render: Failed to render a menu.");

	d3d->SetTexture(0, NULL);
	d3d->SetFVF(NULL);
	sdd3d->EndSprite();



If I remove the BeginSprite and EndSprite calls nothing will display. I thought you only needed to make sprite calls when using Sprite->Draw(). I believe that this repetitive use of Begin/End Sprite in this function as well as in my RenderText function is causing all fonts to flicker. Does anyone know of a way around this or why I need these calls at all??? [Edited by - orphankill on October 13, 2007 1:30:16 PM]

Share this post


Link to post
Share on other sites
What does BeginSprite() and EndSprite() do? They don't call beginScene() and EndScene() do they? If so, that's your problem - you can only call DrawPrimitive() from within a BeginScene()..EndScene() block.

Share this post


Link to post
Share on other sites
No no, this whole function is already contained in a BeginScene and EndScene.
Here they are (sorry completely forgot):

void BeginSprite() { d3dspr->Begin(D3DXSPRITE_ALPHABLEND); draw_started = TRUE; }
void EndSprite() { d3dspr->End(); draw_started = FALSE; }


Share this post


Link to post
Share on other sites
d3dspr->Begin(D3DXSPRITE_ALPHABLEND);
d3dspr->End();

Begin saves the current render state settings and sets new ones for sprite drawing based on the flags you pass.

End restores the settings saved in Begin.

That is why you could get unexpected results if you try to draw something inside a sprite's begin-end block, since the render states are changed during that phase.
The only workaround is to set the render state manually. They are explained in the docs. But that is just a waste of coding time. The sprite interface basically just draws lots of quads using a Draw*** function.

Share this post


Link to post
Share on other sites
Huh...by adding these three render states, it works now: (my fonts still flicker badly sometimes though)

d3d->SetRenderState(D3DRS_LIGHTING, FALSE);
d3d->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
d3d->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);

Share this post


Link to post
Share on other sites

This topic is 3719 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this