@@ -1,14 +1,14 @@ | |||
lib/ | |||
bin/ | |||
debug/ | |||
inc/utsTextSuiteVersion.inc | |||
*.so | |||
*.lps | |||
*.exe | |||
*.res | |||
*.ico | |||
*.dbg | |||
*.dll | |||
*.zip | |||
*.heaptrc | |||
*.heaptrace | |||
lib/ | |||
bin/ | |||
debug/ | |||
inc/utsTextSuiteVersion.inc | |||
*.so | |||
*.lps | |||
*.exe | |||
*.res | |||
*.ico | |||
*.dbg | |||
*.dll | |||
*.zip | |||
*.heaptrc | |||
*.heaptrace |
@@ -1,9 +1,9 @@ | |||
[submodule "src/TextSuite"] | |||
path = src/TextSuite | |||
url = b3rgmann@git.bergmann89.de:opengl/TextSuite.git | |||
[submodule "src/OpenGLCore"] | |||
path = src/OpenGLCore | |||
url = b3rgmann@git.bergmann89.de:opengl/OpenGLCore.git | |||
[submodule "src/Utils"] | |||
path = src/Utils | |||
url = b3rgmann@git.bergmann89.de:freepascal/utils.git | |||
[submodule "src/TextSuite"] | |||
path = src/TextSuite | |||
url = b3rgmann@git.bergmann89.de:opengl/TextSuite.git | |||
[submodule "src/OpenGLCore"] | |||
path = src/OpenGLCore | |||
url = b3rgmann@git.bergmann89.de:opengl/OpenGLCore.git | |||
[submodule "src/Utils"] | |||
path = src/Utils | |||
url = b3rgmann@git.bergmann89.de:freepascal/utils.git |
@@ -0,0 +1,17 @@ | |||
# Overview | |||
libTextSuite is a dynamic library that encapsulate the [TextSuite](https://git.bergmann89.de/opengl/TextSuite) project to be able to use it on different platforms and programming languages. Out of the box the following platforms and languages are supported. | |||
- __supported platforms__ | |||
- i386-win32 | |||
- x64_64-win64 | |||
- i386-linux | |||
- x86_64-linux | |||
- __supported languages__ | |||
- C | |||
- C++ | |||
- C# | |||
- FPC | |||
- (Delphi) | |||
A detailed [Documentation](./doc/docu.md) is shipped with every copy of libTextSuite. |
@@ -12,6 +12,7 @@ DOCU_DIR="$SCRIPTDIR/doc" | |||
INC_MAJOR=false | |||
INC_MINOR=false | |||
INC_BUGFIX=false | |||
ALLZIPDIR="$SCRIPTDIR/TextSuite-all" | |||
if [ -z "$FIRST_VERSION" ]; then | |||
FIRST_VERSION="0.0.0.0" | |||
@@ -133,7 +134,7 @@ printf "const Version = 'v$NEWVERSION $HASH';" > inc/utsTextSuiteVersion.inc | |||
function BuildConfig() | |||
{ | |||
CONFIG=$1 | |||
POSTFIX=$2 | |||
TARGET=$2 | |||
FILEEXT=$3 | |||
DBGEXT=".dbg" | |||
@@ -144,36 +145,47 @@ function BuildConfig() | |||
cleaupAndExit 1 | |||
fi | |||
ZIPDIR="bin/$POSTFIX" | |||
BINDIR="$ZIPDIR" | |||
ZIPPATH="$SCRIPTDIR/libTextSuite-$POSTFIX.zip" | |||
BINDIR="$SCRIPTDIR/bin" | |||
ZIPDIR="$SCRIPTDIR/TextSuite-$TARGET" | |||
ZIPPATH="$SCRIPTDIR/TextSuite-$TARGET.zip" | |||
if [ -n "$TAGNAME" ]; then | |||
mkdir -p "$SCRIPTDIR/$TAGNAME/" | |||
ZIPPATH="$SCRIPTDIR/$TAGNAME/libTextSuite-$POSTFIX.zip" | |||
ZIPPATH="$SCRIPTDIR/$TAGNAME/TextSuite-$TARGET.zip" | |||
fi | |||
BINNAME="libTextSuite-$POSTFIX$FILEEXT" | |||
DBGNAME="libTextSuite-$POSTFIX$DBGEXT" | |||
TARGETDIR="$BINDIR/$TARGET" | |||
BINNAME="$TARGETDIR/libtextsuite$FILEEXT" | |||
DBGNAME="$TARGETDIR/libtextsuite$DBGEXT" | |||
if [ ! -f $BINNAME ]; then | |||
echo "file not found: $EXENAME" | |||
echo "file not found: $BINNAME" | |||
cleaupAndExit 2 | |||
fi | |||
# extract debug infos | |||
cp "$BINNAME" "$DBGNAME" || { log "unable to copy binary to *.dbg"; cleaupAndExit 3; } | |||
objcopy --only-keep-debug "$DBGNAME" || { log "unable to strip $DBGNAME"; cleaupAndExit 3; } | |||
objcopy --strip-debug --strip-unneeded "$BINNAME" || { log "unable to copy binary to $BINNAME"; cleaupAndExit 3; } | |||
objcopy --add-gnu-debuglink "$DBGNAME" "$BINNAME" || { log "unable to create debug link"; cleaupAndExit 3; } | |||
if [ ! -f $DBGNAME ]; then | |||
echo "file not found: $DBGNAME" | |||
cleaupAndExit 2 | |||
fi | |||
mkdir -p $BINDIR | |||
mv "$BINNAME" "$BINDIR/" || { log "unable to copy linked binary"; cleaupAndExit 3; } | |||
mv "$DBGNAME" "$BINDIR/" || { log "unable to copy linked debug infos"; cleaupAndExit 3; } | |||
# use this to copy data folder instead of data archive: cp -R --preserve=links data $BINDIR || { log "unable to copy data folder"; cleaupAndExit 4; } | |||
cp -r "$HEADER_DIR" "$BINDIR" || { log "unable to copy header files"; cleaupAndExit 4; } | |||
cp -r "$DOCU_DIR" "$BINDIR/docu" || { log "unable to copy documentation files"; cleaupAndExit 5; } | |||
# copy header and docu | |||
mkdir -p "$ZIPDIR/bin" | |||
cp -r "$TARGETDIR" "$ZIPDIR/bin" || { log "unable to copy binaries"; cleaupAndExit 3; } | |||
cp -r "$HEADER_DIR" "$ZIPDIR" || { log "unable to copy header files"; cleaupAndExit 4; } | |||
cp -r "$DOCU_DIR" "$ZIPDIR/docu" || { log "unable to copy documentation files"; cleaupAndExit 5; } | |||
pushd $ZIPDIR | |||
rm -rf $ZIPPATH | |||
zip -r $ZIPPATH ./* || { log "unable to create zip archive"; cleaupAndExit 6; } | |||
pushd "$ZIPDIR" | |||
rm -rf "$ZIPPATH" | |||
zip -r "$ZIPPATH" "." || { log "unable to create zip archive"; cleaupAndExit 6; } | |||
popd | |||
mkdir -p "$ALLZIPDIR" | |||
echo "mv $ZIPDIR/* $ALLZIPDIR/" | |||
cp -rf $ZIPDIR/* $ALLZIPDIR/ || { log "unable to copy binaries to all directory"; cleaupAndExit 3; } | |||
rm -rf "$ZIPDIR" | |||
} | |||
while [[ $# -gt 0 ]]; do | |||
@@ -218,5 +230,17 @@ BuildConfig "Win64Release" "x86_64-win64" ".dll" | |||
BuildConfig "Linux32Release" "i386-linux" ".so" | |||
BuildConfig "Linux64Release" "x86_64-linux" ".so" | |||
ALLZIPPATH="$SCRIPTDIR/TextSuite-all.zip" | |||
if [ -n "$TAGNAME" ]; then | |||
mkdir -p "$SCRIPTDIR/$TAGNAME/" | |||
ALLZIPPATH="$SCRIPTDIR/$TAGNAME/TextSuite-all.zip" | |||
fi | |||
pushd "$ALLZIPDIR" | |||
rm -rf "$ALLZIPPATH" | |||
zip -r "$ALLZIPPATH" "." || { log "unable to create zip archive"; cleaupAndExit 6; } | |||
popd | |||
rm -rf "$ALLZIPDIR" | |||
cleaupAndExit 0 | |||
@@ -1,12 +1,12 @@ | |||
all: | |||
$(info call one of the following rules to build for a specific compiler: mingw, gnuc) | |||
mingw: | |||
gcc -DWIN32 example.c main-mingw.c -lopengl32 -mwindows -o example.exe | |||
gnuc: | |||
gcc -DLINUX -o example main-gnuc.c example.c -lGL -lGLU -lglut -ldl | |||
clean: | |||
rm -rf example | |||
all: | |||
$(info call one of the following rules to build for a specific compiler: mingw, gnuc) | |||
mingw: | |||
gcc -DWIN32 example.c main-mingw.c -lopengl32 -mwindows -o example.exe | |||
gnuc: | |||
gcc -DLINUX -o example main-gnuc.c example.c -lGL -lGLU -lglut -ldl | |||
clean: | |||
rm -rf example | |||
rm -rf example.exe |
@@ -1,179 +1,179 @@ | |||
#include <stdio.h> | |||
#include <GL/gl.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
#ifdef LINUX | |||
# include "../../libTextSuite.h" | |||
#else | |||
# include "..\..\libTextSuite.h" | |||
#endif | |||
#if _WIN64 | |||
# define LIB_NAME "..\\..\\..\\libTextSuite-x86_64-win64.dll" | |||
#elif _WIN32 | |||
# define LIB_NAME "..\\..\\..\\libTextSuite-i386-win32.dll" | |||
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) | |||
# define LIB_NAME "../../../libTextSuite-x86_64-linux.so" | |||
#elif __linux__ && (__i386 || _X86_) | |||
# define LIB_NAME "../../../libTextSuite-i386-linux.so" | |||
#else | |||
# error 'unknown operation system' | |||
#endif | |||
#ifdef LINUX | |||
# define FontCreator ltsFontCreatorFreeType | |||
#else | |||
# define FontCreator ltsFontCreatorGDI | |||
#endif | |||
lts_context_handle_t context; | |||
lts_font_creator_handle_t creator; | |||
lts_renderer_handle_t renderer; | |||
lts_font_handle_t font; | |||
lts_post_processor_handle_t pp; | |||
lts_post_processor_handle_t ppFillPattern; | |||
lts_post_processor_handle_t ppFillColor; | |||
lts_post_processor_handle_t ppBorder; | |||
const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
const lts_wchar_t CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 }; | |||
const lts_wchar_t CHAR_RANGE_E[] = { 'e', 0 }; | |||
const uint8_t PATTER_DATA[] = { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
void WINAPI execute_post_proc(lts_char_handle_t charHandle, lts_image_handle_t imageHandle) | |||
{ | |||
lts_post_processor_execute(ppFillPattern, charHandle, imageHandle); | |||
lts_post_processor_execute(ppFillColor, charHandle, imageHandle); | |||
lts_post_processor_execute(ppBorder, charHandle, imageHandle); | |||
} | |||
bool exampleInit() | |||
{ | |||
if (lts_initialize(LIB_NAME) != ltsErrNone) | |||
{ | |||
showMessage("unable to initialize library"); | |||
return false; | |||
} | |||
context = lts_context_create(); | |||
if (!context) | |||
{ | |||
showMessage("unable to create text suite context"); | |||
return false; | |||
} | |||
renderer = lts_renderer_create(context, ltsRendererOpenGL, ltsFormatRGBA8); | |||
if (!renderer) | |||
{ | |||
showMessage("unable to create text suite renderer"); | |||
return false; | |||
} | |||
creator = lts_font_creator_create(context, FontCreator); | |||
if (!creator) | |||
{ | |||
showMessage("unable to create text suite creator"); | |||
return false; | |||
} | |||
lts_post_processor_custom_data_t ppData; | |||
ppData.args = NULL; | |||
ppData.execute = &execute_post_proc; | |||
pp = lts_post_processor_custom_create(context, &ppData); | |||
if (!pp) | |||
{ | |||
showMessage("unable to create custom post processor"); | |||
return false; | |||
} | |||
lts_image_handle_t img = lts_image_create(context); | |||
lts_image_create_empty(img, ltsFormatAlpha8, 4, 4); | |||
void* imgData = lts_image_get_data(img); | |||
if (img) memcpy(imgData, &PATTER_DATA[0], 16); | |||
ppFillPattern = lts_post_processor_fill_pattern_create(context, img, true, ltsPosition(0, 0), LTS_IMAGE_MODES_MODULATE_ALL, LTS_COLOR_CHANNELS_RGBA); | |||
lts_post_processor_add_chars(ppFillPattern, ltsUsageInclude, &CHAR_RANGE_LOREM[0]); | |||
ppFillColor = lts_post_processor_fill_color_create(context, ltsColor4f(0.0, 0.0, 0.5, 1.0), LTS_IMAGE_MODES_REPLACE_ALL, LTS_COLOR_CHANNELS_RGB); | |||
lts_post_processor_add_chars(ppFillColor, ltsUsageExclude, &CHAR_RANGE_E[0]); | |||
ppBorder = lts_post_processor_border_create(context, 3.0, 0.5, ltsColor4f(0.0, 0.5, 0.0, 1.0), true); | |||
lts_post_processor_add_chars(ppBorder, ltsUsageInclude, &CHAR_RANGE_E[0]); | |||
font = lts_font_creator_get_font_by_file(creator, "../Prototype.ttf", 40, 0, ltsAANormal); | |||
if (!font) | |||
{ | |||
showMessage("unable to create text suite font"); | |||
return false; | |||
} | |||
if (lts_font_set_post_processor(font, pp) != ltsErrNone) | |||
{ | |||
showMessage("unable to set post processor"); | |||
return false; | |||
} | |||
return true; | |||
} | |||
bool exampleRender(int width, int height) | |||
{ | |||
const lts_color4f_t color = { 1.0, 1.0, 1.0, 1.0 }; | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
lts_block_flags_t flags = 0; | |||
FLAGS_SET(flags, ltsBlockFlagWordWrap); | |||
lts_text_block_handle_t textBlock = lts_renderer_begin_block(renderer, 10, 10, width-20, height-20, flags); | |||
if (!textBlock) | |||
{ | |||
showMessage(lts_get_last_error_msg()); | |||
return false; | |||
} | |||
if (lts_text_block_set_horz_align(textBlock, ltsHorzAlignJustify) != ltsErrNone) | |||
{ | |||
showMessage("unable to set horizontal alignment"); | |||
return false; | |||
} | |||
if (lts_text_block_set_font(textBlock, font) != ltsErrNone) | |||
{ | |||
showMessage("unable to set font"); | |||
return false; | |||
} | |||
if (lts_text_block_set_color(textBlock, color) != ltsErrNone) | |||
{ | |||
showMessage("unable to set font"); | |||
return false; | |||
} | |||
if (lts_text_block_text_out_a(textBlock, TEST_TEXT) != ltsErrNone) | |||
{ | |||
showMessage("unable to print text"); | |||
return false; | |||
} | |||
if (lts_renderer_end_block(renderer, textBlock) != ltsErrNone) | |||
{ | |||
showMessage("unable to finish text block"); | |||
return false; | |||
} | |||
//lts_text_block_destroy(textBlock); | |||
glDisable(GL_BLEND); | |||
return true; | |||
} | |||
void exampleFinish() | |||
{ | |||
lts_font_destroy(font); | |||
lts_post_processor_destroy(ppBorder); | |||
lts_post_processor_destroy(ppFillColor); | |||
lts_post_processor_destroy(ppFillPattern); | |||
lts_post_processor_destroy(pp); | |||
lts_font_creator_destroy(creator); | |||
lts_renderer_destroy(creator); | |||
lts_context_destroy(context); | |||
lts_finalize(); | |||
#include <stdio.h> | |||
#include <GL/gl.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
#ifdef LINUX | |||
# include "../../libTextSuite.h" | |||
#else | |||
# include "..\..\libTextSuite.h" | |||
#endif | |||
#if _WIN64 | |||
# define LIB_NAME "..\\..\\..\\bin\\x86_64-win64\\libtextsuite.dll" | |||
#elif _WIN32 | |||
# define LIB_NAME "..\\..\\..\\bin\\i386-win32\\libtextsuite.dll" | |||
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) | |||
# define LIB_NAME "../../../bin/x86_64-linux/libtextsuite.so" | |||
#elif __linux__ && (__i386 || _X86_) | |||
# define LIB_NAME "../../../bin/i386-linux/libtextsuite.so" | |||
#else | |||
# error 'unknown operation system' | |||
#endif | |||
#ifdef LINUX | |||
# define FontCreator ltsFontCreatorFreeType | |||
#else | |||
# define FontCreator ltsFontCreatorGDI | |||
#endif | |||
lts_context_handle_t context; | |||
lts_font_creator_handle_t creator; | |||
lts_renderer_handle_t renderer; | |||
lts_font_handle_t font; | |||
lts_post_processor_handle_t pp; | |||
lts_post_processor_handle_t ppFillPattern; | |||
lts_post_processor_handle_t ppFillColor; | |||
lts_post_processor_handle_t ppBorder; | |||
const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
const lts_wchar_t CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 }; | |||
const lts_wchar_t CHAR_RANGE_E[] = { 'e', 0 }; | |||
const uint8_t PATTER_DATA[] = { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
void WINAPI execute_post_proc(lts_char_handle_t charHandle, lts_image_handle_t imageHandle) | |||
{ | |||
lts_post_processor_execute(ppFillPattern, charHandle, imageHandle); | |||
lts_post_processor_execute(ppFillColor, charHandle, imageHandle); | |||
lts_post_processor_execute(ppBorder, charHandle, imageHandle); | |||
} | |||
bool exampleInit() | |||
{ | |||
if (lts_initialize(LIB_NAME) != ltsErrNone) | |||
{ | |||
showMessage("unable to initialize library"); | |||
return false; | |||
} | |||
context = lts_context_create(); | |||
if (!context) | |||
{ | |||
showMessage("unable to create text suite context"); | |||
return false; | |||
} | |||
renderer = lts_renderer_create(context, ltsRendererOpenGL, ltsFormatRGBA8); | |||
if (!renderer) | |||
{ | |||
showMessage("unable to create text suite renderer"); | |||
return false; | |||
} | |||
creator = lts_font_creator_create(context, FontCreator); | |||
if (!creator) | |||
{ | |||
showMessage("unable to create text suite creator"); | |||
return false; | |||
} | |||
lts_post_processor_custom_data_t ppData; | |||
ppData.args = NULL; | |||
ppData.execute = &execute_post_proc; | |||
pp = lts_post_processor_custom_create(context, &ppData); | |||
if (!pp) | |||
{ | |||
showMessage("unable to create custom post processor"); | |||
return false; | |||
} | |||
lts_image_handle_t img = lts_image_create(context); | |||
lts_image_create_empty(img, ltsFormatAlpha8, 4, 4); | |||
void* imgData = lts_image_get_data(img); | |||
if (img) memcpy(imgData, &PATTER_DATA[0], 16); | |||
ppFillPattern = lts_post_processor_fill_pattern_create(context, img, true, ltsPosition(0, 0), LTS_IMAGE_MODES_MODULATE_ALL, LTS_COLOR_CHANNELS_RGBA); | |||
lts_post_processor_add_chars(ppFillPattern, ltsUsageInclude, &CHAR_RANGE_LOREM[0]); | |||
ppFillColor = lts_post_processor_fill_color_create(context, ltsColor4f(0.0, 0.0, 0.5, 1.0), LTS_IMAGE_MODES_REPLACE_ALL, LTS_COLOR_CHANNELS_RGB); | |||
lts_post_processor_add_chars(ppFillColor, ltsUsageExclude, &CHAR_RANGE_E[0]); | |||
ppBorder = lts_post_processor_border_create(context, 3.0, 0.5, ltsColor4f(0.0, 0.5, 0.0, 1.0), true); | |||
lts_post_processor_add_chars(ppBorder, ltsUsageInclude, &CHAR_RANGE_E[0]); | |||
font = lts_font_creator_get_font_by_file(creator, "../Prototype.ttf", 40, 0, ltsAANormal); | |||
if (!font) | |||
{ | |||
showMessage("unable to create text suite font"); | |||
return false; | |||
} | |||
if (lts_font_set_post_processor(font, pp) != ltsErrNone) | |||
{ | |||
showMessage("unable to set post processor"); | |||
return false; | |||
} | |||
return true; | |||
} | |||
bool exampleRender(int width, int height) | |||
{ | |||
const lts_color4f_t color = { 1.0, 1.0, 1.0, 1.0 }; | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
lts_block_flags_t flags = 0; | |||
FLAGS_SET(flags, ltsBlockFlagWordWrap); | |||
lts_text_block_handle_t textBlock = lts_renderer_begin_block(renderer, 10, 10, width-20, height-20, flags); | |||
if (!textBlock) | |||
{ | |||
showMessage(lts_get_last_error_msg()); | |||
return false; | |||
} | |||
if (lts_text_block_set_horz_align(textBlock, ltsHorzAlignJustify) != ltsErrNone) | |||
{ | |||
showMessage("unable to set horizontal alignment"); | |||
return false; | |||
} | |||
if (lts_text_block_set_font(textBlock, font) != ltsErrNone) | |||
{ | |||
showMessage("unable to set font"); | |||
return false; | |||
} | |||
if (lts_text_block_set_color(textBlock, color) != ltsErrNone) | |||
{ | |||
showMessage("unable to set font"); | |||
return false; | |||
} | |||
if (lts_text_block_text_out_a(textBlock, TEST_TEXT) != ltsErrNone) | |||
{ | |||
showMessage("unable to print text"); | |||
return false; | |||
} | |||
if (lts_renderer_end_block(renderer, textBlock) != ltsErrNone) | |||
{ | |||
showMessage("unable to finish text block"); | |||
return false; | |||
} | |||
//lts_text_block_destroy(textBlock); | |||
glDisable(GL_BLEND); | |||
return true; | |||
} | |||
void exampleFinish() | |||
{ | |||
lts_font_destroy(font); | |||
lts_post_processor_destroy(ppBorder); | |||
lts_post_processor_destroy(ppFillColor); | |||
lts_post_processor_destroy(ppFillPattern); | |||
lts_post_processor_destroy(pp); | |||
lts_font_creator_destroy(creator); | |||
lts_renderer_destroy(creator); | |||
lts_context_destroy(context); | |||
lts_finalize(); | |||
} |
@@ -1,10 +1,10 @@ | |||
#ifndef EXAMPLE_H | |||
#define EXAMPLE_H | |||
#include <stdbool.h> | |||
bool exampleInit(); | |||
bool exampleRender(int width, int height); | |||
void exampleFinish(); | |||
#ifndef EXAMPLE_H | |||
#define EXAMPLE_H | |||
#include <stdbool.h> | |||
bool exampleInit(); | |||
bool exampleRender(int width, int height); | |||
void exampleFinish(); | |||
#endif /* EXAMPLE_H */ |
@@ -1,16 +1,16 @@ | |||
#ifndef HELPER_H | |||
#define HELPER_H | |||
#if defined(WIN32) | |||
#include <windows.h> | |||
extern HWND hwnd; | |||
static inline void showMessage(const char* msg) | |||
{ MessageBox(hwnd, msg, "TextSuiteExample Error", MB_OK); }; | |||
#elif defined(LINUX) | |||
#include <stdio.h> | |||
static inline void showMessage(const char* msg) | |||
{ printf("%s\n", msg); }; | |||
#endif | |||
#ifndef HELPER_H | |||
#define HELPER_H | |||
#if defined(WIN32) | |||
#include <windows.h> | |||
extern HWND hwnd; | |||
static inline void showMessage(const char* msg) | |||
{ MessageBox(hwnd, msg, "TextSuiteExample Error", MB_OK); }; | |||
#elif defined(LINUX) | |||
#include <stdio.h> | |||
static inline void showMessage(const char* msg) | |||
{ printf("%s\n", msg); }; | |||
#endif | |||
#endif /* HELPER_H */ |
@@ -1,57 +1,57 @@ | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
static int windowId; | |||
static int screenw, screenh; | |||
static void Resize(int width, int height) | |||
{ | |||
screenw = width; | |||
screenh = height; | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
} | |||
static void Render(void) | |||
{ | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
if (!exampleRender(screenw, screenh)) | |||
{ | |||
glutDestroyWindow(windowId); | |||
return; | |||
} | |||
glutSwapBuffers(); | |||
} | |||
int main(int argc, char** argv) | |||
{ | |||
glutInit(&argc, argv); | |||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |||
glutInitWindowSize(640, 480); | |||
windowId = glutCreateWindow("libTextSuite example"); | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
if (!exampleInit()) | |||
return 1; | |||
glutReshapeFunc(Resize); | |||
glutDisplayFunc(Render); | |||
glutMainLoop(); | |||
exampleFinish(); | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
static int windowId; | |||
static int screenw, screenh; | |||
static void Resize(int width, int height) | |||
{ | |||
screenw = width; | |||
screenh = height; | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
} | |||
static void Render(void) | |||
{ | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
if (!exampleRender(screenw, screenh)) | |||
{ | |||
glutDestroyWindow(windowId); | |||
return; | |||
} | |||
glutSwapBuffers(); | |||
} | |||
int main(int argc, char** argv) | |||
{ | |||
glutInit(&argc, argv); | |||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |||
glutInitWindowSize(640, 480); | |||
windowId = glutCreateWindow("libTextSuite example"); | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
if (!exampleInit()) | |||
return 1; | |||
glutReshapeFunc(Resize); | |||
glutDisplayFunc(Render); | |||
glutMainLoop(); | |||
exampleFinish(); | |||
} |
@@ -1,159 +1,159 @@ | |||
#include <windows.h> | |||
#include <Wingdi.h> | |||
#include <GL/gl.h> | |||
#include "example.h" | |||
const char g_szClassName[] = "OpenGLWindowClass"; | |||
HDC hdc; | |||
HGLRC hglrc; | |||
HWND hwnd; | |||
int done = 0; | |||
int screenw, screenh; | |||
void SysShutdown (void) | |||
{ | |||
done = 1; | |||
exampleFinish(); | |||
wglMakeCurrent(hdc, NULL); | |||
wglDeleteContext(hglrc); | |||
PostQuitMessage(0); | |||
} | |||
void setPixelFormat() | |||
{ | |||
PIXELFORMATDESCRIPTOR pfd = | |||
{ | |||
sizeof(PIXELFORMATDESCRIPTOR), | |||
1, | |||
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, | |||
PFD_TYPE_RGBA, | |||
32, | |||
0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters | |||
16, | |||
0,0,0,0,0,0,0 | |||
}; | |||
int indexPixelFormat = ChoosePixelFormat(hdc, &pfd); | |||
SetPixelFormat(hdc, indexPixelFormat, &pfd); | |||
} | |||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||
{ | |||
switch(msg) | |||
{ | |||
case WM_CREATE: | |||
if ((hdc = GetDC(hwnd)) == NULL) // get device context | |||
{ | |||
MessageBox(hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
setPixelFormat(); | |||
if ((hglrc = wglCreateContext(hdc)) == NULL) | |||
{ | |||
MessageBox(hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
if (!wglMakeCurrent(hdc, hglrc)) | |||
{ | |||
MessageBox(hwnd, "Failed to make OpenGL Rendering Context current", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
glDisable(GL_DEPTH_TEST); | |||
glDisable(GL_CULL_FACE); | |||
if (!exampleInit()) | |||
{ | |||
SysShutdown(); | |||
break; | |||
} | |||
break; | |||
case WM_SIZE: | |||
screenw = LOWORD(lParam); | |||
screenh = HIWORD(lParam); | |||
break; | |||
case WM_PAINT: | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
if (!exampleRender(screenw, screenh)) | |||
SysShutdown(); | |||
SwapBuffers(hdc); | |||
break; | |||
case WM_CLOSE: | |||
SysShutdown(); | |||
DestroyWindow(hwnd); | |||
break; | |||
case WM_DESTROY: | |||
SysShutdown(); | |||
PostQuitMessage(0); | |||
break; | |||
default: | |||
return DefWindowProc(hwnd, msg, wParam, lParam); | |||
} | |||
return 0; | |||
} | |||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |||
{ | |||
WNDCLASSEX wc; | |||
MSG Msg; | |||
wc.cbSize = sizeof(WNDCLASSEX); | |||
wc.style = 0; | |||
wc.lpfnWndProc = WndProc; | |||
wc.cbClsExtra = 0; | |||
wc.cbWndExtra = 0; | |||
wc.hInstance = hInstance; | |||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |||
wc.lpszMenuName = NULL; | |||
wc.lpszClassName = g_szClassName; | |||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | |||
if(!RegisterClassEx(&wc)) | |||
{ | |||
MessageBox(NULL, "Window Registration Failed!", "Error!", | |||
MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
if ((hwnd = CreateWindowEx( | |||
WS_EX_CLIENTEDGE, | |||
g_szClassName, | |||
"libTextSuite example", | |||
WS_OVERLAPPEDWINDOW, | |||
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, | |||
NULL, NULL, hInstance, NULL)) == NULL) | |||
{ | |||
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
ShowWindow(hwnd, nCmdShow); | |||
UpdateWindow(hwnd); | |||
while(GetMessage(&Msg, NULL, 0, 0) > 0 && done == 0) | |||
{ | |||
TranslateMessage(&Msg); | |||
DispatchMessage(&Msg); | |||
} | |||
return Msg.wParam; | |||
#include <windows.h> | |||
#include <Wingdi.h> | |||
#include <GL/gl.h> | |||
#include "example.h" | |||
const char g_szClassName[] = "OpenGLWindowClass"; | |||
HDC hdc; | |||
HGLRC hglrc; | |||
HWND hwnd; | |||
int done = 0; | |||
int screenw, screenh; | |||
void SysShutdown (void) | |||
{ | |||
done = 1; | |||
exampleFinish(); | |||
wglMakeCurrent(hdc, NULL); | |||
wglDeleteContext(hglrc); | |||
PostQuitMessage(0); | |||
} | |||
void setPixelFormat() | |||
{ | |||
PIXELFORMATDESCRIPTOR pfd = | |||
{ | |||
sizeof(PIXELFORMATDESCRIPTOR), | |||
1, | |||
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, | |||
PFD_TYPE_RGBA, | |||
32, | |||
0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters | |||
16, | |||
0,0,0,0,0,0,0 | |||
}; | |||
int indexPixelFormat = ChoosePixelFormat(hdc, &pfd); | |||
SetPixelFormat(hdc, indexPixelFormat, &pfd); | |||
} | |||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||
{ | |||
switch(msg) | |||
{ | |||
case WM_CREATE: | |||
if ((hdc = GetDC(hwnd)) == NULL) // get device context | |||
{ | |||
MessageBox(hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
setPixelFormat(); | |||
if ((hglrc = wglCreateContext(hdc)) == NULL) | |||
{ | |||
MessageBox(hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
if (!wglMakeCurrent(hdc, hglrc)) | |||
{ | |||
MessageBox(hwnd, "Failed to make OpenGL Rendering Context current", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
glDisable(GL_DEPTH_TEST); | |||
glDisable(GL_CULL_FACE); | |||
if (!exampleInit()) | |||
{ | |||
SysShutdown(); | |||
break; | |||
} | |||
break; | |||
case WM_SIZE: | |||
screenw = LOWORD(lParam); | |||
screenh = HIWORD(lParam); | |||
break; | |||
case WM_PAINT: | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
if (!exampleRender(screenw, screenh)) | |||
SysShutdown(); | |||
SwapBuffers(hdc); | |||
break; | |||
case WM_CLOSE: | |||
SysShutdown(); | |||
DestroyWindow(hwnd); | |||
break; | |||
case WM_DESTROY: | |||
SysShutdown(); | |||
PostQuitMessage(0); | |||
break; | |||
default: | |||
return DefWindowProc(hwnd, msg, wParam, lParam); | |||
} | |||
return 0; | |||
} | |||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |||
{ | |||
WNDCLASSEX wc; | |||
MSG Msg; | |||
wc.cbSize = sizeof(WNDCLASSEX); | |||
wc.style = 0; | |||
wc.lpfnWndProc = WndProc; | |||
wc.cbClsExtra = 0; | |||
wc.cbWndExtra = 0; | |||
wc.hInstance = hInstance; | |||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |||
wc.lpszMenuName = NULL; | |||
wc.lpszClassName = g_szClassName; | |||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | |||
if(!RegisterClassEx(&wc)) | |||
{ | |||
MessageBox(NULL, "Window Registration Failed!", "Error!", | |||
MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
if ((hwnd = CreateWindowEx( | |||
WS_EX_CLIENTEDGE, | |||
g_szClassName, | |||
"libTextSuite example", | |||
WS_OVERLAPPEDWINDOW, | |||
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, | |||
NULL, NULL, hInstance, NULL)) == NULL) | |||
{ | |||
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
ShowWindow(hwnd, nCmdShow); | |||
UpdateWindow(hwnd); | |||
while(GetMessage(&Msg, NULL, 0, 0) > 0 && done == 0) | |||
{ | |||
TranslateMessage(&Msg); | |||
DispatchMessage(&Msg); | |||
} | |||
return Msg.wParam; | |||
} |
@@ -1,12 +1,12 @@ | |||
all: | |||
$(info call one of the following rules to build for a specific compiler: mingw, gnuc) | |||
mingw: | |||
g++ -std=c++11 -DWIN32 -static-libgcc -static-libstdc++ main-mingw.cpp example.cpp -lopengl32 -mwindows -o example.exe | |||
gnuc: | |||
g++ -std=c++11 -DLINUX -o example main-gnuc.cpp example.cpp -lGL -lGLU -lglut -ldl | |||
clean: | |||
rm -rf example | |||
all: | |||
$(info call one of the following rules to build for a specific compiler: mingw, gnuc) | |||
mingw: | |||
g++ -std=c++11 -DWIN32 -static-libgcc -static-libstdc++ main-mingw.cpp example.cpp -lopengl32 -mwindows -o example.exe | |||
gnuc: | |||
g++ -g -std=c++11 -DLINUX -o example main-gnuc.cpp example.cpp -lGL -lGLU -lglut -ldl | |||
clean: | |||
rm -rf example | |||
rm -rf example.exe |
@@ -1,127 +1,127 @@ | |||
#include <stdio.h> | |||
#include <GL/gl.h> | |||
#include <string.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
#ifdef LINUX | |||
# include "../../libTextSuite.hpp" | |||
#else | |||
# include "..\..\libTextSuite.hpp" | |||
#endif | |||
#if _WIN64 | |||
static const std::string LibName("..\\..\\..\\libTextSuite-x86_64-win64.dll"); | |||
#elif _WIN32 | |||
static const std::string LibName("..\\..\\..\\libTextSuite-i386-win32.dll"); | |||
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) | |||
static const std::string LibName("../../../libTextSuite-x86_64-linux.so"); | |||
#elif __linux__ && (__i386 || _X86_) | |||
static const std::string LibName("../../../libTextSuite-i386-linux.so"); | |||
#else | |||
# error 'unknown operation system' | |||
#endif | |||
#ifdef LINUX | |||
# define FontCreatorExample FontCreatorFreeType | |||
#else | |||
# define FontCreatorExample FontCreatorGDI | |||
#endif | |||
typedef std::unique_ptr<lts::PostProcessor> PostProcessorPtrU; | |||
std::shared_ptr<lts::Library> library; | |||
std::shared_ptr<lts::Context> context; | |||
std::shared_ptr<lts::FontCreator> creator; | |||
std::shared_ptr<lts::Renderer> renderer; | |||
std::shared_ptr<lts::Image> pattern; | |||
std::shared_ptr<lts::Font> font; | |||
std::shared_ptr<lts::PostProcessorList<PostProcessorPtrU>> ppList; | |||
const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
const lts::WideChar CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 }; | |||
const lts::WideChar CHAR_RANGE_E[] = { 'e', 0 }; | |||
const uint8_t PATTER_DATA[] = { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
bool exampleInit() | |||
{ | |||
library.reset(new lts::Library(LibName)); | |||
context.reset(new lts::Context(*library)); | |||
creator.reset(new lts::FontCreatorExample(*context)); | |||
renderer.reset(new lts::RendererOpenGL(*context, lts::Format::RGBA8)); | |||
ppList.reset(new lts::PostProcessorList<PostProcessorPtrU>(*context)); | |||
pattern.reset(new lts::Image(*context)); | |||
pattern->createEmpty(lts::Format::Alpha8, 4, 4); | |||
memcpy(pattern->getData(), &PATTER_DATA[0], 16); | |||
PostProcessorPtrU ppFillPattern(new lts::PostProcessorFillPattern( | |||
*context, | |||
*pattern, | |||
lts::Position{0, 0}, | |||
lts::ImageModeModulateAll, | |||
lts::ColorChannelsRGBA)); | |||
ppFillPattern->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_LOREM[0]); | |||
ppList->push_back(std::move(ppFillPattern)); | |||
PostProcessorPtrU ppFillColor(new lts::PostProcessorFillColor( | |||
*context, | |||
lts::Color4f{ 0.0, 0.0, 0.5, 1.0 }, | |||
lts::ImageModeReplaceAll, | |||
lts::ColorChannelsRGB)); | |||
ppFillColor->addChars(lts::CharRangeUsage::Exclude, &CHAR_RANGE_E[0]); | |||
ppList->push_back(std::move(ppFillColor)); | |||
PostProcessorPtrU ppBorder(new lts::PostProcessorBorder( | |||
*context, | |||
3.0, | |||
0.5, | |||
lts::Color4f{ 0.0, 0.5, 0.0, 1.0 }, | |||
true)); | |||
ppBorder->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_E[0]); | |||
ppList->push_back(std::move(ppBorder)); | |||
font = creator->getFontByFile( | |||
"../Prototype.ttf", | |||
40, | |||
lts::FontStyles(), | |||
lts::AntiAliasing::Normal); | |||
font->setPostProcessor(ppList.get()); | |||
return true; | |||
} | |||
bool exampleRender(int width, int height) | |||
{ | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
auto textBlock = renderer->beginBlock(10, 10, width-20, height-20, lts::BlockFlags({ lts::BlockFlag::WordWrap })); | |||
textBlock->setHorzAlign(lts::HorzAlign::Justify); | |||
textBlock->setFont(font.get()); | |||
textBlock->setColor(lts::Color4f{ 1.0, 1.0, 1.0, 1.0 }); | |||
textBlock->textOutA(TEST_TEXT); | |||
renderer->endBlock(std::move(textBlock)); | |||
glDisable(GL_BLEND); | |||
return true; | |||
} | |||
void exampleFinish() | |||
{ | |||
font.reset(); | |||
ppList.reset(); | |||
pattern.reset(); | |||
renderer.reset(); | |||
creator.reset(); | |||
context.reset(); | |||
library.reset(); | |||
#include <stdio.h> | |||
#include <GL/gl.h> | |||
#include <string.h> | |||
#include "example.h" | |||
#include "helper.h" | |||
#ifdef LINUX | |||
# include "../../libTextSuite.hpp" | |||
#else | |||
# include "..\..\libTextSuite.hpp" | |||
#endif | |||
#if _WIN64 | |||
static const std::string LibName("..\\..\\..\\bin\\x86_64-win64\\libtextsuite.dll"); | |||
#elif _WIN32 | |||
static const std::string LibName("..\\..\\..\\bin\\i386-win32\\libtextsuite.dll"); | |||
#elif __linux__ && (__amd64 || __x86_64 || _M_AMD64 || __ppc64__) | |||
static const std::string LibName("../../../bin/x86_64-linux/libtextsuite.so"); | |||
#elif __linux__ && (__i386 || _X86_) | |||
static const std::string LibName("../../../bin/i386-linux/libtextsuite.so"); | |||
#else | |||
# error 'unknown operation system' | |||
#endif | |||
#ifdef LINUX | |||
# define FontCreatorExample FontCreatorFreeType | |||
#else | |||
# define FontCreatorExample FontCreatorGDI | |||
#endif | |||
typedef std::unique_ptr<lts::PostProcessor> PostProcessorPtrU; | |||
std::shared_ptr<lts::Library> library; | |||
std::shared_ptr<lts::Context> context; | |||
std::shared_ptr<lts::FontCreator> creator; | |||
std::shared_ptr<lts::Renderer> renderer; | |||
std::shared_ptr<lts::Image> pattern; | |||
std::shared_ptr<lts::Font> font; | |||
std::shared_ptr<lts::PostProcessorList<PostProcessorPtrU>> ppList; | |||
const char* TEST_TEXT = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
const lts::WideChar CHAR_RANGE_LOREM[] = { 'L', 'o', 'r', 'e', 'm', 0 }; | |||
const lts::WideChar CHAR_RANGE_E[] = { 'e', 0 }; | |||
const uint8_t PATTER_DATA[] = { | |||
0xFF, 0xBF, 0x7F, 0xBF, | |||
0xBF, 0xFF, 0xBF, 0x7F, | |||
0x7F, 0xBF, 0xFF, 0xBF, | |||
0xBF, 0x7F, 0xBF, 0xFF | |||
}; | |||
bool exampleInit() | |||
{ | |||
library.reset(new lts::Library(LibName)); | |||
context.reset(new lts::Context(*library)); | |||
creator.reset(new lts::FontCreatorExample(*context)); | |||
renderer.reset(new lts::RendererOpenGL(*context, lts::Format::RGBA8)); | |||
ppList.reset(new lts::PostProcessorList<PostProcessorPtrU>(*context)); | |||
pattern.reset(new lts::Image(*context)); | |||
pattern->createEmpty(lts::Format::Alpha8, 4, 4); | |||
memcpy(pattern->getData(), &PATTER_DATA[0], 16); | |||
PostProcessorPtrU ppFillPattern(new lts::PostProcessorFillPattern( | |||
*context, | |||
*pattern, | |||
lts::Position{0, 0}, | |||
lts::ImageModeModulateAll, | |||
lts::ColorChannelsRGBA)); | |||
ppFillPattern->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_LOREM[0]); | |||
ppList->push_back(std::move(ppFillPattern)); | |||
PostProcessorPtrU ppFillColor(new lts::PostProcessorFillColor( | |||
*context, | |||
lts::Color4f{ 0.0, 0.0, 0.5, 1.0 }, | |||
lts::ImageModeReplaceAll, | |||
lts::ColorChannelsRGB)); | |||
ppFillColor->addChars(lts::CharRangeUsage::Exclude, &CHAR_RANGE_E[0]); | |||
ppList->push_back(std::move(ppFillColor)); | |||
PostProcessorPtrU ppBorder(new lts::PostProcessorBorder( | |||
*context, | |||
3.0, | |||
0.5, | |||
lts::Color4f{ 0.0, 0.5, 0.0, 1.0 }, | |||
true)); | |||
ppBorder->addChars(lts::CharRangeUsage::Include, &CHAR_RANGE_E[0]); | |||
ppList->push_back(std::move(ppBorder)); | |||
font = creator->getFontByFile( | |||
"../Prototype.ttf", | |||
40, | |||
lts::FontStyles(), | |||
lts::AntiAliasing::Normal); | |||
font->setPostProcessor(ppList.get()); | |||
return true; | |||
} | |||
bool exampleRender(int width, int height) | |||
{ | |||
glEnable(GL_BLEND); | |||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | |||
auto textBlock = renderer->beginBlock(10, 10, width-20, height-20, lts::BlockFlags({ lts::BlockFlag::WordWrap })); | |||
textBlock->setHorzAlign(lts::HorzAlign::Justify); | |||
textBlock->setFont(font.get()); | |||
textBlock->setColor(lts::Color4f{ 1.0, 1.0, 1.0, 1.0 }); | |||
textBlock->textOutA(TEST_TEXT); | |||
renderer->endBlock(std::move(textBlock)); | |||
glDisable(GL_BLEND); | |||
return true; | |||
} | |||
void exampleFinish() | |||
{ | |||
font.reset(); | |||
ppList.reset(); | |||
pattern.reset(); | |||
renderer.reset(); | |||
creator.reset(); | |||
context.reset(); | |||
library.reset(); | |||
} |
@@ -1,10 +1,10 @@ | |||
#ifndef EXAMPLE_H | |||
#define EXAMPLE_H | |||
#include <stdbool.h> | |||
bool exampleInit(); | |||
bool exampleRender(int width, int height); | |||
void exampleFinish(); | |||
#ifndef EXAMPLE_H | |||
#define EXAMPLE_H | |||
#include <stdbool.h> | |||
bool exampleInit(); | |||
bool exampleRender(int width, int height); | |||
void exampleFinish(); | |||
#endif /* EXAMPLE_H */ |
@@ -1,16 +1,16 @@ | |||
#ifndef HELPER_H | |||
#define HELPER_H | |||
#if defined(WIN32) | |||
#include <windows.h> | |||
extern HWND hwnd; | |||
static inline void showMessage(const char* msg) | |||
{ MessageBox(hwnd, msg, "TextSuiteExample Error", MB_OK); }; | |||
#elif defined(LINUX) | |||
#include <stdio.h> | |||
static inline void showMessage(const char* msg) | |||
{ printf("%s\n", msg); }; | |||
#endif | |||
#ifndef HELPER_H | |||
#define HELPER_H | |||
#if defined(WIN32) | |||
#include <windows.h> | |||
extern HWND hwnd; | |||
static inline void showMessage(const char* msg) | |||
{ MessageBox(hwnd, msg, "TextSuiteExample Error", MB_OK); }; | |||
#elif defined(LINUX) | |||
#include <stdio.h> | |||
static inline void showMessage(const char* msg) | |||
{ printf("%s\n", msg); }; | |||
#endif | |||
#endif /* HELPER_H */ |
@@ -1,74 +1,74 @@ | |||
#include <iostream> | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include <exception> | |||
#include "example.h" | |||
#include "helper.h" | |||
static int windowId; | |||
static int screenw, screenh; | |||
static void Resize(int width, int height) | |||
{ | |||
screenw = width; | |||
screenh = height; | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
} | |||
static void Render(void) | |||
{ | |||
try | |||
{ | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
if (!exampleRender(screenw, screenh)) | |||
{ | |||
glutDestroyWindow(windowId); | |||
return; | |||
} | |||
glutSwapBuffers(); | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
glutDestroyWindow(windowId); | |||
} | |||
} | |||
int main(int argc, char** argv) | |||
{ | |||
try | |||
{ | |||
glutInit(&argc, argv); | |||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |||
glutInitWindowSize(640, 480); | |||
windowId = glutCreateWindow("libTextSuite example"); | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
if (!exampleInit()) | |||
return 1; | |||
glutReshapeFunc(Resize); | |||
glutDisplayFunc(Render); | |||
glutMainLoop(); | |||
exampleFinish(); | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
} | |||
#include <iostream> | |||
#include <GL/gl.h> | |||
#include <GL/glut.h> | |||
#include <exception> | |||
#include "example.h" | |||
#include "helper.h" | |||
static int windowId; | |||
static int screenw, screenh; | |||
static void Resize(int width, int height) | |||
{ | |||
screenw = width; | |||
screenh = height; | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
} | |||
static void Render(void) | |||
{ | |||
try | |||
{ | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
if (!exampleRender(screenw, screenh)) | |||
{ | |||
glutDestroyWindow(windowId); | |||
return; | |||
} | |||
glutSwapBuffers(); | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
glutDestroyWindow(windowId); | |||
} | |||
} | |||
int main(int argc, char** argv) | |||
{ | |||
try | |||
{ | |||
glutInit(&argc, argv); | |||
glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE); | |||
glutInitWindowSize(640, 480); | |||
windowId = glutCreateWindow("libTextSuite example"); | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
if (!exampleInit()) | |||
return 1; | |||
glutReshapeFunc(Resize); | |||
glutDisplayFunc(Render); | |||
glutMainLoop(); | |||
exampleFinish(); | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
} | |||
} |
@@ -1,182 +1,182 @@ | |||
#include <iostream> | |||
#include <exception> | |||
#include <windows.h> | |||
#include <Wingdi.h> | |||
#include <GL/gl.h> | |||
#include <stdio.h> | |||
#include "helper.h" | |||
#include "example.h" | |||
const char g_szClassName[] = "OpenGLWindowClass"; | |||
HDC hdc; | |||
HGLRC hglrc; | |||
HWND hwnd; | |||
int done = 0; | |||
bool canRender = false; | |||
int screenw, screenh; | |||
void SysShutdown (void) | |||
{ | |||
done = 1; | |||
exampleFinish(); | |||
wglMakeCurrent(hdc, NULL); | |||
wglDeleteContext(hglrc); | |||
PostQuitMessage(0); | |||
} | |||
void setPixelFormat() | |||
{ | |||
PIXELFORMATDESCRIPTOR pfd = | |||
{ | |||
sizeof(PIXELFORMATDESCRIPTOR), | |||
1, | |||
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, | |||
PFD_TYPE_RGBA, | |||
32, | |||
0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters | |||
16, | |||
0,0,0,0,0,0,0 | |||
}; | |||
int indexPixelFormat = ChoosePixelFormat(hdc, &pfd); | |||
SetPixelFormat(hdc, indexPixelFormat, &pfd); | |||
} | |||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||
{ | |||
try | |||
{ | |||
switch(msg) | |||
{ | |||
case WM_CREATE: | |||
if ((hdc = GetDC(hwnd)) == NULL) // get device context | |||
{ | |||
MessageBox(hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
setPixelFormat(); | |||
if ((hglrc = wglCreateContext(hdc)) == NULL) | |||
{ | |||
MessageBox(hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
if (!wglMakeCurrent(hdc, hglrc)) | |||
{ | |||
MessageBox(hwnd, "Failed to make OpenGL Rendering Context current", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
glDisable(GL_DEPTH_TEST); | |||
glDisable(GL_CULL_FACE); | |||
if (!exampleInit()) | |||
{ | |||
SysShutdown(); | |||
break; | |||
} | |||
canRender = true; | |||
break; | |||
case WM_SIZE: | |||
screenw = LOWORD(lParam); | |||
screenh = HIWORD(lParam); | |||
break; | |||
case WM_PAINT: | |||
if (!canRender) | |||
break; | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
if (!exampleRender(screenw, screenh)) | |||
SysShutdown(); | |||
SwapBuffers(hdc); | |||
break; | |||
case WM_CLOSE: | |||
SysShutdown(); | |||
DestroyWindow(hwnd); | |||
break; | |||
case WM_DESTROY: | |||
SysShutdown(); | |||
PostQuitMessage(0); | |||
break; | |||
default: | |||
return DefWindowProc(hwnd, msg, wParam, lParam); | |||
} | |||
return 0; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
MessageBox(hwnd, ex.what(), "Exception", MB_OK); | |||
SysShutdown(); | |||
} | |||
} | |||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |||
{ | |||
try | |||
{ | |||
WNDCLASSEX wc; | |||
MSG Msg; | |||
wc.cbSize = sizeof(WNDCLASSEX); | |||
wc.style = 0; | |||
wc.lpfnWndProc = WndProc; | |||
wc.cbClsExtra = 0; | |||
wc.cbWndExtra = 0; | |||
wc.hInstance = hInstance; | |||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |||
wc.lpszMenuName = NULL; | |||
wc.lpszClassName = g_szClassName; | |||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | |||
if(!RegisterClassEx(&wc)) | |||
{ | |||
MessageBox(NULL, "Window Registration Failed!", "Error!", | |||
MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
if ((hwnd = CreateWindowEx( | |||
WS_EX_CLIENTEDGE, | |||
g_szClassName, | |||
"libTextSuite example", | |||
WS_OVERLAPPEDWINDOW, | |||
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, | |||
NULL, NULL, hInstance, NULL)) == NULL) | |||
{ | |||
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
ShowWindow(hwnd, nCmdShow); | |||
UpdateWindow(hwnd); | |||
while(GetMessage(&Msg, NULL, 0, 0) > 0 && done == 0) | |||
{ | |||
TranslateMessage(&Msg); | |||
DispatchMessage(&Msg); | |||
} | |||
return Msg.wParam; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
} | |||
#include <iostream> | |||
#include <exception> | |||
#include <windows.h> | |||
#include <Wingdi.h> | |||
#include <GL/gl.h> | |||
#include <stdio.h> | |||
#include "helper.h" | |||
#include "example.h" | |||
const char g_szClassName[] = "OpenGLWindowClass"; | |||
HDC hdc; | |||
HGLRC hglrc; | |||
HWND hwnd; | |||
int done = 0; | |||
bool canRender = false; | |||
int screenw, screenh; | |||
void SysShutdown (void) | |||
{ | |||
done = 1; | |||
exampleFinish(); | |||
wglMakeCurrent(hdc, NULL); | |||
wglDeleteContext(hglrc); | |||
PostQuitMessage(0); | |||
} | |||
void setPixelFormat() | |||
{ | |||
PIXELFORMATDESCRIPTOR pfd = | |||
{ | |||
sizeof(PIXELFORMATDESCRIPTOR), | |||
1, | |||
PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, | |||
PFD_TYPE_RGBA, | |||
32, | |||
0,0,0,0,0,0,0,0,0,0,0,0,0, // useles parameters | |||
16, | |||
0,0,0,0,0,0,0 | |||
}; | |||
int indexPixelFormat = ChoosePixelFormat(hdc, &pfd); | |||
SetPixelFormat(hdc, indexPixelFormat, &pfd); | |||
} | |||
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) | |||
{ | |||
try | |||
{ | |||
switch(msg) | |||
{ | |||
case WM_CREATE: | |||
if ((hdc = GetDC(hwnd)) == NULL) // get device context | |||
{ | |||
MessageBox(hwnd, "Failed to Get the Window Device Context", "Device Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
setPixelFormat(); | |||
if ((hglrc = wglCreateContext(hdc)) == NULL) | |||
{ | |||
MessageBox(hwnd, "Failed to Create the OpenGL Rendering Context", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
if (!wglMakeCurrent(hdc, hglrc)) | |||
{ | |||
MessageBox(hwnd, "Failed to make OpenGL Rendering Context current", "OpenGL Rendering Context Error", MB_OK); | |||
SysShutdown(); | |||
break; | |||
} | |||
glDisable(GL_DEPTH_TEST); | |||
glDisable(GL_CULL_FACE); | |||
if (!exampleInit()) | |||
{ | |||
SysShutdown(); | |||
break; | |||
} | |||
canRender = true; | |||
break; | |||
case WM_SIZE: | |||
screenw = LOWORD(lParam); | |||
screenh = HIWORD(lParam); | |||
break; | |||
case WM_PAINT: | |||
if (!canRender) | |||
break; | |||
glClearColor(1.0, 1.0, 1.0, 1.0); | |||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); | |||
glViewport(0, 0, screenw, screenh); | |||
glMatrixMode(GL_PROJECTION); | |||
glLoadIdentity(); | |||
glOrtho(0, screenw, screenh, 0, -10, 10); | |||
glMatrixMode(GL_MODELVIEW); | |||
glLoadIdentity(); | |||
if (!exampleRender(screenw, screenh)) | |||
SysShutdown(); | |||
SwapBuffers(hdc); | |||
break; | |||
case WM_CLOSE: | |||
SysShutdown(); | |||
DestroyWindow(hwnd); | |||
break; | |||
case WM_DESTROY: | |||
SysShutdown(); | |||
PostQuitMessage(0); | |||
break; | |||
default: | |||
return DefWindowProc(hwnd, msg, wParam, lParam); | |||
} | |||
return 0; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
MessageBox(hwnd, ex.what(), "Exception", MB_OK); | |||
SysShutdown(); | |||
} | |||
} | |||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) | |||
{ | |||
try | |||
{ | |||
WNDCLASSEX wc; | |||
MSG Msg; | |||
wc.cbSize = sizeof(WNDCLASSEX); | |||
wc.style = 0; | |||
wc.lpfnWndProc = WndProc; | |||
wc.cbClsExtra = 0; | |||
wc.cbWndExtra = 0; | |||
wc.hInstance = hInstance; | |||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); | |||
wc.hCursor = LoadCursor(NULL, IDC_ARROW); | |||
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); | |||
wc.lpszMenuName = NULL; | |||
wc.lpszClassName = g_szClassName; | |||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION); | |||
if(!RegisterClassEx(&wc)) | |||
{ | |||
MessageBox(NULL, "Window Registration Failed!", "Error!", | |||
MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
if ((hwnd = CreateWindowEx( | |||
WS_EX_CLIENTEDGE, | |||
g_szClassName, | |||
"libTextSuite example", | |||
WS_OVERLAPPEDWINDOW, | |||
CW_USEDEFAULT, CW_USEDEFAULT, 640, 480, | |||
NULL, NULL, hInstance, NULL)) == NULL) | |||
{ | |||
MessageBox(NULL, "Window Creation Failed!", "Error!", MB_ICONEXCLAMATION | MB_OK); | |||
return 0; | |||
} | |||
ShowWindow(hwnd, nCmdShow); | |||
UpdateWindow(hwnd); | |||
while(GetMessage(&Msg, NULL, 0, 0) > 0 && done == 0) | |||
{ | |||
TranslateMessage(&Msg); | |||
DispatchMessage(&Msg); | |||
} | |||
return Msg.wParam; | |||
} | |||
catch(const std::exception& ex) | |||
{ | |||
std::cout << "Exception: " << ex.what() << std::endl; | |||
} | |||
} |
@@ -0,0 +1,19 @@ | |||
Thumbs.db | |||
*.obj | |||
*.user | |||
*.aps | |||
*.pch | |||
*.vspscc | |||
*.ncb | |||
*.suo | |||
*.sln.docstates | |||
*.bak | |||
*.cache | |||
*.ilk | |||
*.log | |||
*.lib | |||
*.sbr | |||
*.vssscc | |||
obj/ | |||
bin/ | |||
.vs/ |
@@ -0,0 +1,6 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<configuration> | |||
<startup> | |||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/> | |||
</startup> | |||
</configuration> |
@@ -0,0 +1,9 @@ | |||
<Application x:Class="libTextSuiteExample.App" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:local="clr-namespace:libTextSuiteExample" | |||
StartupUri="MainWindow.xaml"> | |||
<Application.Resources> | |||
</Application.Resources> | |||
</Application> |
@@ -0,0 +1,13 @@ | |||
using System; | |||
using System.IO; | |||
using System.Reflection; | |||
using System.Windows; | |||
namespace libTextSuiteExample | |||
{ | |||
/// <summary> | |||
/// Interaktionslogik für "App.xaml" | |||
/// </summary> | |||
public partial class App : Application | |||
{ } | |||
} |
@@ -0,0 +1,20 @@ | |||
<Window x:Class="libTextSuiteExample.MainWindow" | |||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |||
xmlns:sharpGL="clr-namespace:SharpGL.WPF;assembly=SharpGL.WPF" | |||
xmlns:local="clr-namespace:libTextSuiteExample" | |||
mc:Ignorable="d" | |||
Title="libTextSuite exmple" Height="480" Width="640" | |||
Closing="Window_Closing"> | |||
<Grid> | |||
<sharpGL:OpenGLControl | |||
x:Name="oglControl" | |||
OpenGLDraw="oglControl_OpenGLDraw" | |||
OpenGLInitialized="oglControl_OpenGLInitialized" | |||
Resized="oglControl_Resized" | |||
RenderContextType="FBO" | |||
/> | |||
</Grid> | |||
</Window> |
@@ -0,0 +1,168 @@ | |||
using SharpGL; | |||
using SharpGL.SceneGraph; | |||
using System; | |||
using System.IO; | |||
using System.Reflection; | |||
using System.Runtime.InteropServices; | |||
using System.Windows; | |||
namespace libTextSuiteExample | |||
{ | |||
public partial class MainWindow : Window | |||
{ | |||
private static readonly string TEST_TEXT = @"Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."; | |||
private lts.Context _context; | |||
private lts.FontCreator _fontCreator; | |||
private lts.Renderer _renderer; | |||
private lts.Font _font; | |||
private lts.Image _pattern; | |||
private lts.PostProcessorList _ppList; | |||
private static readonly string LibTextSuiteDllName = "libtextsuite.dll"; | |||
[DllImport("kernel32.dll")] | |||
private static extern IntPtr LoadLibrary(string dllToLoad); | |||
public MainWindow() | |||
{ | |||
InitializeComponent(); | |||
// load libtextsuite depending on architecture | |||
string exeDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); | |||
string archDir = Environment.Is64BitProcess ? "x64" : "x86"; | |||
string dllPath = Path.Combine(exeDir, "resources", archDir, LibTextSuiteDllName); | |||
var handle = LoadLibrary(dllPath); | |||
if (handle == IntPtr.Zero) | |||
{ | |||
MessageBox.Show("Unable to load libtextsuite.dll", "Error", MessageBoxButton.OK, MessageBoxImage.Error); | |||
Application.Current.Shutdown(); | |||
} | |||
} | |||
private void oglControl_OpenGLInitialized(object sender, OpenGLEventArgs args) | |||
{ | |||
var gl = args.OpenGL; | |||
gl.Disable(OpenGL.GL_DEPTH_TEST); | |||
gl.Disable(OpenGL.GLU_CULLING); | |||
gl.Enable(OpenGL.GL_BLEND); | |||
gl.ClearColor(1.0f, 1.0f, 1.0f, 1.0f); | |||
gl.MakeCurrent(); | |||
string exeDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); | |||
string fontPath = Path.Combine(exeDir, "resources", "Prototype.ttf"); | |||
_context = new lts.Context(); | |||
_renderer = new lts.RendererOpenGl(_context, lts.Format.RGBA8); | |||
_fontCreator = new lts.FontCreatorGdi(_context); | |||
_font = _fontCreator.GetFontByFile(fontPath, 40, lts.FontStyles.Empty, lts.AntiAliasing.Normal); | |||
_ppList = new lts.PostProcessorList(_context); | |||
_font.PostProcessor = _ppList; | |||
_pattern = new lts.Image(_context); | |||
_pattern.CreateEmpty(lts.Format.Alpha8, 4, 4); | |||