Skip to content

Commit

Permalink
Merge branch 'master' of github.com:micahpearlman/MonkVG
Browse files Browse the repository at this point in the history
  • Loading branch information
micahpearlman committed Sep 6, 2024
2 parents ca58c6f + 92bd8bc commit 44a90cc
Show file tree
Hide file tree
Showing 191 changed files with 7,211 additions and 36,941 deletions.
7 changes: 4 additions & 3 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignEscapedNewlines: Right
AlignOperands: true
Expand Down Expand Up @@ -53,7 +53,8 @@ BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
# PackConstructorInitializers: PCIS_Never
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
Expand Down
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "thirdparty/angle"]
path = thirdparty/angle
url = https://github.com/google/angle.git
[submodule "thirdparty/stb"]
path = thirdparty/stb
url = https://github.com/nothings/stb.git
72 changes: 57 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,76 @@ project(monkvg VERSION 0.1.0)

# configuration
option(MKVG_DO_VULKAN_BACKEND "Use Vulkan as the rendering backend. NOT IMPLEMENTED" OFF) # Not Implemented Yet
option(MKVG_DO_OPENGLES_BACKEND "Use OpenGL ES as the rendering backend. NOT IMPLEMENTED" OFF)
option(MKVG_DO_OPENGL_BACKEND "Use OpenGL as the rendering backend." ON)
option(MKVG_DO_GLU_TESSELATION "Use GLU tesselator" ON)
option(MKVG_DO_EXAMPLES "Build examples in the ./examples directory" ON)

if (MKVG_DO_VULKAN_BACKEND)
message(FATAL_ERROR "Vulkan Backend Not Implemented Yet")
endif()
if (MKVG_DO_OPENGLES_BACKEND)
message(FATAL_ERROR "OpenGL ES Backend Not Implemented Yet")
endif()

if (MKVG_DO_OPENGLES_BACKEND AND MKVG_DO_OPENGL_BACKEND)
message(FATAL_ERROR "Cannot build both OpenGL and OpenGL ES backends MKVG_DO_OPENGLES_BACKEND: ${MKVG_DO_OPENGLES_BACKEND} MKVG_DO_OPENGL_BACKEND: ${MKVG_DO_OPENGL_BACKEND}" )
endif()

# C++ 20
set(CMAKE_CXX_STANDARD 20)

# require PkgConfig
find_package(PkgConfig REQUIRED)

# External Project Handler
include(build_external_proj.cmake)

## GLU Tesselation
if(MKVG_DO_GLU_TESSELATION)
add_subdirectory(thirdparty/glu)
set(GLU_LIBRARIES glu_tess glu_util)
set(GLU_INCLUDE_DIRS thirdparty/glu/include)
set(GLU_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/glu/include)
message(STATUS "GLU Tesselation Enabled")
message(STATUS "GLU_INCLUDE_DIRS: ${GLU_INCLUDE_DIRS}")
message(STATUS "GLU_LIBRARIES: ${GLU_LIBRARIES}")
endif()


## OpenGL Backend
if(MKVG_DO_OPENGL_BACKEND)
if (${CMAKE_SYSTEM_NAME} MATCHES Linux)
# use vendor version of OpenGL if available
set(OpenGL_GL_PREFERENCE "GLVND")
endif()

find_package(OpenGL REQUIRED)
find_package(glm REQUIRED)
if (APPLE)
# for whatever reason apple requires explicit include path
set(GLM_INCLUDE_DIRS ${GLM_INCLUDE_DIRS} /opt/homebrew/include)
endif(APPLE)


set(BACKEND_SOURCE ${BACKEND_SOURCE}
./src/opengl/glBatch.cpp
./src/opengl/glContext.cpp
./src/opengl/glFont.cpp
./src/opengl/glImage.cpp
./src/opengl/glPaint.cpp
./src/opengl/glPath.cpp)
./src/opengl/glPath.cpp
./src/opengl/glShader.cpp)
set(BACKEND_INCLUDE ${BACKEND_INCLUDE}
./src/opengl
${GLU_INCLUDE_DIRS}
./thirdparty/gles2-bc/Sources/OpenGLES
./thirdparty/gles2-bc/Sources/OpenGLES/OpenGLES11
./thirdparty/gles2-bc/Sources/OpenGLES/OpenGLES20)
${GLM_INCLUDE_DIRS})

set(MNKVG_COMPILE_DEFS ${MNKVG_COMPILE_DEFS} MNKVG_GL_BACKEND)


endif()



## setup common source
set(COMMON_SOURCE ${COMMON_SOURCE}
./src/mkBaseObject.cpp
./src/mkBatch.cpp
Expand All @@ -52,26 +87,33 @@ set(COMMON_SOURCE ${COMMON_SOURCE}
)
set(COMMON_INCLUDE ${COMMON_INCLUDE} ${CMAKE_CURRENT_SOURCE_DIR}/src)

# GLES2-BC library
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/gles2-bc)

## Build the MonkVG library
message(STATUS "MNKVG_COMPILE_DEFS: ${MNKVG_COMPILE_DEFS}")
add_library(monkvg ${COMMON_SOURCE} ${BACKEND_SOURCE})
add_dependencies(monkvg ${GLU_LIBRARIES} gles2-bc)
add_dependencies(monkvg ${GLU_LIBRARIES} ${MNKVG_DEPENDENCIES})
target_compile_definitions(monkvg PRIVATE ${MNKVG_COMPILE_DEFS})

target_include_directories(monkvg
PUBLIC
${CMAKE_CURRENT_SOURCE_DIR}/include
PRIVATE
${COMMON_INCLUDE}
${BACKEND_INCLUDE})
target_link_libraries(monkvg ${GLU_LIBRARIES} gles2-bc)

target_link_libraries(monkvg ${GLU_LIBRARIES} ${MNKVG_LIBRARIES})

if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
target_compile_options(monkvg PRIVATE -Wno-deprecated-enum-enum-conversion)
endif()

if (MKVG_DO_EXAMPLES)
## Build Examples

include(ExternalProject)
# include(ExternalProject)
# suppress annoying C++ 20 deprecation warnings
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
add_compile_options(-Wno-deprecated-enum-enum-conversion)
endif()

# Platform Specific librarys like GLX on Linux
set(PLATFORM_LIBS )
Expand All @@ -82,7 +124,6 @@ if (MKVG_DO_EXAMPLES)
endif()


find_package(glm REQUIRED)

if (APPLE)
find_package(glfw3 3.4 REQUIRED)
Expand All @@ -101,7 +142,8 @@ if (MKVG_DO_EXAMPLES)
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/include/MonkVG
${GLM_INCLUDE_DIRS}
${GLFW_INCLUDE_DIRS}
${GLFW_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/stb
)
target_link_libraries(glfw_hello_world PUBLIC
monkvg
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ MonkVG: An OpenVG implementation

## Overview

MonkVG is an OpenVG 1.1 *like* vector graphics API implementation currently using an OpenGL ES (1.1 or 2.0) backend that should be compatible with any HW that supports OpenGL ES 1.1 or 2.0, which includes most iOS and Android devices as well as Linux, MacOS and Windows platforms.
MonkVG is an OpenVG 1.1 *like* vector graphics API implementation currently using an OpenGL 3.3 backend that should be compatible with any HW that supports OpenGL ES 3.3.

This is an open source BSD licensed project that is in active development. Contributors and sponsors welcome.

Expand All @@ -17,8 +17,10 @@ Projects using MonkVG include:

## Whats New

- (9/6/2024) Complete refactor of the code base. Currently only OpenGL 3.3 backend is supported.
- (2/17/2022) CMake build support and GLFW example.
- (1/22/2012) Now supports OpenGL ES 1.1 *AND* 2.0
- (1/22/2012) Now supports OpenGL ES 1.1 *AND* 2.0 (NOTE: as of 9/6/2024 only OpenGL 3.3 is supported)


## Installation

Expand All @@ -29,6 +31,18 @@ git clone --recursive https://github.com/micahpearlman/MonkVG.git
```

There are currently, GLFW (see `./examples` diectory). Also, *VERY OLD* iOS and OSX XCode 4 projects as well as *VERY OLD* contributed Android projects (thanks Paul Holden)and Windows project (thanks Vincent Richomme).

Examples requires the GLFW library to be installed. On MacOS:

```
brew install glfw
```

Debian/Ubuntu:

```
sudo apt-get install libglfw3-dev
```
### CMake Build

```
Expand Down
39 changes: 0 additions & 39 deletions build_external_proj.cmake

This file was deleted.

86 changes: 70 additions & 16 deletions examples/glfw_hello_world.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,21 @@
#include <GLFW/glfw3.h>
#endif

// GLM math library
#include <glm/glm.hpp>

// STB image loader
#define STB_IMAGE_IMPLEMENTATION
#include <stb_image.h>

// System
#include <iostream>

#define WINDOW_WIDTH 1024
#define WINDOW_WIDTH 1024
#define WINDOW_HEIGHT 768

int main(int argc, char **argv) {
std::cout << "Hello, MonkVG!\n";
// Initialise GLFW
if (!glfwInit()) {
std::cerr << "Failed to initialize GLFW\n";
Expand All @@ -45,33 +50,65 @@ int main(int argc, char **argv) {
#endif

// Open a window and create its OpenGL context
GLFWwindow *window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "MonkVG Hello World",
NULL, NULL);
GLFWwindow *window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT,
"MonkVG Hello World", NULL, NULL);
if (window == NULL) {
fprintf(stderr, "Failed to open GLFW window.\n");
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);

// Initialize MonkVG using GLES 2.0 rendering
glfwMakeContextCurrent(window);
vgCreateContextMNK(WINDOW_WIDTH, WINDOW_HEIGHT,
VG_RENDERING_BACKEND_TYPE_OPENGLES20);
VG_RENDERING_BACKEND_TYPE_OPENGL33);

// create a paint
VGPaint paint;
// create fill and stroke paints
VGPaint fill_paint = vgCreatePaint();
vgSetPaint(fill_paint, VG_FILL_PATH);
VGfloat fill_color[4] = {0.0f, 1.0f, 0.0f, 1.0f};
vgSetParameterfv(fill_paint, VG_PAINT_COLOR, 4, &fill_color[0]);

paint = vgCreatePaint();
vgSetPaint(paint, VG_FILL_PATH);
VGfloat color[4] = {0.0f, 1.0f, 0.0f, 1.0f};
vgSetParameterfv(paint, VG_PAINT_COLOR, 4, &color[0]);
VGPaint stroke_paint = vgCreatePaint();
vgSetPaint(stroke_paint, VG_STROKE_PATH);
VGfloat stroke_color[4] = {1.0f, 0.0f, 0.0f, 1.0f};
vgSetParameterfv(stroke_paint, VG_PAINT_COLOR, 4, &stroke_color[0]);

// create a simple box path
VGPath path;
path = vgCreatePath(VG_PATH_FORMAT_STANDARD, VG_PATH_DATATYPE_F, 1, 0, 0, 0,
VG_PATH_CAPABILITY_ALL);
vguRect(path, 0.0f, 0.0f, 100.0f, 150.0f);

// load and create an opencv image
int img_width, img_height, img_channels;

// Load the image (JPEG, PNG, etc.)
// Flip the image vertically to match OpenGL's coordinate system
stbi_set_flip_vertically_on_load(true);
const char *filename = "roy.png"; // Replace with your image path
unsigned char *img_data =
stbi_load(filename, &img_width, &img_height, &img_channels, 0);

if (img_data == nullptr) {
std::cerr << "Failed to load image: " << filename << std::endl;
return -1;
}

// Display image info
std::cout << "Loaded image: " << filename << std::endl;
std::cout << "Width: " << img_width << ", Height: " << img_height
<< ", Channels: " << img_channels << std::endl;
assert(img_channels == 4);
// Create an OpenVG image with the appropriate format
VGImage vg_image = vgCreateImage(VG_sRGBA_8888, img_width, img_height,
VG_IMAGE_QUALITY_BETTER);

// Copy the image data to the OpenVG image
vgImageSubData(vg_image, img_data, img_width * 4, VG_sRGBA_8888, 0, 0,
img_width, img_height);

// Free image memory
stbi_image_free(img_data);

// Ensure we can capture the escape key being pressed below
glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

Expand All @@ -91,12 +128,29 @@ int main(int argc, char **argv) {
vgPushOrthoCamera(0.0f, (float)width, (float)height, 0.0f, -1.0f, 1.0f);

/// draw the basic path
// set up path trasnform
vgSeti(VG_MATRIX_MODE, VG_MATRIX_PATH_USER_TO_SURFACE);
vgLoadIdentity();
vgTranslate(width / 2, height / 2);
vgSetPaint(paint, VG_FILL_PATH);
vgDrawPath(path, VG_FILL_PATH);

// stroke wideth
vgSetf(VG_STROKE_LINE_WIDTH, 5.0f);

// fill and stroke paints
vgSetPaint(fill_paint, VG_FILL_PATH);
vgSetPaint(stroke_paint, VG_STROKE_PATH);

// draw the path with fill and stroke
vgDrawPath(path, VG_FILL_PATH | VG_STROKE_PATH);

// draw the image
vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
vgLoadIdentity();
vgScale(0.25f, 0.25f);
vgTranslate(50, 50);
vgDrawImage(vg_image);

// pop the ortho camera
vgPopOrthoCamera();

// Swap buffers
Expand All @@ -109,7 +163,7 @@ int main(int argc, char **argv) {

// destroy MonkVG
vgDestroyPath(path);
vgDestroyPaint(paint);
vgDestroyPaint(fill_paint);
vgDestroyContextMNK();

glfwDestroyWindow(window);
Expand Down
Binary file added examples/roy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 44a90cc

Please sign in to comment.