Direct2D development status and how to use it

Do you have a typical platform dependent issue you're battling with ? Ask it here. Make sure you mention your platform, compiler, and wxWidgets version.
Post Reply
Predator
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Dec 09, 2015 9:46 pm

Direct2D development status and how to use it

Post by Predator »

Hi,
I have few questions about using Direct2D.

1. What is the development status of Direct2D implementation? Is it almost complete, and can be used as replacement of GDI, or is it still full of bugs?
2. How to get started with Direct2D? Sure, I can download wxWidgets from Github, but I can't find any docs about adding it to my project or any very basics of usage.
3. Direct2D works on Windows 7 and higher. What about Windows XP? Does it automatically swithes to GDI? How much code would I have to write to handle different systems versions?
4. I thought about using OpenGL for 2D drawings. What do you think about this?
- I've read that printing is harder to implement that it is in GDI.
- Is there something like GraphicsPath? So I could combine few objects and check if user have clicked on it?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Direct2D development status and how to use it

Post by doublemax »

1. What is the development status of Direct2D implementation? Is it almost complete, and can be used as replacement of GDI, or is it still full of bugs?
You can try it yourself with the latest wxWidgets version from GIT and the "drawing" sample. It throws lots of asserts, i don't know whether these are harmless and/or easy to fix. But - as usual for GSOC projects - the original author stopped working on it when GSoC was over, so any patches to make it (more) usable are welcome.
2. How to get started with Direct2D? Sure, I can download wxWidgets from Github, but I can't find any docs about adding it to my project or any very basics of usage.
Check the "drawing" sample, search for "DIRECT2D".
3. Direct2D works on Windows 7 and higher. What about Windows XP? Does it automatically swithes to GDI?
AFAIK, no.
How much code would I have to write to handle different systems versions?
Should be minimal, you just need to create a different type of wxGraphicsContext. Everything else stays the same.
4. I thought about using OpenGL for 2D drawings. What do you think about this?
Good idea, i suggested that a few times as a GSoC project, but it was never accepted.
- I've read that printing is harder to implement that it is in GDI.
- Is there something like GraphicsPath? So I could combine few objects and check if user have clicked on it?
I don't know anything about this.
Use the source, Luke!
Predator
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Dec 09, 2015 9:46 pm

Re: Direct2D development status and how to use it

Post by Predator »

Thanks for your answer.
I was looking for a way for printing graphics made with opengl, but I can't find anything that would work like GDI.
There is GL2PS library that enables printing to PostScript. I can also make an image and then print it, but it require a lot of memory.
Is there any way to print graphics made by opengl using vectors or something, that would work like printing using GDI?
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Direct2D development status and how to use it

Post by doublemax »

There is nothing for this in wxWidgets that could help with that.

I'm also not an OpenGL expert, but i know that it's possible to render into a texture. But that means that the graphics card needs to have enough memory to hold one page in printer resolution or you have to render the page in strips.
Use the source, Luke!
Predator
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Dec 09, 2015 9:46 pm

Re: Direct2D development status and how to use it

Post by Predator »

Thanks for your answer, again ;).
I'm learning how drawings in wxWidgets work, and I see a lot of differences between GDI and GDI+ that I know from C#. I have few minor problems, but about this one I have to ask for help.

Except drawing various shapes like lines, circles, curves and ellipses I want to check if user have clicked on one of them. In C# there are few ways to do it. One of them is to make a GraphicsPath and use widen function, so for example line becomes 5px wide and it is easy to click on it. In GDI that is implemented in wxWidgets I can't find anything similar.

So my question is: Is there easier way to check mouse clicks inside shapes than writing some algorithm that would cover theirs contours?

P. S.
I'm sorry for so basic questions...
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Direct2D development status and how to use it

Post by doublemax »

Under Windows wxDC uses GDI, wxGraphicsContext uses GDI+.
http://docs.wxwidgets.org/trunk/classwx ... ntext.html

When using wxGraphicsContext, you can use wxGraphicsPath, but this will only allow to check if a point is inside a polygon, there is nothing that checks if a point lies on a curve. I'm afraid you will have to code this yourself.
http://docs.wxwidgets.org/trunk/classwx ... _path.html
Use the source, Luke!
Manolo
Can't get richer than this
Can't get richer than this
Posts: 828
Joined: Mon Apr 30, 2012 11:07 pm

Re: Direct2D development status and how to use it

Post by Manolo »

Using an algorithm really means using an algorithm for each type of shape (poligon, circle, etc). Their mathematics are different.

Another way is to draw (for example in a wxMemoryDC) each shape with a unique color. You mantain a database or index with the colors you use.
You associate a wxBitmap to that wxMemoryDC (so you really draw to a wxBitmap). Then, convert the wxBitmap to a wxImage. Finally, you can ask wxImage colors (GetRed, GetBlue, GetGreen) at your coordinates. That color may form an index of your database.
Predator
In need of some credit
In need of some credit
Posts: 5
Joined: Wed Dec 09, 2015 9:46 pm

Re: Direct2D development status and how to use it

Post by Predator »

@Doublemax: I'm not looking for an algorithm that would determine if point lies on a line, or on a curve. I'm looking for function, that would make a polygon from line or a curve with some fixed width and then I could check if point is inside this polygon.
In C# there are functions like GraphicsPath.Widen, so it requires only drawing line, `polygon` is made automatically. That's why I am suprised that there is nothing similar available in wxWidgets. So I want to be sure, that I'm not inventing something that already exists and I don't know about.

@Manolo: I have read about color picking and it is a great method, but not perfect. What about polygons that are placed behined others?
Post Reply