Page 1 of 2 12 LastLast
Results 1 to 10 of 14

Thread: Tutorial #2: Compiling your first SDL game

                  
   
  1. #1

    Default Tutorial #2: Compiling your first SDL game

    EDIT (4/6/05): Upgraded tutorial to use KOS 1.3.x instead of 1.2.0. Uploaded a new makefile to coincide with these changes.

    EDIT (4/5/05): Mental2k suggested adding comments as to what's being done in the steps. This is a good idea, so I'm updating the tutorial series with comments. Comments will be shown in red.

    These tutorials should help you get started with Dreamcast development, even if you haven't coded before in your life. I'm trying to make these as newbie friendly as possible, so if you have any trouble with these, post here and let me know, so I can update them as appropriate. Here's part 2, compiling an SDL game:

    1) Run a command prompt (cmd.exe, command.com depending on your version of Windows)

    2) Type cd\cygwin

    3) Type cygwin.bat

    4) Once inside cygwin,
    a) Type cd /usr/local/dc/kos1.3/kos The KOS directory
    b) Type source environ.sh This loads the dcdevelopment environment variables.

    5) Find a simple SDL port (for our usage right now - it should be pure SDL with no other libraries - no SDL_mixer, etc.).
    a) For our purposes, grab http://www.consolevision.com/members...mcast/pong.zip (from gameprog.it)
    b) extract it's contents to c:\cygwin\usr\local\dc\kos1.3\kos

    6) now:
    a) download http://www.consolevision.com/members...t/makefile.zip
    b) Extract to c:\cygwin\usr\local\dc\kos1.3\kos\pong (overwrite the previous makefile) This is a makefile template. It's easy to update it for your own purposes for other ports.

    7) edit makefile to change all instances of .o extensions to match every .c in the directory:
    - so if you have main.c control.c game.c menu.c
    - you'd have main.o control.o game.o menu.o in your makefile (don't change the .c files themselves, the .o files are just for the object files in the makefile) The .o extension stands for object files. The compiler processes the C code and outputs an object file with an .o extension

    8) look for the main function - could be main() or main(argc, argv) - or something else in the parenthesis.
    a)After the main function, there should be a bracket {
    b)After the bracket, add fs_chdir("/cd"); This sets up the main directory as /cd/ rather than / so that the Dreamcast will recognize it.

    9) Open up all the files and look for SDL_SetVideoMode
    a) make sure the width is either 640 or 320 and the height is 480 or 240, and that SDL_FULLSCREEN is initialized.
    - ex: SDL_SetVideoMode(640, 480, 8, SDL_FULLSCREEN) This sets up the screen size to a Dreamcast compatible screen size. 320x240 and 640x480 are the only ones that should be used on SDL for KOS. KOS supports more resolutions, but SDL KOS only supports 3 of those - the 800x600 resolution that SDL KOS supports is only available on VGA monitor setups.

    10) Now, in cygwin:
    a) type cd /usr/local/dc/kos1.3/kos/pong
    b) type make This command processes your makefile, and sets the compiler in motion to process the c files to object files, then finally to link the object files together into a Dreamcast-compatible elf file.

    Congratulations! You should now have an elf file which is now a workable SDL port.

    You can do this for just about every SDL game that you find. Some are more difficult, but most just require these steps. This doesn't have controller support, or any other Dreamcast specific stuff. We'll look at some of that in tutorial #3.

  2. #2
    DCEmu Coder GPF's Avatar
    Join Date
    Apr 2004
    Location
    Texas
    Age
    52
    Posts
    796
    Rep Power
    78

    Default

    easier step 9 add fs_chdir("/cd"); to the beginning of main()

    so everything automatically starts from the root of the cd, instead of trying to track down everything things thats trying to load.

    Troy

  3. #3

    Default

    Cool - it's good to have someone more skilled than I adding to this.

    Plus you've given me some knowledge that I hadn't previously known, which will cut work down considerably.

  4. #4
    DCEmu Newbie
    Join Date
    Apr 2005
    Posts
    5
    Rep Power
    0

    Default

    I think the pong download is corrupt...

  5. #5

    Default

    Yeah, Xylene pointed that out to me earlier.

    It should work fine now.

  6. #6
    DCEmu Dreamcast ron's Avatar
    Join Date
    Apr 2004
    Location
    MadriDC
    Age
    23
    Posts
    402
    Rep Power
    74

    Default

    >Great tutorial. Thank You
    SH4 Risc LittleEndian

  7. #7
    DCEmu Newbie
    Join Date
    Apr 2005
    Posts
    5
    Rep Power
    0

    Default

    everything works until get to make...then it says this;

    bash: make: command not found

    Did I do something wrong? :S

  8. #8
    DCEmu Coder
    Join Date
    Apr 2004
    Location
    Botoru Battalion
    Age
    51
    Posts
    257
    Rep Power
    74

    Default

    Re-run the Cygwin setup, and when you get to the select packages menu click the "view" button until the "Not Installed" option appears then go down the list and find make, and select it for download. then continue.

  9. #9
    DCEmu Newbie
    Join Date
    Apr 2005
    Location
    WI
    Age
    44
    Posts
    1
    Rep Power
    0

    Default

    I am such a n00b. I can get to the step where we compile the .elf file, but when I enter make, it does it stuff, then spits out some errors ("pong.c:208:warning enumeration value sdlk_fx no handled in switch", for example) with the final statement "Make: *** [pong.elf] Error:1".

    Any ideas?

  10. #10

    Default

    I followed everything, but I think I'm screwing up the part where you initalize the video mode.

    I only found SDL_SetVideoMode in init.c, so that isn't the problem. I get an error when I compile. I may of did this part wrong.

    Code:
      SDL_SetVideoMode(640, 480, 8, SDL_FULLSCREEN)
      // setto la modalita' video da utilizzare
      if ((scr = SDL_SetVideoMode(SCR_W, SCR_H, BPP, flags)) == NULL)
      {
        fprintf(stderr, "\n%s\n", SDL_GetError());
        return -1;
      }
    Did I do that right? :?

    EDIT: I didn't close and save my makefile, so that could of been the problem. I saved it, and I get, "'pause' redeclared as a different type of symbol". Any ideas?

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •