UEZ

FreeBasic Graphical Examples build 2017-01-22

21 posts in this topic




Very nice effects !

You play with graphics with a disconcerting skilfulness.

It's a pleasure for the eyes ! ;)


AutoIt 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Share this post


Link to post
Share on other sites

I was curious why the executables are that big and whether free version of Visual Studio can be set to produce smaller exes. So I rewrote your code in C(++) and compiled it. I ended up with 5.5kb executables after removing CRT dependencies (by using Taylor series to approximate sin and cos) Pythagoras.zip

I hate default settings ...shit.

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites
19 hours ago, wakillon said:

Very nice effects !

You play with graphics with a disconcerting skilfulness.

It's a pleasure for the eyes ! ;)

Thank you. :)

 

53 minutes ago, trancexx said:

I was curious why the executables are that big and whether free version of Visual Studio can be set to produce smaller exes. So I rewrote your code in C(++) and compiled it. I ended up with 5.5kb executables after removing CRT dependencies (by using Taylor series to approximate sin and cos) Pythagoras.zip

I hate default settings ...shit.

Well done. Can you please post your C++ code? I want to see how you did that in C++.

Apropos dependencies: why didn't you use the inline ASM functions for Sin/Cos instead of approx. using Taylor series?

\sin x=\sum _{n=0}^{\infty }{\frac {(-1)^{n}}{(2n+1)!}}x^{2n+1}=x-{\frac {x^{3}}{3!}}+{\frac {x^{5}}{5!}}-\cdots \quad {\text{ for all }}x\!

\cos x=\sum _{n=0}^{\infty }{\frac {(-1)^{n}}{(2n)!}}x^{2n}=1-{\frac {x^{2}}{2!}}+{\frac {x^{4}}{4!}}-\cdots \quad {\text{ for all }}x\!

 


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

7 hours ago, UEZ said:

Well done. Can you please post your C++ code? I want to see how you did that in C++.

Apropos dependencies: why didn't you use the inline ASM functions for Sin/Cos instead of approx. using Taylor series?

\sin x=\sum _{n=0}^{\infty }{\frac {(-1)^{n}}{(2n+1)!}}x^{2n+1}=x-{\frac {x^{3}}{3!}}+{\frac {x^{5}}{5!}}-\cdots \quad {\text{ for all }}x\!

\cos x=\sum _{n=0}^{\infty }{\frac {(-1)^{n}}{(2n)!}}x^{2n}=1-{\frac {x^{2}}{2!}}+{\frac {x^{4}}{4!}}-\cdots \quad {\text{ for all }}x\!

 

Inline ASM when I have real compiler to work with? No thanks.

As for sin and cos approximations, this could be the code (in AutoIt):

Func cos_($x)
    If $x < 0 Then $x = -$x
    While $x >= 3.14159265359
        $x -= 6.28318530718
    WEnd
    Return 1.0 - ($x * $x / 2) * (1 - ($x * $x / 12) * (1 - ($x * $x / 30) * (1 - $x * $x / 56)))
EndFunc

Func sin_($x)
    Return cos_($x - 1.570796326795)
EndFunc

Source of the exe is pretty much your AutoIt code. I just copy/passed it and cleaned a bit:

#include <windows.h>
#pragma comment( linker, "/entry:MwWinMain" )



__forceinline float cos_(float x) {
	if (x < 0.0f)
		x = -x;
	while (3.14159265359f < x)
		x -= 6.28318530718f;
	return 1.0f - (x*x / 2.0f)*(1.0f - (x*x / 12.0f) * (1.0f - (x*x / 30.0f) * (1.0f - x*x / 56.0f)));
}

__forceinline float sin_(float x) { return cos_(x - 1.570796326795f); }


__forceinline WCHAR* int_to_wstr(int val)
{
	static WCHAR buf[32] = { 0 };
	int i = 30;
	for (; val && i; --i, val /= 10)
		buf[i] = L"0123456789"[val % 10];
	
	return &buf[i + 1];
}


// Global Variables:
HWND hWnd;
WCHAR szTitle[50] = L"GDI Animated Pythagoras Tree v2.5 / FPS:   ";                  // The title bar text
WCHAR* szWindowClass = L"UEZ_thingy";            // the main window class name
UINT_PTR IDT_TIMER1 = 100;
UINT_PTR IDT_TIMER2 = 1000;
HDC $hDC;
HDC $hGfxDC;
int $iW = 1200, $iH = 700;
HBITMAP $hBitmapGDI;
HGDIOBJ $hObjOld, $hPen, $hBrush, $hPen_Old, $hBrush_Old;
int $iFPS = 0;

// Forward declarations of functions included in this code module:
__forceinline ATOM                MyRegisterClass();
__forceinline bool                InitInstance();
LRESULT CALLBACK    WndProc(HWND, UINT, WPARAM, LPARAM);


int APIENTRY MwWinMain()
{
	MyRegisterClass();
	if (!InitInstance()) return FALSE;

	MSG msg;
	// Main message loop:
	while (GetMessage(&msg, NULL, 0, 0))
	{
		TranslateMessage(&msg);
		DispatchMessage(&msg);
	}

	ExitProcess((int)msg.wParam);
}


__forceinline ATOM MyRegisterClass()
{
	WNDCLASSEXW wcex;

	wcex.cbSize = sizeof(WNDCLASSEX);
	wcex.style = CS_HREDRAW | CS_VREDRAW;
	wcex.lpfnWndProc = WndProc;
	wcex.cbClsExtra = 0;
	wcex.cbWndExtra = 0;
	wcex.hInstance = nullptr;
	wcex.hIcon = nullptr;
	wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);// (HBRUSH)(GetStockObject(WHITE_BRUSH));
	wcex.lpszMenuName = nullptr;
	wcex.lpszClassName = szWindowClass;
	wcex.hIconSm = nullptr;

	return RegisterClassExW(&wcex);
}

__forceinline bool InitInstance()
{
	hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT, CW_USEDEFAULT, $iW, $iH, nullptr, nullptr, nullptr, nullptr);

	if (!hWnd) return false;

	$hDC = GetDC(hWnd);
	$hBitmapGDI = CreateCompatibleBitmap($hDC, $iW, $iH);
	$hGfxDC = CreateCompatibleDC($hDC);
	$hObjOld = SelectObject($hGfxDC, $hBitmapGDI);
	$hPen = GetStockObject(DC_PEN);
	$hBrush = GetStockObject(DC_BRUSH);
	$hPen_Old = SelectObject($hGfxDC, $hPen);
	$hBrush_Old = SelectObject($hGfxDC, $hBrush);
	SetStretchBltMode($hDC, WHITEONBLACK);

	ShowWindow(hWnd, 1);
	UpdateWindow(hWnd);

	SetTimer(hWnd,             // handle to main window 
		IDT_TIMER1,           // timer identifier 
		10,                  //interval 
		nullptr);           // no timer callback

	SetTimer(hWnd,             // handle to main window 
		IDT_TIMER2,           // timer identifier 
		1000,                //interval 
		nullptr);           // no timer callback

	return true;
}


void PythagorasRec(HDC $hDC, int $iX1, int $iY1, int $iX2, int $iY2, int $iRecDepth)
{
	auto $iBGR1 = ((255 - ($iRecDepth + 10) * 10) << 8) + $iRecDepth * 20;

	static float $i = 0;
	int $dx = $iX2 - $iX1;
	int $dy = $iY1 - $iY2;
	int  $iX3 = $iX2 - $dy;
	int $iY3 = $iY2 - $dx;
	int  $iX4 = $iX1 - $dy;
	int $iY4 = $iY1 - $dx;

	int  $iX5 = $iX4 + ($dx - $dy) / (2.5f - cos_(($iX4 + $i) / 400) / 1.5f);

	int  $iY5 = $iY4 - ($dx + $dy) / (2.25f + sin_(($iX5 + $iY4 - $i) / 500));

	$i += 0.06666f;

	BeginPath($hDC);
	MoveToEx($hDC, $iX1, $iY1, nullptr);
	LineTo($hDC, $iX2, $iY2);
	LineTo($hDC, $iX3, $iY3);
	LineTo($hDC, $iX4, $iY4);
	LineTo($hDC, $iX1, $iY1);
	EndPath($hDC);

	// DllCall($hDLL_gdi32, "dword", "SetDCPenColor", "handle", $hDC, "dword", $iBGR1)
	SetDCBrushColor($hDC, $iBGR1 | 0x305090);
	FillPath($hDC);
	//; DllCall($hDLL_gdi32, "bool", "StrokeAndFillPath", "handle", $hDC)
	
	if ($iRecDepth > 0)
	{
		PythagorasRec($hDC, $iX4, $iY4, $iX5, $iY5, $iRecDepth - 1);
		PythagorasRec($hDC, $iX5, $iY5, $iX3, $iY3, $iRecDepth - 1);
	}
}

//
//  FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
//  PURPOSE:  Processes messages for the main window.
//
//  WM_PAINT    - Paint the main window
//  WM_DESTROY  - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
	switch (message)
	{
	case WM_TIMER:
		if (wParam == IDT_TIMER1)
		{
			BitBlt($hGfxDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, WHITENESS);
			PythagorasRec($hGfxDC, 550, 700, 650, 700, 8);
			BitBlt($hDC, 0, 0, $iW, $iH, $hGfxDC, 0, 0, SRCCOPY);
			++$iFPS;
			return 0;
		}
		else if (wParam == IDT_TIMER2)
		{
			WCHAR* sFPS = int_to_wstr($iFPS);
			$iFPS = 0;
			szTitle[41] = *sFPS;
			szTitle[42] = *++sFPS;
			SetWindowText(hWnd, szTitle);
			return 0;
		}
		break;

	case WM_DESTROY:
		KillTimer(hWnd, IDT_TIMER1);
		KillTimer(hWnd, IDT_TIMER2);
		SelectObject($hGfxDC, $hPen_Old);
		DeleteObject($hPen);
		SelectObject($hGfxDC, $hBrush_Old);
		DeleteObject($hBrush);
		SelectObject($hGfxDC, $hObjOld);
		ReleaseDC(hWnd, $hDC);
		DeleteDC($hGfxDC);
		DeleteObject($hBitmapGDI);
		PostQuitMessage(0);
		return 0;

	case WM_PAINT:
	{
		PAINTSTRUCT ps;
		HDC hdc = BeginPaint(hWnd, &ps);
		//// TODO: Add any drawing code that uses hdc here...
		EndPaint(hWnd, &ps);
	}
	break;

	default:
		return DefWindowProc(hWnd, message, wParam, lParam);
	}
	return 0;
}

 

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

@trancexx thanks. At the first look C++ code looks more difficult but it isn't at least compared with Pythagoras code.

The C++ code made me curious and I will install the monster Visual Studio once again.

Thanks for sharing.

Btw, I add your Sin_/Cos_ function to FB just to compare the speed. I expected that the ASM inline is faster but isn't. Might be because the API calls amortize the speed difference.

1 person likes this

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
18 hours ago, UEZ said:

I expected that the ASM inline is faster but isn't. Might be because the API calls amortize the speed difference.

ASM (handcoded) is (a little bit) faster, but what you meant are the "native" FPU-Code FSIN(), FCOS() and FSINCOS(), where are way slower than an (as mentioned and showed by trancexx) approximation.

Calling the/an API-function is once more slower...

One of the reasons, why trancexx used 

__forceinline

which causes the compiler to inline this function into code. That means, no jumps/calls into a function! Makes the code some bytes bigger, but faster:thumbsup:

19 hours ago, UEZ said:

The C++ code made me curious and I will install the monster Visual Studio once again.

I deinstalled VS yesterday....i am waiting for a compiler which is able to use "real" SIMD when switch on the SSE-Flag. I examined the EXE with IDApro. Yes, the compiler produces short and (in most cases) fast(?!) code using (half-hearted) processor-features which were introduced about 20 years ago...

The only code i saw from a compiler using SIMD (as intended) was from the newest INTEL C++/FORTRAN-Compiler XE (v17.0). And to get this performance it is necessary to program in a "vectorizing" style ( and/or excessive use of _intrinsics_(), which force the compiler to fast(?!) code) .

Or use OpenMP, CILK and other features/libraries. But all this is fu*** sh** to push their (INTEL´s) CPU´s. If the program/algorithm is good to parallelize, OpenCL/CUDA on a price-adjusted GPU is up to 50 to 100 times faster than the code running on a CPU.

Enough whining, we have AutoIt after all...:P

1 person likes this

Share this post


Link to post
Share on other sites

@trancexx: I installed VS 2015 Pro. How can I get run your source code?

I opened a Win32Project and pasted your code into the editor but when I try to run it I get ems.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

1 hour ago, UEZ said:

@trancexx: I installed VS 2015 Pro. How can I get run your source code?

I opened a Win32Project and pasted your code into the editor but when I try to run it I get ems.

All default?

If yes then add #include <stdafx.h> at the top of that code, switch to "Release" "x86" then click "Debug" and select "Start Without Debugging"

VS.png

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Aha, working. Now I can play with code. :thumbsup::thumbsup::thumbsup:

THANKS.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

Oh, and to get small exes you'll need to change default settings for both compiler and linker. Otherwise you end up with plenty of BS.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

@trancexx: what have you done that the output (exe) is that small? My output is approx. 100kb.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
1 minute ago, trancexx said:

Oh, and to get small exes you'll need to change default settings for both compiler and linker. Otherwise you end up with plenty of BS.

Can you tell me if it's not too complicated to explain. Otherwise I can live also with 100kb. ;)


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
4 minutes ago, UEZ said:

Can you tell me if it's not too complicated to explain. Otherwise I can live also with 100kb. ;)

Sure. First of all delete all resource files from solution explorer window (right click on "Resource Files" -> delete. Then do the same for header files. Then remove #include #include "stdafx.h" line. Then go to "Project" and select bottom item (it should be "Some_Name Properties...", then expand "C/C++" and click "Precompiled Headers". On the right click "Use (/Yu)" and then select "Not Using Precompiled Headers".

Then on the left expand "Linker" and choose "Manifest File". Then on the right click "Yes /blah blah" and select "No ..."

1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

You should be on 6.5kb now. Few more tweaks and you're done.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

5 minutes ago, trancexx said:

You should be on 6.5kb now. Few more tweaks and you're done.

Yep, exactly 6.5kb. :)

10.000 things to learn...

 

Thanks again.

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites
On 17.10.2016 at 10:33 PM, UEZ said:

10.000 things to learn...

Or ask some of the 10.000 M$-Programmers why they are able to produce such a beautiful and outstanding piece of Software but not able to place a "Build smallest/shortest output possible" Button.

I am afraid, at our next joint beer, you will tell me that you added a "Build smallest/shortest output possible"-Button into the VS (by AutoIt of course! ). I am looking forward to...the beer, not the button:P

1 person likes this

Share this post


Link to post
Share on other sites

#18 ·  Posted

@UEZ, that FreeBasic 3D SinePlot got me interested, do you use one of the FreeBasic IDEs and if so, which one?


2015 - Still no flying cars, instead blankets with sleeves.

Share this post


Link to post
Share on other sites

#19 ·  Posted

@Lakes: here a list of IDEs: https://www.freebasic-portal.de/downloads/ides-fuer-freebasic/

I personally using FbEdit.


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Share this post


Link to post
Share on other sites

#20 ·  Posted

Thanks.


2015 - Still no flying cars, instead blankets with sleeves.

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

  • Similar Content

    • Larnil
      By Larnil
      This script generates Barnsleys Fractal Fern using script only.
      ; version 2017-10-03 ; Barnsley Fractal Fern ; by larnil #include <GUIConstants.au3> Dim $x, $y, $xn, $yn, $n, $r, $dc $WinSize = 800 ; window size ;Create graphics windows AutoItSetOption("GUIOnEventMode", 1) $GUI = GUICreate("Barnsley Fractal Fern", $WinSize, $WinSize, -1, -1) $Graphic = GuiCtrlCreateGraphic(0, 0, $WinSize, $WinSize) GUICtrlSetBkColor(-1, 0x000000) GUICtrlSetGraphic(-1,$GUI_GR_COLOR, 0x00ff00) GUISetState(@SW_SHOW) GUISetOnEvent($GUI_EVENT_CLOSE,"Bye") ;Main $start = TimerInit() _Fern(800) ; hight of fern - can be larger than window MsgBox(0,"Time taken:",Round(TimerDiff($start)/1000,3) &" seconds") While 1 Sleep(100) WEnd Func Bye() Exit EndFunc Func _Fern($height) $f = $height/10.6 ; scale factor. Complete fern is within 0 <= y <= 9.9983 (with no scale) $offset_x = $height/2 - $height/40 ; Side adjustment. Fern is within −2.1820 < x < 2.6558 (with no scale) For $n = 1 To $height*200 ; Number of iterations $r = Random(0, 99, 1) Select Case $r < 85 ; 0-84 = 85% of the time $xn = 0.85 * $x + 0.04 * $y $yn = -0.04 * $x + 0.85 * $y + 1.6 Case $r > 84 AND $r < 92 ; 85-91 = 7% of the time $xn = 0.2 * $x - 0.26 * $y $yn = 0.23 * $x + 0.22 * $y + 1.6 Case $r > 91 AND $r < 99 ; 92-98 = 7% of the time $xn = -0.15 * $x + 0.28 * $y $yn = 0.26 * $x + 0.24 * $y + 0.44 Case Else ; 99-99 = 1% of the time $xn = 0 $yn = 0.16 * $y EndSelect $x = $xn $y = $yn GUICtrlSetGraphic($Graphic, $GUI_GR_PIXEL, $offset_x + $x * $f, $height - $y * $f) Next GUICtrlSetGraphic($Graphic, $GUI_GR_REFRESH) EndFunc ;==> Fern  
      Here is another example where I have used GDI (my very first attempt at using GDI by the way). This script can generate much larger Ferns and save them to file (png). I have used this script to generate a 20000 x 20000 pixel @ 600 dpi image. Looks really good printed out in full size.
      #include <GDIPlus.au3> #include <GUIConstantsEx.au3> ; Param Local Const $iPxColor = 0xFF00FF00 ; Pixel color for fractal Alpha/R/G/B Local Const $iBgColor = 0xFFFFFFFF ; Background color for image Alpha/R/G/B Local Const $iSize = 1000 ; Hight of fern in pixels - image will have this hight and width too Local Const $iIter = $iSize*400 ; Number of iterations - $iSize * 200 is a good starting point ; Call function ;$start = TimerInit() _Fern($iSize,$iIter) ;MsgBox(0,"Time taken:",Round(TimerDiff($start)/1000,3) &" seconds") ; Function for generating Barnsley Fractal Fern Func _Fern($Size,$Iter) _GDIPlus_Startup() ; initialize GDI+ Local $hBitmap = _GDIPlus_BitmapCreateFromScan0($Size, $Size) ; create an empty bitmap Local $hBmpCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) ; get the graphics context of the image _GDIPlus_GraphicsClear($hBmpCtxt, $iBgColor) ; Set the background color for empty bitmap ; Here the magic happens $x=0 ; init $y=0 ; init $f = $Size/10.6 ; scale factor. Complete fern is within 0 <= y <= 9.9983 (with no scale) $offset_x = $Size/2 - $Size/40 ; Side adjustment. Fern is within −2.1820 < x < 2.6558 (with no scale) For $n = 1 To $Iter ; Number of iterations $r = Random(0, 99, 1) Select Case $r < 85 ; 0-84 = 85% of the time $xn = 0.85 * $x + 0.04 * $y $yn = -0.04 * $x + 0.85 * $y + 1.6 Case $r > 84 AND $r < 92 ; 85-91 = 7% of the time $xn = 0.2 * $x - 0.26 * $y $yn = 0.23 * $x + 0.22 * $y + 1.6 Case $r > 91 AND $r < 99 ; 92-98 = 7% of the time $xn = -0.15 * $x + 0.28 * $y $yn = 0.26 * $x + 0.24 * $y + 0.44 Case Else ; 99-99 = 1% of the time $xn = 0 $yn = 0.16 * $y EndSelect $x = $xn $y = $yn _GDIPlus_BitmapSetPixel($hBitmap, $offset_x + $x * $f, $Size - $y * $f, $iPxColor) ; Change pixel color for calculated X,Y Next ; ==> End of magic $File = "\Fractal_Fern_"&StringRight(Hex($iPxColor),6)&"-"&StringRight(Hex($iBgColor),6)&"-"&$iSize&".png" _GDIPlus_ImageSaveToFile($hBitmap, @MyDocumentsDir & $File) ;save bitmap to disk ShellExecute(@MyDocumentsDir & $File); Show it to the world in your default image viewer ; Cleanup GDI+ resources _GDIPlus_GraphicsDispose($hBmpCtxt) _GDIPlus_BitmapDispose($hBitmap) _GDIPlus_Shutdown() EndFunc ;==> _Fern  
       

    • seangriffin
      By seangriffin
      Here's the beginnings of SFML (the Simple and Fast Multimedia Library) for AutoIT. 
      This library provides a wealth of features for developing games and multimedia applications.  You can read up more about SFML here -> http://www.sfml-dev.org.  It uses OpenGL as the renderer for 2D graphics such as sprites, so it's performance is quite good.
      Currently my interest is in 2D sprite engines, so my focus is on the sprite and window APIs.  This is the precursor to another separate UDF I'm working on and will release soon.  If there's any interest I'll flesh out more of this API for the community.
      CSFML is the "C" binding / API for SFML, and it's this API that I'm building this UDF against.
      REQUIREMENTS:
      AutoIt3 3.2 or higher LIST OF FUNCTIONS (so far):
      _CSFML_Startup _CSFML_Shutdown _CSFML_sfClock_create _CSFML_sfClock_getElapsedTime _CSFML_sfClock_restart _CSFML_sfVector2f_Constructor _CSFML_sfVector2f_Update _CSFML_sfVector2f_Move _CSFML_sfColor_Constructor _CSFML_sfColor_fromRGB _CSFML_sfSizeEvent_Constructor _CSFML_sfEvent_Constructor _CSFML_sfVideoMode_Constructor _CSFML_sfRenderWindow_create _CSFML_sfRenderWindow_setVerticalSyncEnabled _CSFML_sfRenderWindow_isOpen _CSFML_sfRenderWindow_pollEvent _CSFML_sfRenderWindow_clear _CSFML_sfRenderWindow_drawText _CSFML_sfRenderWindow_drawSprite _CSFML_sfRenderWindow_display _CSFML_sfRenderWindow_close _CSFML_sfTexture_createFromFile _CSFML_sfSprite_create _CSFML_sfSprite_destroy _CSFML_sfSprite_setTexture _CSFML_sfSprite_setPosition _CSFML_sfSprite_setRotation _CSFML_sfSprite_rotate _CSFML_sfSprite_setOrigin _CSFML_sfFont_createFromFile _CSFML_sfText_create _CSFML_sfText_setString _CSFML_sfText_setFont _CSFML_sfText_setCharacterSize _CSFML_sfText_setFillColor EXAMPLE:
      Currently I only have one example, which is the "Short example" described in the CSFML API documentation, plus some extra features.  Essentially a window (GUI) allowing you to move a sprite around with the keyboard (including rotation).
      DOWNLOAD:
      You can download this UDF, including the example and associated files, from the following GitHub page:
      https://github.com/seanhaydongriffin/CSFML-UDF
      Cheers,
      Sean.
    • rootx
      By rootx
      how can I fit the image when the GUI is maximized? I would like to always measure the 50% height and width of the GUI and is always in the bottom right poistion, and does not lose its quality.
      THX
       
      #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <GDIPlus.au3> #include <Array.au3> #include <WinAPI.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 615, 437, 192, 124,BitOR($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_TABSTOP)) _GDIPlus_Startup() $hImage = _GDIPlus_ImageLoadFromFile(@ScriptDir&"\img.jpg") $hGraphics = _GDIPlus_GraphicsCreateFromHWND($Form1) $resimg = _GDIPlus_ImageResize($hImage,200,300) _GDIPlus_GraphicsDrawImage($hGraphics, $resimg, 0, 0) GUIRegisterMsg($WM_PAINT, "MY_WM_PAINT") ;GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUISetState(@SW_SHOW,$Form1) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func MY_WM_PAINT($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam, $lParam _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_UPDATENOW) _GDIPlus_GraphicsDrawImage($hGraphics, $resimg, 300, 0) _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_VALIDATE) Return $GUI_RUNDEFMSG EndFunc ;==>MY_WM_PAINT ;Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam) ; #forceref $hWnd, $iMsg, $iwParam, $ilParam ; Local $xClient, $yClient ; $xClient = BitAND($ilParam, 0x0000FFFF) ; $yClient = BitShift($ilParam, 16) ; _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_UPDATENOW) ; _GDIPlus_GraphicsDrawImage($hGraphics, $resimg, $xClient/2, $yClient/2) ; _WinAPI_RedrawWindow($Form1, 0, 0, $RDW_VALIDATE) ; ConsoleWrite($xClient & " "&$yClient&@CR) ; Return $GUI_RUNDEFMSG ;EndFunc  
    • chacoya121
      By chacoya121
      plz help explain between GDI+ and Winapi, is it desktop inside another desktop, 3 layer dimension?
      i can't get the picture
      1. u get desktop u can visual see
      2. then u create GDI+ startup another desktop screen dimension?
      3. then u have Winapi command inside GDI+, is this another desktop screen dimension? cuz GDI+ could create bitmap that is one dimension? Winapi get windowDC also another dimension?
      plz help and explain, with picture would be nice, im not good with visualize ("dumb newbie"), still learning
      newbie to programming world
      thankyou.
    • mdwerne
      By mdwerne
      I'm attempting to cobble together a replacement for the 64bit version of BGInfo that will run within WinPE 10/64. I've located a couple useful threads:
       Between the two, they get me close (see code below), but for some reason GDI+ is not working the same within WinPE as it does in Windows 10. Bottomline is that the "Text" never get's written to WallPaper.
      Here is what I have thus far. Any thoughts if any of the GDI commands might not work within WinPE? Any other way to achieve the same result (system information on the wallpaper in WinPE 10)?
      #include <GDIPlus.au3> #include <Date.au3> _GDIPlus_Startup() $image = _GDIPlus_ImageLoadFromFile(@ScriptDir & "\WallPaper.bmp") $imagegraphics = _GDIPlus_ImageGetGraphicsContext($image) $w = _GDIPlus_ImageGetWidth($image) $h = _GDIPlus_ImageGetHeight($image) $whitebrush = _GDIPlus_BrushCreateSolid(0xFFFFFFFF) $fontfamily = _GDIPlus_FontFamilyCreate("Arial") $font = _GDIPlus_FontCreate($fontfamily, 16) $stringformat = _GDIPlus_StringFormatCreate() _GDIPlus_StringFormatSetAlign($stringformat, 2) $rect = _GDIPlus_RectFCreate(0, $h - $h + 100, $w - 25, $h) ;$rect = _GDIPlus_RectFCreate(100, 100, 200, 200) _GDIPlus_GraphicsDrawStringEx($imagegraphics, _Now() & @CRLF & @UserName & @CRLF & @ComputerName & @CRLF & @IPAddress1, $font, $rect, $stringformat, $whitebrush) _GDIPlus_ImageSaveToFile($image, @ScriptDir & "\NewWallPaper.bmp") _GDIPlus_ImageDispose($image) _GDIPlus_GraphicsDispose($imagegraphics) _GDIPlus_BrushDispose($whitebrush) _GDIPlus_FontFamilyDispose($fontfamily) _GDIPlus_FontDispose($font) _GDIPlus_StringFormatDispose($stringformat) _GDIPlus_Shutdown() _ChangeDesktopWallpaper(@ScriptDir & "\NewWallPaper.bmp", 2) Func _ChangeDesktopWallpaper($bmp, $style = 0) ;=============================================================================== ; ; Function Name: _ChangeDesktopWallPaper ; Description: Update WallPaper Settings ; Usage: _ChangeDesktopWallPaper(@WindowsDir & '\' & 'zapotec.bmp',1) ; Parameter(s): $bmp - Full Path to BitMap File (*.bmp) ; [$style] - 0 = Centered, 1 = Tiled, 2 = Stretched ; Requirement(s): None. ; Return Value(s): On Success - Returns 0 ; On Failure - -1 ; Author(s): FlyingBoz ; Thanks: Larry - DllCall Example - Tested and Working under XPHome and W2K Pro ; Excalibur - Reawakening my interest in Getting This done. ; ;=============================================================================== If Not FileExists($bmp) Then Return -1 ;The $SPI* values could be defined elsewhere via #include - if you conflict, ; remove these, or add if Not IsDeclared "SPI_SETDESKWALLPAPER" Logic Local $SPI_SETDESKWALLPAPER = 20 Local $SPIF_UPDATEINIFILE = 1 Local $SPIF_SENDCHANGE = 2 Local $REG_DESKTOP = "HKEY_CURRENT_USER\Control Panel\Desktop" If $style = 1 Then RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 1) RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", 0) Else RegWrite($REG_DESKTOP, "TileWallPaper", "REG_SZ", 0) RegWrite($REG_DESKTOP, "WallpaperStyle", "REG_SZ", $style) EndIf DllCall("user32.dll", "int", "SystemParametersInfo", _ "int", $SPI_SETDESKWALLPAPER, _ "int", 0, _ "str", $bmp, _ "int", BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE)) Return 0 EndFunc ;==>_ChangeDesktopWallpaper Thanks for your time,
      -Mike