Jump to content

  • Log In with Google      Sign In   
  • Create Account


Drawing sprites without a texture


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 george7378   Members   -  Reputation: 1132

Like
0Likes
Like

Posted 20 March 2013 - 12:48 PM

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!



Sponsor:

#2 Juliean   GDNet+   -  Reputation: 2228

Like
1Likes
Like

Posted 20 March 2013 - 01:35 PM

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.



#3 Jason Z   Crossbones+   -  Reputation: 4681

Like
1Likes
Like

Posted 20 March 2013 - 03:19 PM

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.



#4 george7378   Members   -  Reputation: 1132

Like
0Likes
Like

Posted 20 March 2013 - 03:31 PM

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.



#5 CC Ricers   Members   -  Reputation: 623

Like
4Likes
Like

Posted 20 March 2013 - 03:42 PM

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.


Edited by CC Ricers, 20 March 2013 - 03:47 PM.

My development blog: Electronic Meteor

#6 Ludus   Members   -  Reputation: 966

Like
1Likes
Like

Posted 20 March 2013 - 03:53 PM

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



#7 unbird   Crossbones+   -  Reputation: 4816

Like
1Likes
Like

Posted 20 March 2013 - 05:22 PM

D3D 9. Two alternatives:

 

- Use a ID3DXLine with a big width.

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



#8 LancerSolurus   Members   -  Reputation: 485

Like
1Likes
Like

Posted 20 March 2013 - 05:56 PM

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


#9 Flimflam   Members   -  Reputation: 657

Like
1Likes
Like

Posted 20 March 2013 - 09:20 PM

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. 



#10 george7378   Members   -  Reputation: 1132

Like
0Likes
Like

Posted 21 March 2013 - 12:47 PM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS