Author Topic: Compiling a SDL Game (2023)  (Read 25164 times)

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5256
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Compiling a SDL Game (2023)
« on: August 13, 2023, 05:38:59 pm »
Hello

I would like to compile an SDL (SDL1 or 2) application under ArcaOS as a learning activity and with a long term to try to re-compile some SDL open source games that were compiled long ago, that the DLL dependencies changed with time and now are difficult to run.

My question are:
1) Any recommendation on what can I compile first, so I can tune/test my build environment.
2) Is there some "full screen" feature/library for games working today on OS/2?

Regards
« Last Edit: August 13, 2023, 05:57:16 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5365
  • Karma: +127/-1
    • View Profile
Re: Compiling a SDL Game (2023)
« Reply #1 on: August 13, 2023, 07:31:30 pm »
I just compiled git head of Rocks'n'Diamonds, compiled cleanly.
Code: [Select]
git clone https://git.artsoft.org/rocksndiamonds.git
Needs Perl, SDL2_image, SLD2_mixer, SLD2_net, SLD2 and zlib. And the usual GCC environment.
Only problem is lack of mod support in SDL2_mixer. Not set up to test joystick support. Full screen works fine from the settings-->graphics.
Code: [Select]
K:\work\rocksndiamonds>rocksndiamonds.exe
[WARN] cannot read music file 'K:\work\rocksndiamonds/music/mus_classic/mod.apoplexy': Unrecognized audio format
[WARN] cannot read music file 'K:\work\rocksndiamonds/music/mus_classic/mod.chiptune': Unrecognized audio format
[WARN] cannot read music file 'K:\work\rocksndiamonds/music/mus_classic/mod.cream_of_the_earth': Unrecognized audio format

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5256
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a SDL Game (2023)
« Reply #2 on: August 14, 2023, 02:41:23 am »
Thanks Dave.

I started by installing the following on my development enviroment:
- yum install SDL2-devel SDL2_image-devel SDL2_mixer-devel SDL2_net-devel SDL2_ttf-devel perl zlib-devel pthread-devel libcx-devel

I cloned from here, seems to be same:
- https://github.com/ArtsoftEntertainment/rocksndiamonds

And I did a
- make 2>&1 |tee make.out

It compiled fine and it runs just like you described. The game seems playable and sound works. 
I got the same log that you described.

I don't know if something else can be done to at least start minimized the console that shows the errors.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5365
  • Karma: +127/-1
    • View Profile
Re: Compiling a SDL Game (2023)
« Reply #3 on: August 14, 2023, 06:38:37 am »
Well, best would be to fix SDL2_mixer to use lib-libxmp, which builds fine using cmake or OpenWatcom and makefile.os2, haven't tested if the OW DLL is compatible with GCC.
I just tried that,but SDL2_mixer wants to dynamically load modplug_dll.a instead of modplug1.dll or the planned xmp4.dll. I must have built and installed modplug last year and forgot about it :)
Seems SDL2_mixer is hard coded for modplug
Another option is to create a rocksndiamonds.def declaring it a PM app and link it in.
Quick fix is to do,
Code: [Select]
K:\work\rocksndiamonds>exehdr /PMTYPE:PM rocksndiamonds.exe

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5256
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a SDL Game (2023)
« Reply #4 on: August 15, 2023, 03:35:12 am »
Hello

The same author has another SDL game called MirrorMagic. It also worked.It is a reflection game, you have to move mirrors to destroid things on the screen.

I had created this package with a readme file, please let me know if it works on your side and if it decent enought to call it a release and upload it to hobbes.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5256
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a SDL Game (2023)
« Reply #5 on: August 15, 2023, 03:52:12 am »
Well, best would be to fix SDL2_mixer to use lib-libxmp, which builds fine using cmake or OpenWatcom and makefile.os2, haven't tested if the OW DLL is compatible with GCC.
I just tried that,but SDL2_mixer wants to dynamically load modplug_dll.a instead of modplug1.dll or the planned xmp4.dll. I must have built and installed modplug last year and forgot about it :)
Seems SDL2_mixer is hard coded for modplug
Another option is to create a rocksndiamonds.def declaring it a PM app and link it in.
Quick fix is to do,
Code: [Select]
K:\work\rocksndiamonds>exehdr /PMTYPE:PM rocksndiamonds.exe

Hi Dave

I did the "exehdr /PMTYPE:PM rocksndiamonds.exe" but I can not see any difference.
I got this:
Quote
[C:\DEV\5TRYING\ROCKSNDIAMONDSREL]exehdr /PMTYPE:PM rocksndiamonds.exe

Operating System/2 Executable File Header Utility
Version 4.01.003 Dec 11 2003
Copyright (C) IBM Corporation 1988-2003
Copyright (C) Microsoft Corp. 1988-1992.
All rights reserved.

Module:                         rocksndiamonds

Module type:                    Program
Number of memory pages:         000001df (479)
Initial CS:EIP:                 object 1 offset 00000000
Initial SS:ESP:                 object 3 offset 00100000
Automatic data object:          2
Stack allocation:               00100000 (1048576) bytes

 no. virtual  virtual  map      map      flags
     address   size    index    size
0001 00010000 00196720 00000001 00000197 EXECUTABLE, READABLE, 32-bit
0002 001b0000 03f14f00 00000198 00000048 READABLE, WRITEABLE, 32-bit
0003 040d0000 00100000 000001e0 00000000 READABLE, WRITEABLE, 32-bit


But I had also produced a preliminary release for people to test it, and if everything is fine I will put it on hobbes.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5365
  • Karma: +127/-1
    • View Profile
Re: Compiling a SDL Game (2023)
« Reply #6 on: August 15, 2023, 06:58:01 am »
Hi Martin,
The exehdr command should have turned the exe into a PM app with no console, which I see your build does. Perhaps you added a DEF to get the same results, in which case you could also add bldlevel info.
The binary seems to work fine here.
The text file has a couple of issues, the reference to "SET INCLUDE=C:\usr\include" could have "or similar" added, not everyone installs to C: The link at the bottom is for mirrormagic instead of rocksndiamonds.
Also I don't see any source or patches, I assume you will add that.
I'm still trying to get a version of sdl2 mixer with mod support

David McKenna

  • Hero Member
  • *****
  • Posts: 877
  • Karma: +30/-0
    • View Profile
Re: Compiling a SDL Game (2023)
« Reply #7 on: August 15, 2023, 12:45:50 pm »
 Thanks Martin! Seems to work well here...

Regards,

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5256
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a SDL Game (2023)
« Reply #8 on: August 16, 2023, 05:27:51 am »
Thanks for the feedback.

Hi Martin,
The exehdr command should have turned the exe into a PM app with no console, which I see your build does. Perhaps you added a DEF to get the same results, in which case you could also add bldlevel info.
The binary seems to work fine here.
The text file has a couple of issues, the reference to "SET INCLUDE=C:\usr\include" could have "or similar" added, not everyone installs to C: The link at the bottom is for mirrormagic instead of rocksndiamonds.
Also I don't see any source or patches, I assume you will add that.
I'm still trying to get a version of sdl2 mixer with mod support

I want to do that little details, but the thing that I don't know what is where to change the makefile to include a "rocksndiamonds.def" file.

The source code it's on Github, but there is was no patches needed on the source code to compile:
- https://github.com/OS2World/tAME-SDL-STRATEGY-RocksnDiamonds
- https://github.com/OS2World/GAME-SDL-STRATEGY-MirrorMagic

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5365
  • Karma: +127/-1
    • View Profile
Re: Compiling a SDL Game (2023)
« Reply #9 on: August 16, 2023, 06:32:55 am »
Yea, I got the OS/2 patch accepted a couple of years ago, and originally many years ago for the X version. It was the first program I ever ported.
A simple hack, create a src/rocksndiamonds.def and add this to the makefile
Code: [Select]
diff --git a/src/Makefile b/src/Makefile
index b7289d01..6460d9d3 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -82,7 +82,7 @@ endif

 ifeq ($(shell uname -s),OS/2)          # compiling on OS/2
 PROGNAME = ../$(PROGBASE).exe
-EXTRA_LDFLAGS = -Zomf -Zbin-files -Zmap -lcx -Zhigh-mem
+EXTRA_LDFLAGS = -Zomf -Zbin-files -Zmap -lcx -Zhigh-mem rocksndiamonds.def
 endif

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5256
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a SDL Game (2023)
« Reply #10 on: August 16, 2023, 07:04:11 pm »
Thanks for the feedback, I think I completed the requests.
The source code changes had been pushed to the OS2World repo.

I think I'm going with these versions to put them on hobbes.

Regards
« Last Edit: August 16, 2023, 07:08:20 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5256
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a SDL Game (2023)
« Reply #11 on: August 16, 2023, 07:22:14 pm »
Hello Again.

Now I want to compile this one:
- https://github.com/OS2World/GAME-SDL-STRATEGY-2Pong
I also installed libxml2-devel, since it says it requires that library.

But it looks to me that it requires some code changes to declare the variables.
Here is what I got.
Code: [Select]
g++ -c -pipe -fno-exceptions -Wall -W -O2 -march=i486 -mcpu=i686 -D_REENTRANT `xml2-config --cflags` `sdl-config --cflags` -o CSpriteBase.o CSpriteBase.cpp
C:/usr/bin/sh.exe: 1: xml2-config: not found
C:/usr/bin/sh.exe: 1: sdl-config: not found
g++: warning: '-mcpu=' is deprecated; use '-mtune=' or '-march=' instead
CSpriteBase.cpp: In member function 'int CSpriteBase::init(char*)':
CSpriteBase.cpp:40:40: error: 'SDL_SRCCOLORKEY' was not declared in this scope
   40 |       if(r >= 0) SDL_SetColorKey(temp, SDL_SRCCOLORKEY, SDL_MapRGB(temp->format, r, g, b));
      |                                        ^~~~~~~~~~~~~~~
CSpriteBase.cpp:41:28: error: 'SDL_DisplayFormat' was not declared in this scope; did you mean 'SDL_DisplayEvent'?
   41 |       mAnim[count].image = SDL_DisplayFormat(temp);
      |                            ^~~~~~~~~~~~~~~~~
      |                            SDL_DisplayEvent
CSpriteBase.cpp:45:7: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   45 |       if(!mW) mW = mAnim[count].image->w; if(!mH) mH = mAnim[count].image->w;
      |       ^~
CSpriteBase.cpp:45:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   45 |       if(!mW) mW = mAnim[count].image->w; if(!mH) mH = mAnim[count].image->w;
      |                                           ^~
make: *** [CSpriteBase.o] Error 1
Seems some kind of incompatibility between SDL 1 and SDL2.
- https://discourse.libsdl.org/t/sdl-1-2-to-sdl2-sdl-srccolorkey-sdl-srcalpha/24694

Help (like always) is welcome.


Regards
« Last Edit: August 16, 2023, 07:30:35 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5365
  • Karma: +127/-1
    • View Profile
Re: Compiling a SDL Game (2023)
« Reply #12 on: August 16, 2023, 07:35:54 pm »
Well, the -mcpu is obvious, just use -march=i686.
Doesn't seem to be an SDL_image package available as an RPM, which did you use?

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5256
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a SDL Game (2023)
« Reply #13 on: August 16, 2023, 10:39:25 pm »
Well, the -mcpu is obvious, just use -march=i686.
Doesn't seem to be an SDL_image package available as an RPM, which did you use?

Thanks Dave, for what I see this code is for SDL 1 and I'm trying to compile it with SDL 2.  I'm using "SDL2_image-devel"
I tried to go forward and I saw that some things for SDL1 are not longer used on SDL2, like:
- SDL_SRCCOLORKEY
- SDL_DisplayFormat
- SDL_Flip

(I'm checking this reference: https://wiki.libsdl.org/SDL2/MigrationGuide)

Currently replacing "SDL_Flip" for "SDL_RenderPresent" on 2Pong's NET.CPP  is not being easy for me.
Please don't trust me with the mess I did with "2PONG_B2.zip" file.

Regards
« Last Edit: August 16, 2023, 11:02:17 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 5365
  • Karma: +127/-1
    • View Profile
Re: Compiling a SDL Game (2023)
« Reply #14 on: August 16, 2023, 11:55:04 pm »
Yes, porting from SDL1 to SDL2 is not as trivial as we'd hope. Now I see there is SDL3, which my first try with SDL_image wanted, after checking out a SDL1 version, it isn't happy with our png. There's been a few versions of png too.