Drawing sprites without a texture

Started by
8 comments, last by george7378 11 years ago

Is there a way to do this? I just want to draw a coloured rectangle which doesn't need a texture - I tried using the normal sprite methods but just specifying NULL for the texture, but it doesn't like that. I guess I could always just use a 1x1 placeholder texture, but it seems a little uneccessary when all I want is a coloured rectangle!

Thanks!

Advertisement

You might want to use a pixelshader or effect file for this. Not sure if you can use the ID3DXSprite-Interface for this, supposed that you already do? Draw your sprites as screen-transformaded vertex rectangles, and use the pixelshader to eighter draw a texture or the color. Don't know any tutorials for that on top of my head, maybe someone else could help out.

Yes, this is very much possible. Can you describe in more detail how you are drawing your sprites now? It should be as simple as rendering four vertices and transforming them in the way that you want, and either putting the color into the vertex format or use a constant register in the pixel shader to color the output.

At the moment I'm using the standard sprite->Begin(), sprite->Draw() and sprite->End() methods. I guess I could draw a quad, but again, that seems like overkill when sprites work so well with textures. I'm using the sprites as a HUD overlay for a 3D game btw.

I don't remember the specifics, but you can make the texture during runtime by locking a texture resource and writing the pixel color to it. What I usually do is create a single 1x1 white texture for all uses, and a helper function to draw a rectangle area for the sprite using that texture. The function would also let you set your own color, which to multiply with the white texture. Either in your drawing code or pixel shader will do.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

What API are you using? Depending on your API, there may already be a function for this. It's best to check the documentation.

D3D 9. Two alternatives:

- Use a ID3DXLine with a big width.

- Use Clear with rectangle parameters (works only for opaque drawing, I think)

AFAIK you are required to use a texture with DXSprites. Simply make a 1x1 white texture as mentioned by CC Ricers above. In the Sprite->Draw function you have a setting to change it to any color you want (last parameter).


HRESULT Draw(

LPDIRECT3DTEXTURE9 pTexture,

CONST RECT * pSrcRect,

CONST D3DXVECTOR3 * pCenter,

CONST D3DXVECTOR3 * pPosition,

D3DCOLOR Color

);

******************************************************************************************
Youtube Channel

If you're using ID3DXSprite, it requires a texture to use. If you want to continue using that interface, the best choice you have is simply using a 1x1 texture. This will have completely negligible effects on performance.

I went with the 1x1 placeholder texture in the end - it works fine and I can just apply a scaling matrix to get a rectangle of my desired size.

This topic is closed to new replies.

Advertisement