OS2 World Community Forum

OS/2, eCS & ArcaOS - Technical => Programming => Topic started by: Martin Iturbide on August 13, 2023, 05:38:59 pm

Title: Compiling a SDL Game (2023)
Post by: Martin Iturbide 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
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo 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
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide 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
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo 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
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide 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
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide 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
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo 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
Title: Re: Compiling a SDL Game (2023)
Post by: David McKenna on August 15, 2023, 12:45:50 pm
 Thanks Martin! Seems to work well here...

Regards,
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide 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
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo 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
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide 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
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide 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
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo 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?
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide 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
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo 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.
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide on August 18, 2023, 03:51:40 pm
Hi Dave

On RocksnDiamonds and MirrorMagic I was able to hide the console with your indications (the DEF file and even with exehdr).
Now the console don't show, just as I wanted to. But is there a way for the user to see that console if he needs to generate some log.

Regards
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo on August 18, 2023, 04:55:47 pm
Redirect stdout and stderr to a file. By habit I do "rocksndiamonds 2>&1 | tee rocksndiamonds.log" as I always forget the other way without tee.
Title: Re: Compiling a SDL Game (2023)
Post by: Jochen Schäfer on August 18, 2023, 04:56:49 pm
Redirect stdout and stderr to a file. By habit I do "rocksndiamonds 2>&1 | tee rocksndiamonds.log" as I always forget the other way without tee.
Exactly what I did with FeatherPad.
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide on August 21, 2023, 04:08:08 am
Hi.

I was checking lbreakoutHD, it uses SDL2.
- https://sourceforge.net/projects/lgames/files/lbreakouthd/lbreakouthd-1.1.3.tar.gz

But it has two makefiles, makefile.in and makefile.am, that I don't know how to run. Is there any trick or an specific make tool to see if they can compile?

Regards

Title: Re: Compiling a SDL Game (2023)
Post by: Mentore on August 21, 2023, 08:17:57 am
Hi.

I was checking lbreakoutHD, it uses SDL2.
- https://sourceforge.net/projects/lgames/files/lbreakouthd/lbreakouthd-1.1.3.tar.gz

But it has two makefiles, makefile.in and makefile.am, that I don't know how to run. Is there any trick or an specific make tool to see if they can compile?

Regards

Hi Martin,
though I don't remember very well, makefile.in and makefile.am should be a part of the automake package and are needed by the configure shell script.
You may find useful to follow Paul Smedley's rules on compiling Unix ports. It may be as easy as writing "sh configure" or something like this (alas, I don't use an OS/2 machine since ages).

Mentore
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo on August 22, 2023, 02:29:11 am
Hi.

I was checking lbreakoutHD, it uses SDL2.
- https://sourceforge.net/projects/lgames/files/lbreakouthd/lbreakouthd-1.1.3.tar.gz

But it has two makefiles, makefile.in and makefile.am, that I don't know how to run. Is there any trick or an specific make tool to see if they can compile?

Regards

Hi, automake takes makefile.am and outputs makefile.in and configure inputs makefile.in and outputs makefile.
We need to rebuild all the auto stuff to make it work on OS/2, best to run autoreconf, in the root of the source,
Code: [Select]
sh $UNIXROOT/usr/bin/autoreconf -sfi

Which will do all the aclocal, automake, libtoolize and autoconf stuff. Also sometimes there is an autogen.sh which can be run to produce the auto files

Edit: fix the autoreconf parameter
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo on August 22, 2023, 04:11:55 am
Once the updated configure script is generated, it is a good idea to run "sh configure --help 2&1 | tee configure.hlp" to see if there are any interesting parameters to pass and then run "sh configure 'LDFLAGS=-Zomf' 'LIBS=-lcx'" I think that is the right quoting. Add other parameters before LDFLAGS, things like --prefix=[path to install to, such as X:/tmp/lbreakout].
IIRC, lbreakout had problems with where to store the high scores on OS/2.
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo on August 22, 2023, 05:22:11 pm
Tried compiling the version of lbreakout that you mentioned,
Code: [Select]
H:\tmp\lbreakouthd-1.1.3>sh w:/usr/bin/autoreconf -sfi
configure.ac:4: error: Autoconf version 2.71 or higher is required

So we need an autoconf update as ours is 2.69. Guess try an older version of lbreakout.
edit: changing the AC_PREREQ line from 2.71 to 2.69 seems all that is required to run autoconf successfully
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo on August 22, 2023, 05:45:17 pm
OK built it with
Code: [Select]
sh configure --prefix=h:/tmp/lbreakouthd 'LDFLAGS=-Zomf -Zmap -Zbin-files -Zhigh-mem' LIBS=-lcx
make 2>&1 | tee make.log
make install

It got confused by my aspect ratio, see https://sourceforge.net/p/lgames/bugs/102/ (https://sourceforge.net/p/lgames/bugs/102/) and also the title was above my screen. Biggest problem is that it is slow, much slower then lbreakout2 and not fun to play. Probably expects accelerated 3D support.
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide on August 22, 2023, 06:43:40 pm
OK built it with
Code: [Select]
sh configure --prefix=h:/tmp/lbreakouthd 'LDFLAGS=-Zomf -Zmap -Zbin-files -Zhigh-mem' LIBS=-lcx
make 2>&1 | tee make.log
make install

It got confused by my aspect ratio, see https://sourceforge.net/p/lgames/bugs/102/ (https://sourceforge.net/p/lgames/bugs/102/) and also the title was above my screen. Biggest problem is that it is slow, much slower then lbreakout2 and not fun to play. Probably expects accelerated 3D support.


Thanks Dave.

I'm getting this:

Quote
[C:\DEV\5TRYING\LBREAKOUTHD-1.1.3]sh configure --prefix=C:/tmp/lbreakouthd 'LDFLAGS=-Zomf -Zmap -Zbin-files -Zhigh-mem' LIBS=-lcx
checking for a BSD-compatible install... ./install-sh -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... no
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... no
checking for cc... no
checking for cl.exe... no
checking for clang... no

[C:\DEV\5TRYING\LBREAKOUTHD-1.1.3]make   2>&1  | tee make.log
make: *** No targets specified and no makefile found.  Stop.

[C:\DEV\5TRYING\LBREAKOUTHD-1.1.3]make install
make: Nothing to be done for `install'.

It is like make does not find the makefine.

Regards
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide on August 22, 2023, 06:44:31 pm
OK built it with
Code: [Select]
sh configure --prefix=h:/tmp/lbreakouthd 'LDFLAGS=-Zomf -Zmap -Zbin-files -Zhigh-mem' LIBS=-lcx
make 2>&1 | tee make.log
make install

It got confused by my aspect ratio, see https://sourceforge.net/p/lgames/bugs/102/ (https://sourceforge.net/p/lgames/bugs/102/) and also the title was above my screen. Biggest problem is that it is slow, much slower then lbreakout2 and not fun to play. Probably expects accelerated 3D support.

Thanks Dave.

I'm getting this:

Quote
[C:\DEV\5TRYING\LBREAKOUTHD-1.1.3]sh configure --prefix=C:/tmp/lbreakouthd 'LDFLAGS=-Zomf -Zmap -Zbin-files -Zhigh-mem' LIBS=-lcx
checking for a BSD-compatible install... ./install-sh -c
checking whether build environment is sane... yes
checking for a race-free mkdir -p... ./install-sh -c -d
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... no
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
checking whether make supports the include directive... yes (GNU style)
checking for gcc... no
checking for cc... no
checking for cl.exe... no
checking for clang... no

[C:\DEV\5TRYING\LBREAKOUTHD-1.1.3]make   2>&1  | tee make.log
make: *** No targets specified and no makefile found.  Stop.

[C:\DEV\5TRYING\LBREAKOUTHD-1.1.3]make install
make: Nothing to be done for `install'.

I don't know why it says that can not find gcc, it is on my path.
It is like make does not find the makefile.

Regards
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo on August 22, 2023, 07:38:29 pm
You did do the autoreconf part first? It looks like you didn't and exeext=.exe is not set.
Edit: or you're missing something in the autotools department. autoconf, automake, libtool, libtool-ltdl-dev m4 and whatever I'm forgetting. Or possibly you are pulling in utilities from \os2 instead of @unixroot\usr.
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide on August 22, 2023, 09:17:22 pm
My mistake, I forgot this:
edit: changing the AC_PREREQ line from 2.71 to 2.69 seems all that is required to run autoconf successfully
Title: Re: Compiling a SDL Game (2023)
Post by: Martin Iturbide on August 22, 2023, 10:46:18 pm
Hello Dave

It compiled and runs. Yes, I have the same issue, it is unplayable because it is very slow. But I think it had been a good learning experience with automake.

Regards
Title: Re: Compiling a SDL Game (2023)
Post by: Dave Yeo on August 22, 2023, 11:49:03 pm
I tried building lbreakout2, something I've done before. No joy, configure didn't add some libs (png, intl and SDL) and the level stuff is screwed up.
Code: [Select]
H:\tmp\lbreakout2-2.6.5\client>lbreakout2.exe
LBreakout2 2.6.5
Copyright 2001-2011 Michael Speck
Published under GNU GPL
---
Looking up data in: .
Looking up highscores in: .
Looking up custom levels in: W:\Home/.lgames/lbreakout2-levels
Compiled without sound and music
W:\Home/.lgames/lbreakout2.conf: file not found
Loading theme 'AbsoluteB'
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/bricks.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/bricks.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/paddle.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/paddle.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/weapon.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/weapon.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/shot.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/shot.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/extras.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/extras.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/fr_left.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/fr_left.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/fr_top.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/fr_top.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/fr_right.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/fr_right.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/life.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/life.png
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/back0.png
Fatal STK Error!
Couldn't open ./gfx/H:/tmp/lbreakout2-2.6.5/client/gfx/AbsoluteB/back0.png
GUI finalized
STK finalized
SDL finalized

Note the PATHS start with .gfx/H:
LBreakout2 is quite playable, lots of additional levels available, likely the same levels as LBreakout_hd uses.