Compiling on Windows
Hi Everyone,
I've been trying to compile OpenGlassBox on Windows. After more than a week, I have finally been able to compile all the dependencies and the main code itself. However, now the code fails to run properly. It is failing on line 38 in main.cpp of the OpenGlassBox code itself. I provide the snippet below. This is trying to load the PNG file that contains the font and it fails to do so, returning a NULL pointer. The window opens up but apart from a dark blue background color, nothing at all is displayed.
Has anyone gotten this to work under Windows? Any help would be much appreciated!! I'm using Microsoft Visual Studio.
Thank you!!
This is the function that's failing:
bool GlassBox::setupGraphics(SDL_Renderer& renderer) { std::string fontpath = m_path.expand("Fonts/font.PNG"); m_fontTexture = IMG_LoadTexture(&renderer, fontpath.c_str()); if (m_fontTexture == nullptr) { std::cerr << "Failed loading font " << fontpath << std::endl; return false; }
m_window.setBackgroundColor(50, 50, 100);
return true;
}
Hi sorry for your pain during all this week 😱 Ill try to adapt my makefile for windows with git bash. You can replace he m_path.expand("Fonts/font.PNG") by the whole path to the texture. Path takes a macro from .makefile to locate in desired folders and you have not define this macro. If the file is found by .extand() the full path is returned else if is not found expand() returns the argument, so the texture loader will search the file in the same folder than your application. The texture loading should not take problems even for windows once the full path is set correctly. Maybe check if the extension is PNG not png.
I believe that it is finding the file itself. The error seems to trace to SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type) in IMG.c where it is looking for the type of image and cannot load the image on line 291 in the call image = supported[i].load(src); where i = 10 for PNG.
Possibly related problem here, but under Linux.
The project builds just fine, however the demo under ./demo/build-release/Demo/Demo does not get created.
Running OpenGlassBox/build/OpenGlassBox-demo instead complains like this:
Parsing script 'Simulations/TestCity.txt'
Failed opening 'Simulations/TestCity.txt' Reason 'No such file or directory'
Creating the Simulations folder and copying the TestCity.txt from demo/data/Simulations results in a seemingly similar issue as described by @patbangert: Failed loading font Fonts/font.png.
Parsing script './Simulations/TestCity.txt'
done
City Paris added
Path Road added
Unit Home 3 added
Unit Home 4 added
Unit Work 5 added
Unit Work 6 added
Map Grass added
Map Water added
City Versailles added
Map Grass added
Map Water added
Path Road added
Unit Home 7 added
Unit Work 2 added
Failed loading font Fonts/font.png
Hi sorry for your pain during all this week 😱 Ill try to adapt my makefile for windows with git bash. You can replace he m_path.expand("Fonts/font.PNG") by the whole path to the texture. Path takes a macro from .makefile to locate in desired folders and you have not define this macro. If the file is found by .extand() the full path is returned else if is not found expand() returns the argument, so the texture loader will search the file in the same folder than your application. The texture loading should not take problems even for windows once the full path is set correctly. Maybe check if the extension is PNG not png.
Fixing the path[1] in demo/src/main.cpp line 37 did the trick for me in addition to running the binary in OpenGlassBox/build/OpenGlassBox-demo after creating the Simulations folder and copying TestCity.txt from demo/data/Simulations. make clean and make all to build again.
[1] meaning I gave the absolute path as argument to m_path.expand(). I tested a couple of partial/relative paths which did not work for some reason.
@patbangert @BenitoEck I cannot test on Windows since last time I had to reinstall my Linux and I lost my Windows VM.
Anyway:
- the data folder not find was due to MyMakefile issue: it generates path to find files inside data but I have to update it to also located in demo/data. So I moved the data folder.
- I updated MyMakefile and now I'm tracking the dearimgui and the second repo imgui_sdl is no longer needed.
- I cleaned a little my includes, fix English and asked IA to rewrite my README.
@patbangert @BenitoEck I have to check if CI pass before you can update the HEAD.
Thanks for tending to this so promptly. However I still have to manuall copy the Simulations folder to the demo binary to make it work (unlike the description in the README) and the path issue seems not to be resolved, although I get a slightly different error message now:
Failed loading font 'Fonts/font.png' from one of the following folders: /home/myuser/.local/share/OpenGlassBox/0.2.0/data:/usr/local/share/OpenGlassBox/0.2.0/data:/home/myuser/foo/bar/OpenGlassBox/data:.
P.S.: I deleted two earliers comments that are no longer relevant to the current state.
@BenitoEck Not anymore with the last bunch of commits (once Linux and MacOs will succeeded). You will need to type: git submodule --update and rm -fr build folder
Don't think that's it. I wiped the local repo to be sure to start from a clean slate. ~~Also giving the absolute path as before does not work any longer.~~
@BenitoEck yes now you can update. I was git push force
I saw the latest changes, confirmend them, cleaned up, updated and build the project in several ways from scratch. The issues remain unchanged. However the workarounds (giving absolute path, copy Simulations folder) still work for my, so I'll call it day. Thanks.
@BenitoEck which Linux do you have ?
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
@BenitoEck You have made sudo make install ? I'm seeing issued with MyMakfile
No, I followed the description from the Readme:
make download-external-libs
make CXX=g++ -j8
or alternatively make all or make build-demo. But that does not change the result.
I did not plan to install the project and the Readme states this step as optional. But since you asked I installed it via sudo make install, which does not change the situation, at least for me.
Instead when it installs the docs, it copies the complete build path to usr/local/share e.g. /usr/local/share/OpenGlassBox/0.2.0/home/myuser/foo/bar/baz/OpenGlassBox/doc while the search paths for Fonts/font.png which are /home/myuser/.local/share/OpenGlassBox/0.2.0/data:/usr/local/share/OpenGlassBox/0.2.0/data:/home/myuser/foo/bar/baz/OpenGlassBox/data remain empty still after installation.
To me it looks like the paths are build wrong or I misunderstand the Readme file. However, I found a workaround and willl now stop investigating this issue. Thanks and good luck.
Because you did not make git submodule update your issue is fixed now. Do not do make install yet I noticed demo/data is not installed (while the /user/local path is fixed). The CI using Ubuntu works. I agree MyMakefile was not my best idea, I should use cmake like everyone 😪