tutorial on cross-compiling blender games

when i first heard about blender, it was from a linux mag - so i assumed that the main part of blenderheads would be linux users. after i found out about blender’s game engine and games made in blender i was thrilled because i thought that this means more games that run under linux natively …well, i was mistaken …(at least on elysiun) we’re still the heavy minority …i’ve nothing against being a minority, but i’d like to be respected. i don’t want much …just the same rights as win* or any other users have :frowning:

now to get to the point:
the problem is mainly the games that run around on elysiun …they’re all (that i’ve seen) just win* binary. i don’t blame the guys for it, in most cases it’s because they don’t know how to port the game. …so i thought that a cross-compiling tutorial for all (and from all) the platforms would solve the problem. …i’m not a coder, so i don’t know how it’s done, but if someone would do it who knows how to, he/she’d be my hero!! :smiley: …please? …pretty please? …someone?

I do agree that most users are Windows based, but that what makes Blender so widely used. I am guessing, but windows, is probably used by atleast 90% of all computer users. Thats why I started using blender, I was able to do things in Blender, that I wasn’t able to do in many other same type programs, beause Blender is Windows friendly. But, I believe that the heart and soul of Blender, and the People who continue to improve it, are basically Linux people. Most Windows users, do not know about programming, or Python, or C/C++ etc… I believe, and I certainly can be wrong, that most of the great people who put alot of their own time and effort to continually improve Blender are not neccassarily Windows users, I believe the opposite to be true. Windows Users are usually the last to be able to try out new things, because they usally would come out first, in a different OS than windows. Thankfully all those great Programmers would not forget about us (The Windows Users) Who on a whole ,do not Know very much about Programming and such. They would eventually get to making such things compatable with the Windows OS… As a Die Hard Windows user, Trying my best to learn Python, a simple script writing Program, and C/C++ a not so simple language, I certainly Respect all those who work hard on Improving Blender. Who I believe many of them use Windows, But most prefer Linux or a different OS. Any way I may be way off, but thats my Opinion. I cant say it enough, I love Blender, It has been a Great Accomplishment, Going back to, Buying the rights and making it open source. What a great accomplishment. And to all those who made it happen, all the hours and effort, and time, that was spent by these people, you all continually amaze me. As a humble user, I again say thanks, for all your efforts, expertise, and time spent, to continually make Blender better and better,every year… I am just a Humble user of this great program, and don’t claim to know what you guys go thru to make it work, but I know it is a lot of effort, and a lobor of love… So I just want to say, Thank You, For continually working deligently on making Blender better all the time, and for a program that continues to give me, and so many others so much joy… THANKS…

The NDNChief… Sorry for going on, and on, and on… :smiley:


Unless I’m missing something, you compile games under Linux exactly the same way
as under Windows ( and it’s one of the Blender’s strenghts)
Just choose the Save runtime in the file menu!!!

Yes but you need to have the linux version installed on linux to create linux executables of your games. What I think silver_hook is saying is that there are loads of great executable blender games out there, but he can’t play them because the authors haven’t released linux executables, because they don’t have linux.

What would be great would be the ability to compile linux executables using the windows version of blender, and vise-versa. Then a game author can release both windows and linux executables for their games - problem solved. :slight_smile:

Keith. 8)

Unfortunately this isn’t possible at the moment.

What people need to do is release at least the .blend’s so that linux users can play the game on their computer. Release the .exe for windows users, because it just makes the games seem more professional, and doesn’t require blender, and the .blend for linux users.

Although we really do need a way to cross-publish.

Some people don’t mind releasing their .blend files, but other people like to release a playable version of their game without giving full access to their models/textures/python scripts etc. The exe format theoretically provides a way of doing this. I wouldn’t attempt to open an EXE on principle, but if someone releases the .blend file for their game, many would take it as an invitation to use the textures/scripts etc inside.

Truthfully blender EXEs aren’t very secure anyway. I’ve found a way of making EXEs and .blend files more secure (i.e. locked using python) but a locked .blend file can’t be compiled by other people anyway so its useless.

A locked .blend could be used with the linux equivilent of the blenderplayer.exe and still be secure, that would work. :slight_smile:

Keith. 8)

I think the devs should add an option in the next release of the game engine. Like you could choose to export the runtime for windows, linux, Mac OSX, and another platforms. This makes sharing games much more easier. :-?

When creating a game give the .blends to a linux user to create the linux compatible .exe for you. Thats all you can really do.

Talking blindly (because I’m not fully familiary with the blender codebase) and just from my experiences, getting that might be more trouble than it’s worth. Lagan’s suggestion is probably more viable… hell, you could get a copy of Knoppix (or Gnoppix), run linux from the CD-ROM and run blender (download and run the executable) to port it to linux that way. And you never have to install linux (although it’d be nice if you did). Just an idea.

I have gnoppix, but I can’t get it to work. Because when I would run it, I have to chance some windows options, and these options are displayed in Ms-dos windows. When I open an ms-dos windows, it will suddenly close autmatic, or close when I move the cursor. So I tried to configure it, but I can’t because of the automatic closing of ms-dos windows. I really hate that, I even can’t see my msconfig windows, that one will also close on mouse move. I think that’s a bug in win xp Prof. :x

Talking blindly (because I’m not fully familiary with the blender codebase) and just from my experiences, getting that might be more trouble than it’s worth. Lagan’s suggestion is probably more viable… hell, you could get a copy of Knoppix (or Gnoppix), run linux from the CD-ROM and run blender (download and run the executable) to port it to linux that way. And you never have to install linux (although it’d be nice if you did). Just an idea.[/quote]

Integrating a multi-OS publishing isn’t that hard.
AFAIK the Blender game executables are the gameplayer and the .blend linked together. So it shouldn’t be a match to use a gameplayer binary for a different OS and do just the same. No need for that much code or magic. There is no compiling or something else inside Blender when exporting a game.
Surely the Blender distribution would get bigger (because there would be an extra binary for each OS) but there could be a special ‘multi-OS publishing package’ (for those who don’t need it).

Oh… that make sense. Disregard my comment in that case.

Most people DO release the .blend file, it makes the game a LOT smaller and easier to download. Usually they’re compressed in a .zip file, but linux people can open that. YOu can lock the file too so people can’t open it (well, at least i think you can, somebody sent out a blend file that i couldn’t open with blender but it autoran when i double-clicked on it, so you mus be able to). Besides, i haven’t heard one complaint about somebody stealing something of somebody’s elses.


I think we can lock them, but if someone steal some codes, I think we should allow that, because Blender is also opensource, but If people steal complete models and gameplay, we should do something. So we allow useing textures, codes, and sensors set up, but not allow stealing models. :slight_smile:

yup, that’s exactly what i meant.

i know cross-compiling (not 100% sure how though) can be done without having those OSes installed …so IMVHO blender could have an export/compile to all the platforms it supports.

publishing .blend files is a solution, but not a very good one if you don’t want to publish it as an open-sourced project which most (win*) users don’t …at least not into broader public.

one ad hoc solution would be to have a forum, locked only to registered users, where each game-dev would post his/her .blend file and people would compile it to whatever platform they use and send it back to the forum or dev/user so the dev/user would then publish the executables to the broader public (e.g. on the web)

p.s. sorry for the wierd phrase-form and usage of words, but i’m a law student and i’m just in the exam-fever :]

sooo …basically that’s it? all agree that there should be done something but we’re not going to do it? …oh come on! …someone surely knows how to cross-sompile. or at least someone can surely open up a closed subforum for the cause.

I think cross-compiling is 1) not a good way to go… you need a compiler and other things I’d rather not see bundled with blender and 2) look at the quote below from kEinStein… it can be done without compiling.

OK here is a python script to do it:
Exports Linux exes from Windows, and Windows exes from Linux.

# Blender Publisher script.
# Creates a Linux or Win32 executable from a blend file.
# Create a Linux exe from Windows, or a Windows exe from Linux!
# You need:
#	blenderplayer for each platform (http://www.blender3d.org/Download/)
#	A CKey for Blender < 2.26
#	A Full python installation (for struct module - HELP! can you do this with native python?)
#	A blender game.

# 1. Save the .blend file.  Compress, Sign and Lock the file if Blender < 2.26
# 2. Set the config below.
# 3. Run this script.  You can run it from within Blender or from a python command line.

# Config: set this appropriately
# The Published Blender executable file: (to be created)
# The .blend file you want to publish:
# The blenderplayer (Other operating system version)

# Copyright (c) 2003 Kester Maddock.  All Rights Reserved.

# ----------------------------------------------------------------------------------------
import struct

# Copy the run time
expgame = file(OUTPUTFILE, "w")
expexe = file(BLENDERPLAYER, "r")
while (1):
	data = expexe.read(8192)
	if (data == ""):
dataoffset = expgame.tell()

# copy the blend data
blend = file(BLENDFILE, "r")
while (1):
	data = blend.read(8192)
	if (data == ""):

# link them together
expgame.write(struct.pack(">L", dataoffset));

# Finished

Can anyone work out how to remove the struct.pack call? That would mean you don’t need a full Python install.

Creating a MacOSX version:

  1. Grab and Unzip the OSX version of Blender.
  2. Blender < 2.26: Sign, Lock & Compress your blend file
  3. Save it as blenderplayer.app/Contents/Resources/game.blend
  4. It has to be called game.blend, not aliens-funkygame.blend or whatever.
  5. Zip up & distribute the blenderplayer.app dir. Mac users will know what to do.

This is how it works in theory - I don’t have a Mac to test with. :slight_smile:

Shouldn’t it be

expgame.write(struct.pack("&lt;L", dataoffset));

on Intel? I mean Intel-CPUs are little endian.
But a great idea using a script for this… Why didn’t come someone else up with it? It isn’t the first time this topic appears. I will try this script.
And yes, you can substitute struct.pack() with an own function. Not that hard, I think. But I will try it later.

Nice spot, but no it is written big endian on all platforms.

See BLO_write_runtime in source/blender/blenloader/intern/writefile.c for how Blender does it internally - this python does it the same way.