Gdi+ Dev C++

Quite a while ago, I made '>this snippet. This code is basically the same, except that it adds animation.

May 13, 2001  This marks the end of my first GDI+ tutorial. My aim was simply to get you up and running - to show you how to set up a program to use GDI+ and explain some basic concepts about the way it is set up. My next tutorial will be on using brushes - with GDI+ you can make a brush display a gradient, or even be textured with a bitmap. The GDI, as a military army, navy, and air force, was officially formed on October 12, 1995, by the final act of the United Nations Global Defense Initiative, in response to the rise of the Brotherhood of Nod and its efforts to gain power in unstable, third-world nations. Before the First Tiberium War began, the GDI followed its mandate under the orders of the United Nations Security Council. In GDI we used COLORREF as a variable that held a colour. It was a typedef for a DWORD, and a COLORREF was built using the RGB macro. Colours could be retrieved using GetRValue, GetGValue and GetBValue. In contrast, GDI+ uses the COLOR class, which takes four values to contruct - the extra being alpha. A task-oriented review of an animation library and the application which uses it.

This method of blitting is very fast assuming you don't use a surface that's too large. On a 500 x 500 surface, I managed 350fps using only 0-1% of the cpu. This snippet may appear much slower because of the amount of CPU it's applying to each pixel, but the blitting itself is very fast. Also, don't forget that an average game will only redraw parts of the window that need redrawing, this redraws the whole surface every time.

So, as long as you know what you're doing, Windows GDI isn't actually that slow :icon_lol:

Attached executable:
GDI Animation.zip

Gdi dev c reviews
Preview Image:

edit: Running in Debug may reduce speed by a lot, set it as Release.

3,534 Views

Here's a speed test :) mine stays at about 480fps with only 2-3% CPU.

William Hemsworth1,339

Another really nice effect using this method :icon_smile:

Got it working with objects and bitmaps, I think with some optimizations I could use this to make some neat games :)

optimumgaint

Sorry, I should have tested it with multiple compilers, replace that line with:

and it should work.

mrnutty761

Pretty cool. Looks something someone will see if they were high of drugs.

Pretty cool. Looks something someone will see if they were high of drugs.

Haha, what have you been smoking? I'd go crazy if anything turned out that intense.
Thanks alot for the feedback :icon_razz:

Dave Sinkula2,398

Issues when building with mingw:

main.cpp:12: error: ISO C++ prohibits anonymous structs
main.cpp: In function `void onFrame(pixel*)':
main.cpp:60: error: expected primary-expression before 'unsigned'
main.cpp:60: error: expected `;' before 'unsigned'
main.cpp: In function `void MakeSurface(HWND__*)':
main.cpp:134: warning: passing NULL used for non-pointer converting 2 of `void* CreateThread(_SECURITY_ATTRIBUTES*, DWORD, DWORD (*)(void*), void*, DWORD, DWORD*)'
main.cpp:134: warning: passing NULL used for non-pointer converting 5 of `void* CreateThread(_SECURITY_ATTRIBUTES*, DWORD, DWORD (*)(void*), void*, DWORD, DWORD*)'
main.cpp: In function `int WinMain(HINSTANCE__*, HINSTANCE__*, CHAR*, int)':
main.cpp:237: warning: passing NULL used for non-pointer converting 4 of `BOOL GetMessageA(tagMSG*, HWND__*, UINT, UINT)'

This includes the cast you've already corrected. So it's mostly just that anonymous struct you may want to look at.

[edit]Also, the necessary library to link with:

-LD:ProgramsCodeBlocksMinGWlib -lgdi32

Where the path to the library will be whatever your install might be.

Edited by Dave Sinkula: n/a

Gdi+ Example

This includes the cast you've already corrected. So it's mostly just that anonymous struct you may want to look at.

Does giving the anonymous structure a name fix that?
Never thought there would be so many compiler issues, and I didn't realize that anonymous structs weren't allowed.

Gdi+ Dev C++

Thanks :)

Dev C++ Download

Dave Sinkula2,398

Does giving the anonymous structure a name fix that?

Yup. I just named it s , for example.

Hi, thanks for the cool code. I got it working in a Win32 app (project type choice) in VC++ Express 2010 by making the includes:
#include 'stdafx.h'
#include 'GDIWin32.h'
#include <windows.h>
#include <iostream>
#include <cmath>

and putting the L in front of the quoted text, as in:
// Init wc
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.cbSize = sizeof( WNDCLASSEX );
wc.hbrBackground = CreateSolidBrush( 0 );
wc.hCursor = LoadCursor( NULL, IDC_ARROW );
wc.hIcon = LoadIcon( NULL, IDI_APPLICATION );
wc.hIconSm = LoadIcon( NULL, IDI_APPLICATION );
wc.hInstance = hInstance;
wc.lpfnWndProc = WndProc;
wc.lpszClassName = L'animation_class';
wc.lpszMenuName = NULL;
wc.style = 0;

// Register wc
if ( !RegisterClassEx(&wc) ) {
MessageBox( NULL, L'Failed to register window class.', L'Error', MB_OK );
return 0;
}

Very cool, thanks very much. Any thoughts on how this could be implemented in a Windows Forms Application? (Sorry if this is a really stupid question, just starting in VC++.) Thanks again, Bill

Bill Dreschel

Finally got around to putting this animation code into a Visual C++ 2010 Express Windows form application. To use it, start a new form build, add a PictureBox, name it 'src' and make it some even dimension like 400,400. Add a button, name it 'btnStart', text to 'Start', add a timer to the form, set it to 20ms and disabled.
Add the attached code.

Have fun! THANKS AGAIN FOR POSTING THE FAST ANIMATION SNIPPET!

Edited by mike_2000_17: Fixed formatting

Gdi Development

Hi,
And this is a C Sharp version from Bill Dreschel's code. The picture box I used named 'pictureBox1'. It looks pretty good.
I post this here because I found this article while I was searching for a CSharp solution about something like this.
And I think it may help someone like me :-)

Gdi+ Tutorial

Edited by thetukiet: adb