Skip to content

Commit

Permalink
Add the windows demo. (#76)
Browse files Browse the repository at this point in the history
* Add the windows demo.

* Update README.md.
  • Loading branch information
domchen authored Dec 14, 2023
1 parent 1007410 commit 7a3239e
Show file tree
Hide file tree
Showing 20 changed files with 551 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ jobs:

- name: Build Windows
run: |
node build_tgfx -a x64
node build_tgfx -s ./win Hello2D -o ./out/release/win -a x64
- name: Save Third-Party Cache
if: ${{ (github.event_name == 'push') && (steps.third-party-cache.outputs.cache-hit != 'true') }}
Expand Down
89 changes: 47 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ provided above in the [**Build Prerequisites**](#build-prerequisites) and
[**Dependencies**](#dependencies) sections. They will guide you through the
necessary steps to configure your development environment.

### Android Demo
### Android

The android demo project requires the **Android NDK**. We recommend using the **19.2.5345600**
version, which has been fully tested with the tgfx library. If you open the project with Android
Expand Down Expand Up @@ -146,7 +146,7 @@ please search for a solution on Google. However, if you believe the problem is a
project configuration, you can open an [Issue](https://github.com/Tencent/tgfx/issues/new/choose)
to address it.

### iOS Demo
### iOS

Run the following command in the `ios/` directory or double-click on it:

Expand Down Expand Up @@ -178,7 +178,7 @@ generate a project with webp encoding support, please run the following command:

Finally, open XCode and launch the `ios/Hello2D.xcworkspace` to build and run the demo project.

### macOS Demo
### macOS


Run the following command in the `mac/` directory or double-click on it:
Expand All @@ -204,7 +204,7 @@ a project with freetype support, please run the following command:

At last, launch XCode and open the `mac/Hello2D.xcworkspace`. You'll be ready to go!

### Web Demo
### Web

The web demo project requires the **Emscripten SDK**. You can download and install
it from the [official website](https://emscripten.org/). We recommend using the **3.1.20** version,
Expand Down Expand Up @@ -251,25 +251,62 @@ npm run build:debug

With these steps completed, you will be able to debug C++ files directly within Chrome DevTools.

To build the demo project in CLion, please Open the `Settings` panel in CLion and go to
`Build, Execution, Deployment` > `CMake`. Create a new build target. And then set the `CMake options`
to the following value:

```
DCMAKE_TOOLCHAIN_FILE="path/to/emscripten/emscripten/version/cmake/Modules/Platform/Emscripten.cmake"
```

Once you have created the build target, make sure to adjust the `Configurations` accordingly to
align with the newly created build target. By doing so, you will gain the ability to build the tgfx
library in CLion.

Additionally, please note that when using `ESModule` for your project, it is necessary to manually
pack the generated `.wasm` file into the final web program. This is because common packing tools
usually ignore the `.wasm` file. Moreover, remember to upload the `.wasm` file to a server, enabling
users to access it from the network.

### QT Demo
### Windows

To start, open the `win/` directory in CLion. Next, open the `File->Setting` panel and navigate to
`Build, Execution, Deployment->ToolChains`. Set the toolchain of CLion to `Visual Studio` with either
`amd64` (Recommended) or `x86` architecture. Once done, you'll be able to build and run the `Hello2D`
target.

If you prefer to use the VS Studio IDE, you can open the `x64 Native Tools Command Prompt for VS 2019`
and execute the following command in the `win/` directory:

```
cmake -G "Visual Studio 16 2019" -A x64 -B ./build-x64
```

This will generate a project for the `x64` architecture. If you want to generate a project for the
`x86` architecture, open the `x86 Native Tools Command Prompt for VS 2019` and run the following
command instead:

```
cmake -G "Visual Studio 16 2019" -A Win32 -B ./build-x86
```

Finally, go to the `build-x64/` or `build-x86/` directory and open the `Hello2D.sln` file. You'll be
ready to go!

For **macOS** users, to begin, please open the `qt/` folder in CLion. Then, navigate to the
`qt/QTCMAKE.cfg` file to modify the QT path with your local QT installation path. Once done, you can
proceed to build and run the `Hello2D` target.
### QT

For Windows users, ensure that the ToolChain of CLion is set to Visual Studio with `amd64`
For **macOS** users, just open the `qt/` directory in CLion. Then, navigate to the `qt/QTCMAKE.cfg`
file to modify the QT path with your local QT installation path. Once done, you can proceed to build
and run the `Hello2D` target.

For **Windows** users, ensure that the ToolChain of CLion is set to `Visual Studio` with `amd64`
architecture. Then, navigate to the `qt/` folder in CLion and find the `qt/QTCMAKE.cfg` file.
Modify the QT path to match your local QT installation path. Afterward, access the configuration
panel of the `Hello2D` target in CLion. Enter the local QT DLL library path in the
`Environment Variables` row, e.g., `PATH=C:\Qt\6.6.1\msvc2019_64\bin`. Finally, you're ready to
build and run the `Hello2D` target.

## Build TGFX
## Build Library

Aside from directly integrating the source code of tgfx into your project, you also have the option
of linking with the precompiled libraries. TGFX utilizes the [**vendor_tools**](https://github.com/libpag/vendor_tools)
Expand Down Expand Up @@ -313,38 +350,6 @@ To access more details and options, execute the command along with the `-h [--he
node build_tgfx -h
```

## Development

We recommend using the [**CLion**](https://www.jetbrains.com/clion/) IDE on the macOS platform for
development. After synchronizing with `depsync`, there are a few configurations that need to be set
up before opening the project in CLion.

### macOS

No additional configurations of CLion are necessary. **Please note that currently, the unit test
targets for tgfx can only be accessed on macOS**.

### Windows

Open the **File->Setting** panel, and go to **Build, Execution, Deployment->ToolChains**, then set
the toolchain of CLion to **Visual Studio** with **amd64 (Recommended)** or **x86** architecture.

### Web

If you wish to target the web platform, you'll need to install the **Emscripten SDK** and follow
these steps:

- Open the `Settings` panel in CLion and go to `Build, Execution, Deployment` > `CMake`. Create a new build target.
- Set the `CMake options` to the following value:

```
DCMAKE_TOOLCHAIN_FILE="path/to/emscripten/emscripten/version/cmake/Modules/Platform/Emscripten.cmake"
```

- After creating the build target, modify the `Configurations` located before the `Run / Debug` buttons to match the newly created build target.

Once you've completed these steps, you'll have the ability to build the tgfx library and conduct debugging in CLion.


## Contribution

Expand Down
17 changes: 17 additions & 0 deletions qt/.idea/fileTemplates/includes/TGFX File Header.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions qt/.idea/fileTemplates/internal/C Header File.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions qt/.idea/fileTemplates/internal/C Source File.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions qt/.idea/fileTemplates/internal/C++ Class Header.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions qt/.idea/fileTemplates/internal/C++ Class.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions src/opengl/egl/EGLWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

#if defined(__ANDROID__) || defined(ANDROID)
#include <android/native_window.h>
#elif defined(_WIN32)
#include <WinUser.h>
#endif
#include <EGL/eglext.h>
#include <GLES3/gl3.h>
Expand Down Expand Up @@ -55,13 +57,19 @@ std::shared_ptr<Surface> EGLWindow::onCreateSurface(Context* context) {
EGLint width = 0;
EGLint height = 0;

// If the rendering size changes,eglQuerySurface based on ANativeWindow may give the wrong size.
#if defined(__ANDROID__) || defined(ANDROID)
if (nativeWindow) {
// If the rendering size changes,eglQuerySurface() may give the wrong size on same platforms.
#if defined(__ANDROID__) || defined(ANDROID)
width = ANativeWindow_getWidth(nativeWindow);
height = ANativeWindow_getHeight(nativeWindow);
}
#elif defined(_WIN32)
RECT rect;
GetClientRect(nativeWindow, &rect);
width = static_cast<int>(rect.right - rect.left);
height = static_cast<int>(rect.bottom - rect.top);
#endif
}

if (width <= 0 || height <= 0) {
auto eglDevice = static_cast<EGLDevice*>(device.get());
eglQuerySurface(eglDevice->eglDisplay, eglDevice->eglSurface, EGL_WIDTH, &width);
Expand Down
17 changes: 17 additions & 0 deletions win/.idea/fileTemplates/includes/TGFX File Header.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions win/.idea/fileTemplates/internal/C Header File.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions win/.idea/fileTemplates/internal/C Source File.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions win/.idea/fileTemplates/internal/C++ Class Header.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions win/.idea/fileTemplates/internal/C++ Class.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions win/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions win/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
cmake_minimum_required(VERSION 3.13)
project(Hello2D)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif ()

if (MSVC)
add_compile_options("/utf-8")
string(TOLOWER ${MSVC_C_ARCHITECTURE_ID} ARCH)
endif (MSVC)

if (CMAKE_BUILD_TYPE MATCHES "Debug")
add_definitions(-DDEBUG)
else ()
add_definitions(-DNDEBUG)
endif ()

add_definitions(-DNOMINMAX -D_USE_MATH_DEFINES -DWIN32 -D_WINDOWS -D_CRT_SECURE_NO_WARNINGS)
find_library(Bcrypt_LIB Bcrypt)
list(APPEND HELLO_2D_LIBS ${Bcrypt_LIB})
find_library(ws2_32_LIB ws2_32)
list(APPEND HELLO_2D_LIBS ${ws2_32_LIB})
find_library(SHCORE_LIB SHCore)
list(APPEND HELLO_2D_LIBS ${SHCORE_LIB})
file(GLOB ANGLE_LIBS ../vendor/angle/win/${ARCH}/*${CMAKE_STATIC_LIBRARY_SUFFIX})
list(APPEND HELLO_2D_LIBS ${ANGLE_LIBS})
list(APPEND HELLO_2D_INCLUDES ../vendor/angle/include)

file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/libEGL.dll)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/angle/win/${ARCH}/libEGL.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/libGLESv2.dll)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/angle/win/${ARCH}/libGLESv2.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
if (ARCH STREQUAL "x86")
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/zlib.dll)
file(COPY ${CMAKE_CURRENT_SOURCE_DIR}/../vendor/angle/win/${ARCH}/zlib.dll DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
endif ()

set(TGFX_BUILD_DRAWERS ON)

set(CMAKE_POLICY_DEFAULT_CMP0077 NEW)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../ ./tgfx)

file(GLOB_RECURSE HELLO_2D_SOURCE_FILES src/*.*)
add_executable(Hello2D WIN32 ${HELLO_2D_SOURCE_FILES} app.rc)
target_include_directories(Hello2D PRIVATE ${HELLO_2D_INCLUDES} src)
target_link_libraries(Hello2D tgfx-drawers tgfx ${HELLO_2D_LIBS})
1 change: 1 addition & 0 deletions win/app.rc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
IDI_ICON1 ICON DISCARDABLE "images/tgfx.ico"
Binary file added win/images/tgfx.ico
Binary file not shown.
Loading

0 comments on commit 7a3239e

Please sign in to comment.