Archived

This topic is now archived and is closed to further replies.

ageny6

GDI+?

Recommended Posts

Wow, there is such a thing as GDI+? I read about it in the online MSDN library http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/AboutGDIPlus/IntroductiontoGDIPlus/OverviewofGDIPlus.asp Is it really that better as they claim it to be? "...but programmers of new applications should use GDI+ for all their graphics needs because GDI+ optimizes many of the capabilities of GDI and also provides additional features." Is there a way to get GDI+ without using windows 2000 or XP? Jonathan

Share this post


Link to post
Share on other sites
Forget it for games, if that''s what you mean. It''s just as slow and ...you know, cumbersome (flickering sprites being the first thing that comes in mind). I also think it''s only available for the windows 2000 or xp platforms.

Share this post


Link to post
Share on other sites
GDI+ is actually very good. It''s sort of like a GDI wrapper around DirectX, and although I haven''t used it for games or done any performance testing on it, I have used it for supporting tools (editors for loading textures, etc). I *think* you can use it on Win9x by simply copying gdiplus.dll, but I''m not sure.

Share this post


Link to post
Share on other sites
quote:
Original post by BriTeg
I *think* you can use it on Win9x by simply copying gdiplus.dll, but I''m not sure.

Are you telling me that all the API functions that come with GDI+ are all in one .dll file?

Has anyone performed tests on the GDI+ vs GDI or has read an article about it???


Jonathan

Share this post


Link to post
Share on other sites
quote:
Original post by ageny6
Are you telling me that all the API functions that come with GDI+ are all in one .dll file?



Yes.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/GDIPlus.asp

I was a bit wrong about Win9x. The page says XP, NT 4.0 (SP6), Win2K, Win98, and WinME. No Win95 listed. gdiplus.dll comes with XP, you have to distribute it for the others.

I used it because it handles .gif/.jpg/.png/.tiff easily. The matrix tranformations for scaling/rotating/etc, are pretty handy too, as are things like splines, gradient brushes, and alpha blending.

But sorry, no performance information.


Share this post


Link to post
Share on other sites
I used gdi+(does transparency correctly unlike win98 api) but since I was also using mfc which provided me with features I needed I dropped gdi+. For win32 stuff I would consider it again. On win95/98/me one needs the gdiplus.dll redistributable file which can be downloaded from ms website. For dev. the gdi+ sdk has it all. Very nice toolkit and c++ like.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
gdi+ works real nice for loading textures into OpenGL very easily and supports lots of nice file formats

Share this post


Link to post
Share on other sites
When GDI+ came out with the Visual Studio .NET I went to try if it's really as good (having gone through nightmares of VB6 flickerings). So I decided to make a remake of our old VB4 game Mad Driver with GDI+ to see how good it is.

Here are the results (you can download the game to see for yourself (2MB) or get some VB.NET source to see how we made it):
Mad Driver v.NET

As I'm writing on the our page, the visual look is good, lots of things can be done with it, but the thing just isn't fast, because it is not hardware accelerated (GDI+ is no DirectX wrapper as someone mentioned). So for such a simple game as we've made you need 1GHz or better CPU to run the game smoothly in 1 player mode.

So I recomend GDI+ for static things only (and for manipulating bitmaps, getting pixel information or such), but for games use DX or OGL which makes use of your GPU.

[edited by - Flamer3D on May 30, 2003 7:44:24 AM]

Share this post


Link to post
Share on other sites
You said you recoded a VB game? I understand that GDI+ is compatible with VB.Net. But, a guy like me has only VB6 and VC6. I know that it is only for c++ according to microsoft, but is there somewhere a VB6 GDI+?

Jonathan

[edited by - ageny6 on May 31, 2003 1:50:44 PM]

Share this post


Link to post
Share on other sites
This is great! I thought it was only for .NET. So somebody can usit with C++ or VB6 and doesn''t need .NET framework at all to work?

Because even if it isn''t the solution for fast graphically intense games, it includes lots of useful things for loading pictures, creating shapes, paths and other stuff that you use in the background for different things, maybe even texture creation (but I''m not sure how fast this part of GDI+ is).

Share this post


Link to post
Share on other sites
Yes, GDI+ is quite good actually. Over at CodePrject.com somebody did an article on drawing speed in GDI+. Might wanna check it out:
Drawing Speed in GDI+

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius -- and a lot of courage -- to move in the opposite direction.

Share this post


Link to post
Share on other sites
quote:
Original post by Flamer3D
So somebody can usit with C++ or VB6 and doesn't need .NET framework at all to work?

So you are telling me that you can take the GDI+ for c++ and convert it to vb6? If so, how in the world can you do that??? Did I interpret what you meant all wrong (did you mean something else when you mentioned vb6?)?


Jonathan

[edited by - ageny6 on June 1, 2003 8:51:52 AM]

Share this post


Link to post
Share on other sites
I was asking Arild Fines if you can use GDI+ withouth having .NET framework installed. That was the meaning of the question, I got that VB6 or C++ there unintentually.

Otherwise you can make any C++ API work with VB6, just have to make a wrapper for it (I think it is the sam as with calls to win32 from VB6 when you use the declare statement)

Share this post


Link to post
Share on other sites
GDI+ uses C++ and classes for all the graphic objects.
You will not be able to manipulate these classes directly in VB6.

You will need to create a DLL in C++ and create wrapper functions around GDI+

For instance here are a couple of functions that I have exposed to VB6.

The wrapper functions...

int CALLBACK GDIplusInitEngine(void)
{

// Init gdiplus

Gdiplus::Status Stat = Gdiplus::GdiplusStartup(&gdiplusToken,&gdiplusStartupInput, NULL);

if(Stat == Gdiplus::Ok) return -1; else return 0;

}

void CALLBACK GDIplusCloseEngine(void)
{
Gdiplus::GdiplusShutdown(gdiplusToken);
}

You have to initialise GDI+ once and you have to close it when finished.






Share this post


Link to post
Share on other sites
Alrighty,

I know that you can create a .dll wrapper class for VB6, but I have never done it (never really had to). Is there a good tutorial out there that can help me in this process? Is there a VB6 GDI+ already created?

Jonathan

[edited by - ageny6 on June 2, 2003 10:02:36 AM]

Share this post


Link to post
Share on other sites

Don't know which VC you are using but you need to create a DLL project.

You will need to get the GDI+ sdk from Msofts site and refer to gdiplus.lib in your
dependicies for the linker to resolve. You will also need to put wingdi on your include
path as well.

For non XP end users get the redistribution. Never attempt to replace the Msoft
GDI+ dll on XP. Only win 95 cannot have GDI+ (Think)


Here is some sample code. Very monolithic but you should get the idea from this.

// windows and gdi stuff

#include <windows.h>
#include <wingdi.h>
#include <gdiplus.h>



// Just for convenience. You might want to prefix eg. Gdiplus:en
using namespace Gdiplus;

// Some magic decimal numbers for converting VB long colour values to RGB

#define RED_MASK 255
#define GREEN_MASK 65280
#define BLUE_MASK 16711680


// Some globals. Stick em in a class if you want this is just to get it going.

static ULONG_PTR gdiplusToken;
static GdiplusStartupInput gdiplusStartupInput;

// A flag to detect if we called init

static int GdiPlusInit;


/* Just some functions.

I find creating a .def file in VC works ok for the mangling for VB6

so create a .def file and list each function like this

EXPORTS

GDIplusInitEngine
GDIplusCloseEngine
GDIplusLineTo
SomeOtherFunc


*/


// CloseEngine - See DLL - Also read Msofts notes on caveats

void CALLBACK GDIplusCloseEngine(void)
{

if(GdiPlusInit)
{
GdiplusShutdown(gdiplusToken);
GdiPlusInit = 0;
}


}

// Initengine - read notes further down in DLLmain
int CALLBACK GDIplusInitEngine(void)
{

// Just in case you call it twice - Global keeps track of it.
GDIplusCloseEngine();
// Init gdiplus

Status Stat = GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

if(Stat == Ok)
{
GdiPlusInit = 1;
}
else
{
GdiPlusInit = 0;
}

return(GdiPlusInit);

}


//Just a simple Drawline. Pass the Device context in from VB


void CALLBACK GDIplusLineTo(HDC Ahdc, int x1, int y1, int x2, int y2, int outlineW, int outlineCol)
{

Pen* myPen;
Graphics* myGraphics;

int S_Red , S_Green , S_Blue;

S_Red = (outlineCol & RED_MASK);
S_Green = (outlineCol & GREEN_MASK) >> 8;
S_Blue = (outlineCol & BLUE_MASK) >> 16;


myPen = new Pen(Color(255, S_Red, S_Green, S_Blue),(float) outlineW);

myGraphics = new Graphics(Ahdc);

// Cool GDI+ antialiased lines
myGraphics->SetSmoothingMode(SmoothingModeHighQuality);

// I want round ended lines. Have a look there is a ton if settings.
myPen->SetStartCap(LineCapRound);
myPen->SetEndCap(LineCapRound);

/* GDI+ seems to have a problem with some linewidths when plotting
a line with the same cords. Drawing an ellipse seems to fix it and it looks better */

if(x1 == x2 && y1 == y2)
{
SolidBrush brush(Color(255, S_Red, S_Green, S_Blue));
myGraphics->FillEllipse(&brush, x1 - (outlineW/2),y1 - (outlineW/2),outlineW ,outlineW);

}
else
{
myGraphics->DrawLine(myPen, x1, y1, x2, y2);
}

delete myGraphics;
delete myPen;


}


// Dll Entry point
int WINAPI DllMain(HINSTANCE hInstance,DWORD fdwReason,PVOID pvReserved)
{


switch (fdwReason)
{
case DLL_PROCESS_ATTACH:

/* Do not be tempted to init GDIplus from here
Microsoft strongly advises not too
Init it from your calling application.

You must also close it down when finished with it
don't attempt to nest either */

GdiPlusinit = 0;
break;

case DLL_THREAD_ATTACH:

break;

case DLL_THREAD_DETACH:

break;

case DLL_PROCESS_DETACH:

/* msoft says nothing about closing it down in a dLL
all depends on what you are using it for I suppose

Note in VB6 you will get bad crashes in the IDE if Gdiplus
is not closed down properly. Watch your close app event
this detach will catch any stragglers though.


if(GdiPlusInit)
{
GdiplusShutdown(gdiplusToken);
GdiPlusInit = 0;
}


break;
}


return TRUE;
}



Ok there is a skeleton. Put your DLL where VB can find it. Usually system directory.


Now the VB end....

Declare Function GDIplusInitEngine Lib "YourGdiPlusDLL" () As Long
Declare Sub GDIplusCloseEngine Lib "YourGdiPlusDll" ()

Declare Sub GDIplusLineTo Lib "YourGdiPlusDLL" (ByVal Winhdc As Long, _
ByVal x1 As Long, _
ByVal y1 As Long, _
ByVal x2 as Long, _
Byval y2 as Long, _
ByVal penwidth As Long, _
ByVal pencolour As Long)



sub main()
ok = GDIplusInitEngine()

if ok = 0 then
beep
end
end if
myform.show

' draw a line
GdiPlusLineTo(myform.hDc, 0 , 0 , 100 , 132 , 4 , vbRed)

end sub



That should get you started. I also think there is a good tutorial over at flipcode.com for using your own DLL's
from VB.

Good luck














[edited by - andyed on June 2, 2003 12:12:20 PM]

Share this post


Link to post
Share on other sites
Awesome, that should get me started. I will look into it tommorrow and ask questions later (because god knows how much I ask)

Jonathan

Share this post


Link to post
Share on other sites
Here is the tutorial for interfacing VB with C++ via Dll''s Some good stuff about string types and UDT''s as well.

http://www.flipcode.com/articles/article_vbdlls.shtml

Share this post


Link to post
Share on other sites