# GDI-like functions for DirectX10?

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

## Recommended Posts

Hi, I'm used to using GDI functions (e.g, Ellipse, Rectangle, FillRect, Polygon, GradientFill, LineTo, DrawText etc). Was wondering if there are anything equivalent in DirectX10? Or can I use these functions to manipulate the buffer? Reason is, I want a light-weight method of drawing these primitive shapes on screen without having to create a bunch of vertices, textures, etc. Instead, I want to be able to quickly prototype ideas, like:
device->ClearRenderTargetView(....);

// Draw simple Border
DrawRectangle(device,
10, 10,
width-20, height-20,
NO_FILL, 0xffffffff);

// Offset where the menu text starts from

// Draw selected menu's highlight border
DrawRectangle(device,
FILL, 0xff00eeee);

// Draw each menu item one after the other, centered.
{
// Let the selected menu text be BLUE. Non-selected menu text be WHITE
DWORD textColor = i==_selectedMenuIndex ? 0xffffffff : 0xff0000ff;
DrawText(device,
(width-TextWidth(_menuItem[i]))/2, // An idea to center the text. Or might use GDI-like flags like DT_CENTER, etc.
textColor);
}

swapchain->Present(0,0);


And another example
device->ClearRenderTargetView(....);

// Random routine to draw a bunch of rectangles and circles on screen

for (int i=0; i<5000; i++)
{
int x = rand()%width;
int y = rand()%height;
int width = 10+rand()%100; // random size between 10-110
int height = 10+rand()%100; // random size between to-100
DWORD color = RGB(rand()%255, rand()%255, rand()%255);

// Draw a rectangle/ellipse alternatively
if (i%2==0)
DrawRectangle(device, x, y, width, height, color);
else
DrawEllipse(device, x,y,width,height, color);
}

swapchain->Present(0,0);



##### Share on other sites
Take a look at Direct2D.

##### Share on other sites
Hi,

Thanks for the reply! For a moment there, I thought you were talking about DirectDraw. Got me confused there for a sec!

Will definitely check it out.

However, here's an extension to my question:

Are there any similar GDI-like functions for DirectX 9?

Do I have to lock the back buffer, and manually draw/fill the shapes myself (point by point)? Are there any helper functions (in D3DX perhaps?)? Or am I doomed to creating vertices and rendering them, when all I want is draw/fill a shape on the screen?

I'm really interested to understand how the same thing can be/used to be achieved in DirectX9 and 10, with/without helper or additional APIs.

Thanks
Josh

##### Share on other sites
Quote:
 Original post by joshualimmAre there any similar GDI-like functions for DirectX 9?
You can use IDirect3DSurface9::GetDC to get an HDC you can sue with GDI, and if you're using that for a texture you can use pTexture->GetSurfaceLevel(0, & pSurface); to get the top level surface for the texture.

Note that there's some restrictions on the surface formats you can use for that though.

##### Share on other sites
Thanks Steve for the info. Will give that a try!

Regards,
Josh

##### Share on other sites
Quote:
Original post by Evil Steve
Quote:
 Original post by joshualimmAre there any similar GDI-like functions for DirectX 9?
You can use IDirect3DSurface9::GetDC to get an HDC you can sue with GDI, and if you're using that for a texture you can use pTexture->GetSurfaceLevel(0, & pSurface); to get the top level surface for the texture.

Note that there's some restrictions on the surface formats you can use for that though.

Does that actually offer any advantages over straight GDI apart from integration with D3D components (ie so drawing say a HUD in a 3D game)? I assume using GDI like this is no more or less hardware accelerated than GDI normally is?