Dynamic 2D Elements in DirectX

Started by
3 comments, last by brwarner 16 years, 1 month ago
How can I draw 2D elements (boxes, circles, rounded boxed, etc.) using DirectX without having premade textures for them. I've seen this implemented in other games for UI and was wondering how without using any of the D3DX libraries.
Advertisement
Quote:Original post by brwarner
How can I draw 2D elements (boxes, circles, rounded boxed, etc.) using DirectX without having premade textures for them. I've seen this implemented in other games for UI and was wondering how without using any of the D3DX libraries.
First, why don't you want to use D3DX? It's part of DirectX and the only reason you wouldn't want to use it is if you're doing XBox development or something where D3DX doesn't exist (Although there are alternatives). You might as well not use D3D and write your own device driver or something instead...

What other games have you seen that do this? And what makes you think they don't have premade textures? You don't have to have one texture for every shape; for instance a box is 4 lines.

And D3D itself doesn't have any support for that sort of stuff; it's not GDI. You'll either have to do something weird with GDI to use it to render shapes, or render them yourself using textures or something similar.
Quote:Original post by Evil Steve
It's part of DirectX and the only reason you wouldn't want to use it is if you're doing XBox development or something where D3DX doesn't exist.


Even the original Xbox SDK had it's own version of D3DX. I dunno if the big games made heavy use of it, but it was definitely available.

Quote:Original post by Evil Steve
And D3D itself doesn't have any support for that sort of stuff; it's not GDI. You'll either have to do something weird with GDI to use it to render shapes, or render them yourself using textures or something similar.


I suppose he could use GDI+ to render 2D primitives, and then make a texture from the DIB and use it as a sprite (like how D3DXFont renderes glyphs). Probably a better idea would be to render quads using a pixel shader that renders the desired primitive according to some relevent parameters. You could do some neat effects that way, too.
Quote:Original post by Evil Steve
First, why don't you want to use D3DX? It's part of DirectX and the only reason you wouldn't want to use it is if you're doing XBox development or something where D3DX doesn't exist (Although there are alternatives). You might as well not use D3D and write your own device driver or something instead...


It's not that I don't use D3DX. I wrote a "wrapper" DLL for DirectX that isolates it from the application and does a lot of initialization behind the scenes so the application has less to do. If I used any part of D3DX it would have to be coded into the engine, which I didn't want to do.

I think I'll go with the pixel shader idea.

Quote:Original post by Evil Steve
What other games have you seen that do this? And what makes you think they don't have premade textures? You don't have to have one texture for every shape; for instance a box is 4 lines.

Source Engine modding allowed drawing rounded boxes with variable degrees of roundness, I assumed that this was calculated in game unless they drew many many textures (or otherwise deformed one somehow..)
I'm trying to go the GDI+ way, to see how it works out and I've learned some tutorials on how to draw things using GDI+ but how do I get the results data so I can use it as a texture?

This topic is closed to new replies.

Advertisement