Image Buttons with MaxGUI

This time a little tutorial on how to use images as buttons in BlitzMax with MaxGUI module.

For beginners the most important thing is to understand the event loop.

The image buttons are made with panels that have background graphics. The source below clarifies the rest.

In order to try the code, download the following images:








Save the images to the same folder where you save the code below. In order to get the code working with images, name the violet background picture as “demobg.png” and the blue “Button” labeled images as “button1.png” and “button2.png” and the rest “Button” labeled images as “button1sel.png” and “button2sel.png”.

The code uses gadget sensitivity to change the button images when touched with the mouse.

Feel free to use this code.

Using C and DLLs in BlitzMax

BlitzMax apps can be made faster by using C. Also using DLLs in BlitzMax is possible, but that isn’t documented in BlitzMax’s documentation at all.

First, an example of using C code in BlitzMax. As an example we generate the Mandlebrot set using C code to determine does the point belong to the set (see my article on my personal blog on generating the Mandelbrot set, whole example code is in BlitzMax).

To compile the example below, you need to have MinGW configured to BlitzMax.

We start with the C code (save it as mandelbrot.c):


Next the BlitzMax code that uses the C code:

Compile and run the code and you’ll see a blue shaded Mandelbrot set that should look like following:


In the next part of this post we’ll create a DLL in C and call it from BlitzMax.

I’m still mostly using Visual C++ 2008.

The steps to create a DLL:

  • Start Visual C++ and start a new project
  • Select WIN32 console application, name it (in our example Mandelbrot) and press OK
  • Then click ”Next” and select DLL

You’ll get a pre-generated code for a DLL.

The C code for our DLL is following (Mandelbrot.cpp in Visual C++):


The BlitzMax code using the DLL is as follows:

The DLL function is called from a BlitzMax function, because otherwise one would get a EXCEPTION_STACK_OVERFLOW.

When the DLL is called from a function the memory allocated for the DLL-call is local; after returning from the function all the memory allocated for the function call is freed.

As always, this information is free. You may use the codes above in your projects as you wish.



What if BlitzMax full screen application freezes on exit

With Windows 7 BlitzMax full screen applications worked just fine on my system, but after upgrading to Windows 10 I ran into problems: The app started normally, execution of the app was ok, but sometimes when exiting the app, the application freezed. This problem is probably system related problem; on some systems this problem may not exist, but on some systems there is this problem.


It seems that the best solution for best compatibility is to let the user select between full screen and windowed mode. The problem really is Windows 10 related.

I first thought that setting the graphics driver in BlitzMax would help, but eventually the full screen apps freezed on exit… I also tried to set the the graphics driver to D3D11Max2DDriver (DirectX 11) since my system supports it, but that didn’t help either.

Nostalgia: Missile Attack

Again, some nostalgia. I remember, that it was late 80s, when I had a game called “Missile Attack” for Amiga. It was shareware game priced at $5.

Many years ago I made just for fun my own implementation of this classic game in Blitz3D. For curiosity, if my memory serves me right, in Terminator II young John Connor is playing this kind of game in one part of the movie.

In this blog post is shortened version of my Missile Attack game. The code is quite messy. I hope there are not any horrible bugs in this old game. This is the first time the game sees the daylight.

Copy paste the code to Blitz3D and start playing, it’s really quite fun, though quite pointless. 🙂 No external files are needed.


Instructions for playing:

  • Use mouse to shoot the missiles
  • Space bar for full destruction
  • When at least 2 missiles are shot with one shot. the player is rewarded by bigger shot
  • If a missile goes to the side of the screen, player’s energy decreases
  • If missile touches the line at the bottom of the window, the game ends
  • If the player clears the screen by firing, the player is rewarded by giving 3 full destruction balls

The code isn’t really commented, sorry!

How to capture a screenshot from BlitzMax 2D fullscreen game

It’s of course possible to capture a screenshot from BlitzMax fullscreen game with video capture programs such Fraps. It can be also done with the in the BlitzMax code of the game. Here’s my little code to do it:

One must define a Pixmap to which the screen’s content is grabbed. When the contents are grabbed the pixmap is saved as JPEG picture by name “filename.jpg”.

In this example program the screenshot is taken when key c is pressed and saved as jpeg-file.

Hex 2 Dec

In many programming languages there is built-in command or function to convert a decimal value to a hex value. But at least in BlitzMax there isn’t a command or function to convert a hex value to a dec value. In this post I present my little function to convert a hex value to dec value in BlitzMax and in C.

The BlitzMax function:

First, put somewhere in the beginning of your program line

The function itself:

The C version is a complete program that uses its functions:

Be careful with the C version: It doesn’t check if the input is correct. As you can see from the code the letters in the hex number should be given in capital letters. Feel free to use and improve these codes!

How to retrieve the %AppData% folder

AppData folder is used to store data like hiscores, config, etc. of a game (or app). The AppData folder is a special folder that’s location is related to Windows version one is using. This is why AppData folder must be retrieved with the aid of the system.

In Blitz3D retrieving the AppData folder is as simple as this:

AppDataFolder$ = GetEnv$(”AppData”)

In BlitzMax retrieving the AppData folder isn’t this straight forward. The easiest way to get the location of this special folder is to use external module, BAH.Volumes. Once this module is installed for BlitzMax and imported in the beginning of the code, retrieving the AppData folder is as easy as this:

AppDataFolder = GetUserAppDir()

Above is assumed that the variable AppDataFolder is defined as String.

In order to install external modules to BlitzMax, MinGW must be installed and configured for BlitzMax. The BlitzMax product page has a link to forum topic that explains how to set up MinGW for BlitzMax.

Link: BAH.Volumes (from Google Code)


With good old ANSI C the %AppData% folder can be retrieved as follows: