============
ColorEater3D
============

Copyright (C) Alex Thomson. All rights reserved.

  =================================
  License for Program & Source Code
  =================================

  This program is free software; you can redistribute it and/or modify it under
  the terms of the GNU General Public License as published by the Free Software
  Foundation; either version 2 of the License, or (at your option) any later 
  version.

  This program is distributed in the hope that it will be useful, but WITHOUT
  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

  You should have received a copy of the GNU General Public License along with
  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  Place, Suite 330, Boston, MA 02111-1307 USA.

  Note: The music and sound files distributed for use with this game are under
  seperate licenses from the program and its source code, as described in
  'Sound/License.txt'.


  =======================================
  What tools were used to make this game?
  =======================================

Short answer:
  Programming was done in FreeBASIC
  using SDL as a crossplatform API.

Long answer:
 - SDL was used for basic I/O (keyboard/mouse/window)
 - OpenGL was used for graphics
 - Textures were created using GIMP and loaded using fbpng, which itself uses zlib
 - The font used was modified from screen mode 13 DOS font and embedded in the source for reliability
 - SDL_Mixer was used for music and sound effects
 - Music and Sound effects were downloaded from public internet sites and converted to ogg using Audacity
 - All models were generated by code (see SpriteInit(), MakeSnakeMesh())
 - All levels were generated by code (see GenLevel(), OrbPosnValid())
 - All code is in FreeBASIC except for the fragment shader which is written in GL Shader Language to run on the GPU.


  =========================
  Can I make my own levels?
  =========================

  Yes, you will need to edit modLevel.bas and recompile though.  See "MakingLevels.txt"

  =========
  Compiling
  =========

Compiling requires the fbpng library (version 3.2.q)

Discussion: http://www.freebasic.net/forum/viewtopic.php?t=8024
Download: http://www.mediafire.com/download.php?avx5a8d5lec9kcb

  "Once compiled you will need two files, 'build/libfbpng.a' and 'inc/fbpng.bi'.  These
  should be placed either in your projects directory, or in the lib/ and inc/ dirs of your
  FreeBASIC installation, along with the other libary and header files.  On Linux the
  correct directories are likely to be /usr/include/freebasic/ and /usr/lib/freebasic/linux/"


  ====================
  Compiling on Windows
  ====================

fbc -s gui "ColorEater3D.bas" "ColorEater3D.rc" "modGeometry.bas" "modGUI.bas" "modVoxel.bas" "modSprite.bas" "modLevel.bas"


  ==================
  Compiling on Linux
  ==================

fbc "ColorEater3D.bas" "modGeometry.bas" "modGUI.bas" "modVoxel.bas" "modSprite.bas" "modLevel.bas"

And ensure that you have needed packages. ex:
sudo apt-get install libSDL-mixer1.2-dev

  ===================
  Compiling on MacOSX in 10 EZ Steps
  ===================

Note that I have provided some of the more useful intermediate files in the 'Mac' folder,
these directions however should be sufficent to compile from the .bas source files.  However,
It may still be neccissary to build new object files if you wish to attempt to build for a
non intel mac, or use a different compiler.

_________________________________________
1) Set Up FreeBASIC with GCC for -gen GCC

http://www.freebasic.net/forum/viewtopic.php?t=18465

__________________
2) Create .c files

On Windows run:
fbc -s gui -gen gcc -R -Wc -O2 "ColorEater3D.bas" "modGeometry.bas" "modGUI.bas" "modVoxel.bas" "modSprite.bas" "modLevel.bas"

This will produce "ColorEater3D.c", "modGeometry.c", "modGUI.c", "modVoxel.c", "modSprite.c", "modLevel.c", and "ColorEater3D.exe".
Test "ColorEater3D.exe" to see if it runs the same as the gas executable (produced using the normal compile line).

__________________
3) Get GCC for Mac

3.1 - Register as an Apple Developer

  You do not need to become a paying member of the Mac Developer Program, but you will
  have to provide information about yourself and the target audience of your software.

  http://developer.apple.com/programs/register/

3.2 - Download XCode

  Get XCode 3.2 if OS 10.6, XCode 4.2 if OS 10.7
  For me XCode 3.2.6 was a 10 GB download so this may take some time.

  Download: http://mac.softpedia.com/progDownload/Apple-Xcode-Download-7935.html
  Information: http://developer.apple.com/support/xcode/

Open a Terminal and type: gcc
If it complains about missing input/source files, you have gcc.

_________________________________________
4) Compile Sources to object files on Mac


Use option -D __stdcall__="" to automatically remove windows calling conventions from the sources.
On 64 bit Mac you must use -m32 option to force 32 bit output.

gcc -m32 -D __stdcall__="" modGeometry.c -c -o modGeometry.o
gcc -m32 -D __stdcall__="" modGUI.c -c -o modGUI.o
gcc -m32 -D __stdcall__="" modVoxel.c -c -o modVoxel.o
gcc -m32 -D __stdcall__="" modSprite.c -c -o modSprite.o
gcc -m32 -D __stdcall__="" modLevel.c -c -o modLevel.o

before compiling ColorEater3D.c, find (in ColorEater3D.c):
integer main( integer __FB_ARGC__$, char** __FB_ARGV__$ )
and replace it with:
integer SDL_main( integer __FB_ARGC__$, char** __FB_ARGV__$ )

I suppose using option -D main=SDL_main may also work

gcc -m32 -D main=SDL_main -D __stdcall__="" ColorEater3D.c -c -o ColorEater3D.o

You will also need to compile my operatornew.c
(the one in the Mac folder which has the array versions of operator new/delete)
gcc -m32 operatornew.c -c -o operatornew.o

______________________________________
5) Repeat steps 1-4 with fbpng sources

On Windows run the batch file included with fbpng:
bwin32 -gen gcc -R -Wc -O2

.c files will appear in the subfolder src/o

Note: You may need to remove calls to fb_GfxImageInfo from png_gfxlib2.c because
that might introduce an fbgfx dependency.

gcc -m32 -D __stdcall__="" src/o/file_to_buffer.c -c -o src/o/file_to_buffer.o 
gcc -m32 -D __stdcall__="" src/o/IDAT.c -c -o src/o/IDAT.o 
gcc -m32 -D __stdcall__="" src/o/IHDR.c -c -o src/o/IHDR.o 
gcc -m32 -D __stdcall__="" src/o/PLTE.c -c -o src/o/PLTE.o 
gcc -m32 -D __stdcall__="" src/o/plte_conv.c -c -o src/o/plte_conv.o 
gcc -m32 -D __stdcall__="" src/o/png_destroy.c -c -o src/o/png_destroy.o 
gcc -m32 -D __stdcall__="" src/o/png_dimensions.c -c -o src/o/png_dimensions.o 
gcc -m32 -D __stdcall__="" src/o/png_gfxlib2.c -c -o src/o/png_gfxlib2.o 
gcc -m32 -D __stdcall__="" src/o/png_image.c -c -o src/o/png_image.o 
gcc -m32 -D __stdcall__="" src/o/png_image_convert.c -c -o src/o/png_image_convert.o 
gcc -m32 -D __stdcall__="" src/o/png_image_deinit.c -c -o src/o/png_image_deinit.o 
gcc -m32 -D __stdcall__="" src/o/png_image_init.c -c -o src/o/png_image_init.o 
gcc -m32 -D __stdcall__="" src/o/png_image_prepare.c -c -o src/o/png_image_prepare.o 
gcc -m32 -D __stdcall__="" src/o/png_image_store.c -c -o src/o/png_image_store.o 
gcc -m32 -D __stdcall__="" src/o/png_load.c -c -o src/o/png_load.o 
gcc -m32 -D __stdcall__="" src/o/png_load2.c -c -o src/o/png_load2.o 
gcc -m32 -D __stdcall__="" src/o/png_memory.c -c -o src/o/png_memory.o 
gcc -m32 -D __stdcall__="" src/o/png_opengl.c -c -o src/o/png_opengl.o 
gcc -m32 -D __stdcall__="" src/o/png_pixelformat.c -c -o src/o/png_pixelformat.o 
gcc -m32 -D __stdcall__="" src/o/png_save.c -c -o src/o/png_save.o 
gcc -m32 -D __stdcall__="" src/o/png_save2.c -c -o src/o/png_save2.o 
gcc -m32 -D __stdcall__="" src/o/png_tables.c -c -o src/o/png_tables.o 
gcc -m32 -D __stdcall__="" src/o/row_conv_abgr32.c -c -o src/o/row_conv_abgr32.o 
gcc -m32 -D __stdcall__="" src/o/row_conv_argb32.c -c -o src/o/row_conv_argb32.o 
gcc -m32 -D __stdcall__="" src/o/row_conv_p8.c -c -o src/o/row_conv_p8.o 
gcc -m32 -D __stdcall__="" src/o/row_conv_rgb16.c -c -o src/o/row_conv_rgb16.o 
gcc -m32 -D __stdcall__="" src/o/row_conv_rgb32.c -c -o src/o/row_conv_rgb32.o 
gcc -m32 -D __stdcall__="" src/o/tRNS.c -c -o src/o/tRNS.o 


____________________________________________________
6) Obtain the .c sources for rtlib (FreeBSD version)

The .c sources of rtlib are in the FreeBASIC/src/rtlib sub folder of the freebasic sources.
Download: http://sourceforge.net/projects/fbc/files/Source%20Code/

____________________________________________
7) Compile the FreeBSD rtlib on Mac with GCC

Discussion: http://www.freebasic.net/forum/viewtopic.php?p=133598

Copy the files in rtlib/freebsd to rtlib/darwin
and read INSTALL for directions on generating and running the makefile.

Add -mstackrealign and if running 64bit mac, add -m32 option, by editing the makefile:
ie replace:
CFLAGS = -g -O2
with:
CFLAGS = -m32 -mstackrealign -g -O2


Prebuilt libfb.a can also be downloaded from:
http://hamsterrepublic.com/ohrrpgce/Compiling_in_Mac_OS_X.html
http://dl.dropbox.com/u/16291524/fbc-mac-20101006-2.tar.bz2

Decompress and look in the fbc-mac/lib/darwin/ folder for libfb.a


__________________________________________________________
8) Obtain runtime linking libraries for SDL (Mac Versions)

http://www.libsdl.org/download-1.2.php
http://www.libsdl.org/projects/SDL_mixer/

After downloading the MacOS .dmg files, you must then install them their files to the framework folder
by dragging the .dmg file into the 'applications' folder.

You also need to go through the files and find SDLMain.m and compile it using something like:
gcc -m32 -I/Library/Frameworks/SDL.framework/Versions/A/Headers -c SDLMain.m -o SDLMain.o

_______
9) Link

By now you should have all the object files you need.  Simply place them all in a folder and invoke:

gcc -m32 -L.../darwin/ -lfb -lz -lncurses -framework SDL -framework SDL_mixer -framework OpenGL -framework Cocoa *.o -o ColorEater3D

where .../darwin/ is the path to where you are keeping libfb.a

_______
10) RUN

./ColorEater3D
If it failed, figure out why and repeat steps 1-10
else
   ..gasp
end if