Skip to content

Commit

Permalink
Merge pull request #1 from micro-gl/ci
Browse files Browse the repository at this point in the history
Embed micro-gl for buulding examples
  • Loading branch information
HendrixString authored Aug 31, 2023
2 parents 8145728 + 569f289 commit ec3642f
Show file tree
Hide file tree
Showing 240 changed files with 38,158 additions and 2 deletions.
2 changes: 2 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ set(CMAKE_CXX_FLAGS_RELEASE " -fno-rtti -fno-exceptions -fno-unwind-tables \
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bin")
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

add_subdirectory(libs/micro-gl)

find_package(SDL2)
find_package(microgl CONFIG)

Expand Down
2 changes: 1 addition & 1 deletion examples/example_elliptic_arc_divider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main() {
// Algorithm END

canvas.clear({255,255,255,255});
for (uint ix = 0; ix < output_points.size() - 0; ++ix) {
for (unsigned int ix = 0; ix < output_points.size() - 0; ++ix) {
canvas.drawCircle<blendmode::Normal, porterduff::FastSourceOverOnOpaque, true>(
color_red, color_red,
output_points[ix].x,
Expand Down
2 changes: 1 addition & 1 deletion examples/example_path_fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ path_t<number> path_test() {
path.linesTo2(100,100, 300,100, 300, 300, 100,300);
v start{22.0f, 150.0f - 0.002323204};
path.moveTo(start);
path.linesTo3(start, v{300,120.002323204-t}, v{300, 300}, v{100,300});
path.linesTo3(start, v(300,120.002323204-t), v(300, 300), v(100,300));
path.moveTo({200, 200});
path.lineTo({300,10});

Expand Down
5 changes: 5 additions & 0 deletions examples/libs/micro-gl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
bin/
cmake-build-debug/
cmake-build-release/
.idea/
.DS_Store
61 changes: 61 additions & 0 deletions examples/libs/micro-gl/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
cmake_minimum_required(VERSION 3.20)
project("microgl"
VERSION
1.0.0
DESCRIPTION
"fast, slim, embeddable, headers files only C++11 graphics library, that\ can run on any 32/64 bits computer without **FPU** or **GPU**. no standard library required."
HOMEPAGE_URL
"https://micro-gl.github.io/docs")

enable_language(CXX)
set (CMAKE_CXX_STANDARD 11)
include(GNUInstallDirs)
include(CMakePackageConfigHelpers)
message("===============\n${PROJECT_NAME} v${PROJECT_VERSION} project \n===============")

add_library(${PROJECT_NAME} INTERFACE)
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})

# expose public include directory
#target_include_directories(${PROJECT_NAME} INTERFACE ${PROJECT_SOURCE_DIR}/include)
# define target includes for both direct build via add_subdirectory() and for
# defined installation configuration to allow easier package find
target_include_directories(
${PROJECT_NAME} INTERFACE
$<BUILD_INTERFACE:${${PROJECT_NAME}_SOURCE_DIR}/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>)

#target_link_libraries(${PROJECT_NAME} INTERFACE micro-alloc micro-tess)

# Don't make the install target depend on the all target.
set(CMAKE_SKIP_INSTALL_ALL_DEPENDENCY true)

### install
install(TARGETS ${PROJECT_NAME}
EXPORT ${PROJECT_NAME}_Targets
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})

write_basic_package_version_file("${PROJECT_NAME}ConfigVersion.cmake"
VERSION ${PROJECT_VERSION}
COMPATIBILITY SameMajorVersion)

configure_package_config_file(
"${PROJECT_SOURCE_DIR}/cmake/${PROJECT_NAME}Config.cmake.in"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
INSTALL_DESTINATION
${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
# install cmake config files for targets of this lib, so they can be found more easily
# without a custom find script, but with find_package(microgl CONFIG) command
install(EXPORT ${PROJECT_NAME}_Targets
FILE ${PROJECT_NAME}Targets.cmake
NAMESPACE ${PROJECT_NAME}::
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)

install(FILES
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
"${PROJECT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake"
DESTINATION ${CMAKE_INSTALL_DATAROOTDIR}/${PROJECT_NAME}/cmake)
# install include files
install(DIRECTORY ${PROJECT_SOURCE_DIR}/include/microgl DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
9 changes: 9 additions & 0 deletions examples/libs/micro-gl/LICENSE.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# License
Copyright (2021), `Tomer Shalev` (`[email protected]`, `https://github.com/HendrixString`).
All Rights Reserved.
License is a custom open source semi-permissive license with the following guidelines:
1. unless otherwise stated inside a specific file, derivative work and usage of a specific
file is permitted and should be credited to the project and the author of this project.
2. Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
105 changes: 105 additions & 0 deletions examples/libs/micro-gl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<div align='center'>
<img src='microgl-512-logo-rounded.png' style='height: 200px;'/>
</div>

# micro{gl}
**Fast**, Super **Slim**, **Embeddable**, **Headers** only **`C++11`** vector graphics library, that
can run on any 32/64 bits computer without **FPU** or **GPU**. **No standard library required**.


check out our website at [micro-gl.github.io/docs/microgl](https://micro-gl.github.io/docs/microgl)

<div align='center'>
<img src='micro-gl-sample.png' style='opacity: 0.75; max-height: 200'/>
</div>

## Features


> **Language** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
- **`C++11`**, does not use any **`STL`** library and **standard library**.
- **headers only** library
- most functions are templates, which means you compile only what is used
- compile-time polymorphism (no runtime virtual methods)
- support for 32 bits and 64 bits
- self contained and modular.

> **Graphics** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
- very modular design. if something does not exist, you can implement your own
- over 10 blending modes impemented, you can wrote your own and supply as well
- **`porter-duff`** alpha compositing
- support for 2d sampler
- can support any pixel coding you need, we implemeted a lot out of the box
- can render 3d geometries
- we support 3d shaders
- no need for **GPU**, it is all **CPU**
- no need for **FPU**
- support for any number system including **`Q`** numbers (fixed point), no need to use float points

> **Geometry** &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
- fast implementation for common shapes (rect, rounded rectangles, circles, triangles)
- batch traingles like **GPU** would
- support polygons of any type convex, simple, and complex polygons
- path fills(with even-odd or zero-one fill rule) in any precision
- stroke fills
- quadrilaterals
- bezier patches
- we providea dynamic array, but you can plug your own.

## Installing `micro{gl}`
`microgl` is a headers only library, which gives the following install possibilities:
1. Using `cmake` to invoke the `install` target, that will copy everything in your system via
```bash
$ mkdir cmake-build-release
$ cd cmake-build-release
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ cmake --install .
```
2. Copying the `include/microgl` to anywhere you want.

## Consuming `micro{gl}`
Following options are available:
1. copy the project to a sub folder of your project. inside your **`CMakeLists.txt`** add
```cmake
add_subdirectory(/path/to/microgl)
target_link_libraries(your_app microgl)
```
2. If you installed **`micro{gl}`** with option 1 (see above) at your system, you can instead
```cmake
find_package(microgl CONFIG REQUIRED)
target_link_libraries(your_app microgl::microgl)
```
3. If you have not installed, you can add in your app's `CMakeLists.txt`
```cmake
target_include_directories(app path/to/microgl/folder/include/)
```
4. If you manually copied the `include/microgl` to the default system include path,
you can use `cmake/Findmicrogl.cmake` to automatically create the cmake targets
```cmake
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/path/to/Findmicrogl/folder)
find_package(microgl REQUIRED)
target_link_libraries(your_app microgl::microgl)
```
5. Just copy the `include/microgl` into a sub folder of your project and include the header
files you need with relative path in your source files.

## Running Examples
First make sure you have
- [SDL2](https://www.libsdl.org/) installed at your system.
- [cmake](https://cmake.org/download/) installed at your system.

There are two ways:
1. Use your favourite IDE to load the root `CMakeLists.txt` file, and then it
will pick up all of the targets, including the examples
2. Using the command line:
```bash
$ mkdir cmake-build-release
$ cd cmake-build-release
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ cmake --build . --target <example_name>
$ ../examples/bin/example_name
```

```text
Author: Tomer Shalev, [email protected], all rights reserved (2021)
```
24 changes: 24 additions & 0 deletions examples/libs/micro-gl/TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# TODO
1. investigate allocator for bitmap and static allocator and creation of pre-bitmap
2. add uv transform matrix for drawing (per-vertex)
3. uv instristic support
4. add static asserts for geometric container types
5. test my allocators with tess algorithms
6. make boundary_buffer conditional
7.
8. DONE: add rgba_t to color.h and remove color namespace
9. DONE: create git repos for micro-tess and micro-alloc
10. DONE: add author copyrights
11. DONE: refactor private drawing algorithms as _internal
12. DONE: make allocators seperate lib
13. DONE: try make Q within-place 32 bits
14. DONE: re-work functions into tess
15. DONE: try make tess self-contained
16. DONE: add vec classes into tess
17. DONE: make planar sub division allocator aware
18. DONE: make chunker allocator-aware
19. DONE: make path allocator aware
20. DONE: move some enums into tess package
21. DONE: move base classes of sampler/bitmap, porter-duff, shader into their packages
22. DONE: rework curve_divider into 1 file
23. DONE: z-buffer allocator aware
35 changes: 35 additions & 0 deletions examples/libs/micro-gl/cmake/Findmicrogl.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#========================================================================================
# Copyright (2021), Tomer Shalev ([email protected], https://github.com/HendrixString).
# All Rights Reserved.
#
# this should help find the microgl headers-only package and define the microgl target that was
# installed on your system and does not include CMakeLists.txt file, so you can easily link to it.
# If successful, the following will happen:
# 1. microgl_INCLUDE_DIR will be defined
# 2. microgl::microgl target will be defined so you can link to it using target_link_libraries(..)
#========================================================================================
include(GNUInstallDirs)
include(FindPackageHandleStandardArgs)

find_path(microgl_INCLUDE_DIR
NAMES microgl
HINTS ${CMAKE_INSTALL_INCLUDEDIR}
PATH_SUFFIXES clippers bitmaps samplers)
set(microgl_LIBRARY "/dont/use")
find_package_handle_standard_args(microgl DEFAULT_MSG
microgl_LIBRARY microgl_INCLUDE_DIR)

if(microgl_FOUND)
message("MICROGL was found !!!")
else(microgl_FOUND)
message("MICROGL was NOT found !!!")
endif(microgl_FOUND)

if(microgl_FOUND AND NOT TARGET microgl::microgl)
# build the target
add_library(microgl::microgl INTERFACE IMPORTED)
set_target_properties(
microgl::microgl
PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${microgl_INCLUDE_DIR}")
endif()
4 changes: 4 additions & 0 deletions examples/libs/micro-gl/cmake/microglConfig.cmake.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@PACKAGE_INIT@

include("${CMAKE_CURRENT_LIST_DIR}/@[email protected]")
check_required_components("@PROJECT_NAME@")
Loading

0 comments on commit ec3642f

Please sign in to comment.