Sign in to follow this  
joshualimm

GDI-like functions for DirectX10?

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(....);

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

// Offset where the menu text starts from
int menuTopOffset = 100;

// Draw selected menu's highlight border
int selectedMenuY = menuTopOffset + (_selectedMenuIndex * TextHeight());
DrawRectangle(device, 
              100, selectedMenuY, 
              width-200, selectedMenuY+TextHeight(), 
              FILL, 0xff00eeee);

// Draw each menu item one after the other, centered.
for (int i=0; i<NUM_MENU_ITEMS; i++)
{
	// Let the selected menu text be BLUE. Non-selected menu text be WHITE
    DWORD textColor = i==_selectedMenuIndex ? 0xffffffff : 0xff0000ff;
	DrawText(device, 
                 _menuItem[i], 
                 (width-TextWidth(_menuItem[i]))/2, // An idea to center the text. Or might use GDI-like flags like DT_CENTER, etc.
                 menuTopOffset + (i * TextHeight()),
                 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);

Any recommendations/advices? Thanks Josh

Share this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by joshualimm
Are 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 this post


Link to post
Share on other sites
Quote:
Original post by Evil Steve
Quote:
Original post by joshualimm
Are 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?

Share this post


Link to post
Share on other sites
Quote:
Original post by Fire Lancer
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?
Nope; it's probably slower than using straight GDI, because there's bound to be some additional marshalling of data going on. However, it works well for getting something working quickly, which is what the OP asked for.

A possibly more efficient alternative would be to create a DIB section, and select that into an HDC, and then access the DIB bits as needed, and update the contents of a texture with that. That would also allow you to get around the format restrictions (So long as you do the pixel conversion yourself).

Share this post


Link to post
Share on other sites

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