remove unsupported gl functions from emscripten builds, restore removing gl context settings from emscripten builds
This commit is contained in:
parent
0bf2e12935
commit
52ef535eac
88
README.md
88
README.md
|
@ -12,13 +12,11 @@ SPACE BOX
|
|||
| ~~~~~~~ BOX |/
|
||||
+--------------+ </pre>
|
||||
|
||||
[SPACE BOX] is a C++ framework that facilitates the creation of SDL + OpenGL projects through the use of generic objects that can be used and extended by the programmer. It focuses on game projects but its usefulness is not limited to games.
|
||||
[SPACE BOX] is a C++ framework that makes creating cross-platform games and other interactive applications easier and faster by providing an added layer of abstraction between SDL + OpenGL and the project.
|
||||
|
||||
The main intention for the project is to make running cross-platform applications easier and more immediate by providing a universal tool set that exists as a hidden, extensible layer between SDL + OpenGL and the project.
|
||||
Users can start a project by extending only a single function, the Game class's update function. Using a standard Makefile that can be taken from the examples, the framework can export the same code to multiple platforms like PC, OS/X, Linux, Web GL, Raspberry Pi, and Android.
|
||||
|
||||
An important quality of the framework is it should allow the programmer to start a project by extending only a single function, the Game class's update function. Additionally, the framework should by default create applications that can be easily exported to many platforms (PC, OS/X, Linux, Web GL, Raspberry Pi, and Android) by using a standard Makefile.
|
||||
|
||||
It is in an early, untested state. It comes with a few simple examples that demonstrate how in can be used to create interactive graphics programs.
|
||||
It is in an early, untested state. It comes with a few simple examples that demonstrate how to use it.
|
||||
|
||||
Requirements
|
||||
------------
|
||||
|
@ -40,7 +38,7 @@ libSDL2, libSDL2-image, libSDL2-ttf, and libSDL2-mixer must be available to link
|
|||
### libSDL2
|
||||
|
||||
* Download from <http://libsdl.org/download-2.0.php>
|
||||
* Run ./configure --prefix=[YOUR LIBRARIES PATH] (I'm using $HOME/local/sdl)
|
||||
* Run ./configure --prefix=[YOUR LIBRARIES PATH] (for example, $HOME/local/sdl)
|
||||
* Run make && make install
|
||||
|
||||
### libSDL2-image, libSDL2-ttf, libSDL2-mixer
|
||||
|
@ -50,7 +48,7 @@ libSDL2, libSDL2-image, libSDL2-ttf, and libSDL2-mixer must be available to link
|
|||
* <https://github.com/libsdl-org/SDL_ttf>
|
||||
* <https://github.com/libsdl-org/SDL_mixer>
|
||||
* Run ./configure --prefix=[YOUR LIB PATH] --with-sdl-prefix=[YOUR SDL PATH]
|
||||
* In my case, prefix and SDL prefix are both $HOME/local/sdl
|
||||
* For example, prefix and SDL prefix can be $HOME/local/sdl
|
||||
|
||||
### OpenGL/GLES/GLES2
|
||||
|
||||
|
@ -71,9 +69,7 @@ Test collision detection between a 2D sprite and other 2D sprites and boxes. Per
|
|||
|
||||
### squircle
|
||||
|
||||
Map an image from a rectangle to a circle or from a circle to a rectangle using a shader program. Based on the elliptical grid mapping equations at:
|
||||
|
||||
* <http://squircular.blogspot.com/2015/09/mapping-circle-to-square.html>
|
||||
Map an image from a rectangle to a circle or from a circle to a rectangle using a shader program. Based on the elliptical grid mapping equations at http://squircular.blogspot.com/2015/09/mapping-circle-to-square.html
|
||||
|
||||
|
||||
Other libraries
|
||||
|
@ -83,24 +79,54 @@ These are other libraries that have been used in projects that use this framewor
|
|||
|
||||
### opencv
|
||||
|
||||
Download from <https://opencv.org/releases/> and configure (with custom installation path):
|
||||
#### Linux
|
||||
|
||||
cmake -DCMAKE_INSTALL_PREFIX=$HOME/local/opencv ..
|
||||
Download from https://opencv.org/releases/ and configure (with custom installation path) and make:
|
||||
|
||||
make:
|
||||
$ cmake -DCMAKE_INSTALL_PREFIX=$HOME/local/opencv ..
|
||||
$ make && make install
|
||||
|
||||
The libraries can then be linked by adding the following to the linker flags:
|
||||
|
||||
make && make install
|
||||
-L$(HOME)/local/opencv/lib -Wl,-rpath,$(HOME)/local/opencv/lib -lopencv_videoio -lopencv_core -lopencv_highgui \
|
||||
-lopencv_imgproc
|
||||
|
||||
The specific modules needed at the end of that list may vary depending on the project. There are detailed instructions for building OpenCV on Linux available at https://docs.opencv.org/4.6.0/d7/d9f/tutorial_linux_install.html
|
||||
|
||||
#### Emscripten
|
||||
|
||||
To build the WASM libraries necessary to include OpenCV in an Emscripten build of a SPACEBOX project, set up the Emscripten environment and run OpenCV's `build_js.py` script with the WASM output option. Note that OpenCV's `cv::VideoCapture` object will not be available in the libraries built this way because OpenCV emulates that object in its JS implementation.
|
||||
|
||||
$ source [EMSDK_PATH]/emsdk_env.sh
|
||||
$ python3 [OPENCV_PATH]/platforms/js/build_js.py --emscripten_dir [EMSCRIPTEN_PATH] build_wasm --build_wasm
|
||||
|
||||
There is a detailed explanation of this process at https://docs.opencv.org/4.6.0/d4/da1/tutorial_js_setup.html And useful information for getting around the absence of `cv::VideoCapture` at https://docs.opencv.org/4.6.0/dd/d00/tutorial_js_video_display.html Check out a minimal example of using OpenCV with C++ and Emscripten at https://github.com/mpizenberg/emscripten-opencv
|
||||
|
||||
### zbar
|
||||
|
||||
Download from <http://zbar.sourceforge.net/download.html> and configure to only use image processing features (requires imagemagick) and choose your installation directory:
|
||||
#### Linux
|
||||
|
||||
./configure --without-gtk --without-python --without-qt --disable-video \
|
||||
--prefix=$HOME/local/zbar
|
||||
Download from http://zbar.sourceforge.net/download.html and configure to only use image processing features (requires the imagemagickwand library, available from, for example `apt get libmagickwand-dev`) and choose your installation directory:
|
||||
|
||||
./configure --without-gtk --without-python --without-qt --without-xshm --without-xv --without-jpeg \
|
||||
--disable-video --prefix=$HOME/local/zbar
|
||||
|
||||
make
|
||||
|
||||
make && make install
|
||||
|
||||
#### Emscripten
|
||||
|
||||
To build a WASM library that can be used to build an Emscripten version of a SPACEBOX project, set up the Emscripten environment and configure using `emconfigure` with the same disable flags as above.
|
||||
|
||||
$ source emsdk_env.sh
|
||||
$ emconfigure ./configure --without-gtk --without-python --without-qt --without-xshm --without-xv --without-jpeg \
|
||||
--disable-video
|
||||
$ emmake make
|
||||
$ find . -iname *.a
|
||||
./zbar/.libs/libzbar.a
|
||||
|
||||
There is a detailed tutorial on using Zbar with Web Assembly at https://barkeywolf.consulting/posts/barcode-scanner-webassembly/
|
||||
|
||||
Font
|
||||
----
|
||||
|
@ -110,26 +136,20 @@ When initializing a Game object, the framework will attempt to load the font fil
|
|||
License
|
||||
-------
|
||||
|
||||
The original code for this framework is licensed to freely use, copy, modify and sell, without restriction under the zlib license. See LICENSE.txt for details.
|
||||
SPACEBOX is released under the zlib license. It is free to use, copy, modify and sell. See LICENSE.txt for details.
|
||||
|
||||
Included libraries are included under various permissive licenses:
|
||||
Included libraries are included under various permissive licenses compatible with the zlib license:
|
||||
|
||||
* BPmono.ttf is licensed under the Creative Commons Attribution - No Derivative Works 3.0 license. See LICENSE_BPmono.txt for details.
|
||||
|
||||
* gif-h is unlicensed, public domain code released under the The Unlicense. See lib/gif-h/LICENSE
|
||||
|
||||
* GLEW is included under a permissive license in lib/glew/LICENSE.txt
|
||||
|
||||
* GLM is included under the MIT license in lib/glm/LICENSE
|
||||
|
||||
* nlohmann's json library is included under the MIT license in lib/json/LICENSE.MIT
|
||||
|
||||
* SDL2 GFX is included under a permissive license in lib/sdl2-gfx/LICENSE
|
||||
|
||||
* superxbr.cpp is included under the permissive license at the top of lib/superxbr.cpp
|
||||
- BPmono.ttf is licensed under the Creative Commons Attribution - No Derivative Works 3.0 license. See [LICENSE_BPmono.txt][]
|
||||
- gif-h is unlicensed, public domain code released under the The Unlicense. See [lib/gif-h/LICENSE][]
|
||||
- GLEW is included under the license in [lib/glew/LICENSE.txt][]
|
||||
- GLM is included under the MIT license in [lib/glm/LICENSE][]
|
||||
- nlohmann's json library is included under the MIT license in [lib/json/LICENSE.MIT][]
|
||||
- SDL2 GFX is included under the license in [lib/sdl2-gfx/LICENSE][]
|
||||
- superxbr.cpp is included under the license at the top of [lib/superxbr.cpp][]
|
||||
|
||||
Contact
|
||||
-------
|
||||
|
||||
* email: bam (at) nugget.fun
|
||||
* twitter: <https://twitter.com/diskmem>
|
||||
- email: frank at shampoo dot ooo
|
||||
- twitter: https://twitter.com/diskmem
|
||||
|
|
|
@ -51,10 +51,12 @@ Game::Game()
|
|||
sb::Log::log(log_message.str());
|
||||
glm::ivec2 window_size = configuration()["display"]["dimensions"].get<glm::ivec2>();
|
||||
|
||||
/* Set these before creating a window (see SDL_GLattr.html) */
|
||||
/* Set these before creating a window (see SDL_GLattr.html). Don't ask Emscripten for a GL context version. */
|
||||
#ifndef __EMSCRIPTEN__
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
#endif
|
||||
SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
|
||||
SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
|
||||
SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
|
||||
|
@ -70,6 +72,7 @@ Game::Game()
|
|||
sb::Log::sdl_error("Could not create window");
|
||||
flag_to_end();
|
||||
}
|
||||
|
||||
/* Create an SDL renderer for clearing the screen to black and for logging renderer properties. Destroy renderer when finished.
|
||||
* Skip this in emscripten because it causes a mouse event bug. */
|
||||
#ifndef __EMSCRIPTEN__
|
||||
|
|
|
@ -92,7 +92,7 @@ void Texture::load(void* pixels, glm::vec2 size, GLenum format, GLenum type)
|
|||
sb::Log::gl_errors("after loading texture");
|
||||
}
|
||||
|
||||
/* The texture must have been previously generated with a size to use this generic pixel data load function */
|
||||
#ifndef __EMSCRIPTEN__
|
||||
void Texture::load(void* pixels, GLenum format, GLenum type)
|
||||
{
|
||||
if (!generated())
|
||||
|
@ -104,14 +104,14 @@ void Texture::load(void* pixels, GLenum format, GLenum type)
|
|||
load(pixels, size(), format, type);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void Texture::bind() const
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, this->id());
|
||||
}
|
||||
|
||||
/* Return the size in pixels of mipmap level 0 (the only mipmap level supported by this class). If the texture hasn't been,
|
||||
* generated, return {0, 0}. */
|
||||
#ifndef __EMSCRIPTEN__
|
||||
glm::vec2 Texture::size() const
|
||||
{
|
||||
if (generated())
|
||||
|
@ -128,6 +128,7 @@ glm::vec2 Texture::size() const
|
|||
return {0, 0};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Textures are considered equal if they have the same ID */
|
||||
bool Texture::operator==(const Texture& texture) const
|
||||
|
|
|
@ -53,10 +53,32 @@ namespace sb
|
|||
void load(fs::path);
|
||||
void load(SDL_RWops*);
|
||||
void load(SDL_Surface*);
|
||||
void load(void*, GLenum = GL_RGBA, GLenum = GL_UNSIGNED_BYTE);
|
||||
void load(void*, glm::vec2, GLenum = GL_RGBA, GLenum = GL_UNSIGNED_BYTE);
|
||||
void load(void* pixels, glm::vec2 size, GLenum format = GL_RGBA, GLenum type = GL_UNSIGNED_BYTE);
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
/*!
|
||||
* @overload load(void* pixels, glm::vec2 size, GLenum format, GLenum type)
|
||||
*
|
||||
* The texture must have been previously generated with a size to use this generic pixel data load function. The size is
|
||||
* determined with `glGetTexLevelParameter`, which is only available to OpenGL ES 3.1+, so this overload is not available
|
||||
* for Emscripten builds.
|
||||
*/
|
||||
void load(void* pixels, GLenum format = GL_RGBA, GLenum type = GL_UNSIGNED_BYTE);
|
||||
#endif
|
||||
|
||||
void bind() const override;
|
||||
|
||||
#ifndef __EMSCRIPTEN__
|
||||
/*!
|
||||
* Return the size in pixels of mipmap level 0 (the only mipmap level supported by this class). If the texture hasn't been,
|
||||
* generated, return {0, 0}. `glGetTexLevelParameter` is only available in OpenGL ES 3.1+, so this function is removed from
|
||||
* Emscripten builds.
|
||||
*
|
||||
* @return glm::vec2 A vector consisting of {TEXTURE_MIPMAP_WIDTH, TEXTURE_MIPMAP_HEIGHT}
|
||||
*/
|
||||
glm::vec2 size() const;
|
||||
#endif
|
||||
|
||||
bool operator==(const Texture&) const;
|
||||
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue