beginning of text sample
text can be rendered from right to left
@@ -5,6 +5,7 @@ set(CMAKE_BUILD_TYPE Debug)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread -pedantic")
|
||||
set(BUILD_SHARED_LIBS OFF)
|
||||
set(BUILD_TESTS ON)
|
||||
set(BUILD_SAMPLES ON)
|
||||
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
||||
|
||||
cmake_policy(SET CMP0015 NEW)
|
||||
@@ -23,7 +24,7 @@ include_directories(external/glm/glm)
|
||||
include_directories(external/glad)
|
||||
include_directories(external/stb)
|
||||
|
||||
add_library(${PROJECT_NAME} SHARED external/glad/glad.c ${LIB_SRC})
|
||||
add_library(vb01 SHARED external/glad/glad.c ${LIB_SRC})
|
||||
|
||||
set(GLFW_DIR external/glfw)
|
||||
set(FREETYPE_DIR external/freetype)
|
||||
@@ -73,3 +74,8 @@ if(BUILD_TESTS)
|
||||
add_executable(vb01Tests ${TEST_SRC})
|
||||
target_link_libraries(vb01Tests ${PROJECT_NAME} ${DEPS} cppunit)
|
||||
endif()
|
||||
|
||||
if(BUILD_SAMPLES)
|
||||
add_executable(textSample textSample.cpp)
|
||||
target_link_libraries(textSample ${PROJECT_NAME})
|
||||
endif()
|
||||
|
||||
|
After Width: | Height: | Size: 723 KiB |
|
After Width: | Height: | Size: 274 KiB |
|
After Width: | Height: | Size: 394 KiB |
|
After Width: | Height: | Size: 2.5 MiB |
|
After Width: | Height: | Size: 49 KiB |
|
After Width: | Height: | Size: 462 KiB |
|
After Width: | Height: | Size: 588 KiB |
|
After Width: | Height: | Size: 525 KiB |
|
After Width: | Height: | Size: 338 KiB |
|
After Width: | Height: | Size: 953 KiB |
@@ -8,6 +8,7 @@
|
||||
#include "glad.h"
|
||||
#include <glfw3.h>
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <ft2build.h>
|
||||
#include FT_FREETYPE_H
|
||||
|
||||
@@ -64,7 +65,7 @@ namespace vb01{
|
||||
shader->setVec3(node->getPosition(), "pos");
|
||||
|
||||
Vector2 advanceOffset = Vector2::VEC_ZERO;
|
||||
for(int i = 0; i < entry.length(); i++){
|
||||
for(int i = (leftToRight ? 0 : entry.length() - 1); (leftToRight ? (i < entry.length()) : (i >= 0)); (leftToRight ? i++ : i--)){
|
||||
Glyph *glyphPtr = getGlyph(entry[i]);
|
||||
if(!glyphPtr)
|
||||
continue;
|
||||
@@ -81,8 +82,7 @@ namespace vb01{
|
||||
|
||||
void Text::prepareGlyphs(Glyph glyph, Vector2 advanceOffset){
|
||||
Vector3 nodePos = node->getPosition();
|
||||
Vector2 origin = Vector2(nodePos.x, nodePos.y);
|
||||
origin = origin + (advanceOffset * scale);
|
||||
Vector2 origin = Vector2(nodePos.x, nodePos.y) + (advanceOffset * scale);
|
||||
|
||||
Vector2 size = glyph.size * scale, bearing = glyph.bearing * scale;
|
||||
float data[] = {
|
||||
|
||||
@@ -32,6 +32,8 @@ namespace vb01{
|
||||
inline std::wstring getText(){return entry;}
|
||||
inline bool isHorizontal(){return horizontal;}
|
||||
inline void setHorizontal(bool h){this->horizontal = h;}
|
||||
inline bool isLeftToRight(){return leftToRight;}
|
||||
inline void setLeftToRight(bool ltr){this->leftToRight = ltr;}
|
||||
inline Material* getMaterial(){return material;}
|
||||
inline void setMaterial(Material *mat){this->material = mat;}
|
||||
private:
|
||||
@@ -46,7 +48,7 @@ namespace vb01{
|
||||
std::vector<Glyph> characters;
|
||||
unsigned int VAO, VBO;
|
||||
float scale = 1;
|
||||
bool horizontal = true;
|
||||
bool horizontal = true, leftToRight = true;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
#include <string>
|
||||
|
||||
#include "root.h"
|
||||
#include "text.h"
|
||||
#include "material.h"
|
||||
#include "node.h"
|
||||
#include "animationController.h"
|
||||
#include "animationChannel.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
int main(){
|
||||
Root *root = Root::getSingleton();
|
||||
Node *guiNode = root->getGuiNode();
|
||||
const string PATH = "../", FONT_PATH = PATH + "samples/textSample/fonts/", TEX_PATH = PATH + "samples/textSample/textures/";
|
||||
root->start(800, 600, PATH, "TextSample");
|
||||
|
||||
int numTexts = 4;
|
||||
wstring texts[] = {
|
||||
L"대한민국",
|
||||
L"ĄČĘĖĮŠŲŪ„“",
|
||||
L"عشر",
|
||||
L"中華民國"
|
||||
};
|
||||
string fonts[] = {
|
||||
"batang.ttf",
|
||||
"Palem-nm.ttf",
|
||||
"Amiri-Regular.ttf",
|
||||
"sazanami-mincho.ttf"
|
||||
};
|
||||
bool leftToRight[] = {
|
||||
true,
|
||||
true,
|
||||
false,
|
||||
true
|
||||
};
|
||||
bool horizontal[] = {
|
||||
true,
|
||||
true,
|
||||
true,
|
||||
false
|
||||
};
|
||||
|
||||
Material *textMat = new Material(Material::MATERIAL_TEXT);
|
||||
textMat->setTexturingEnabled(true);
|
||||
string frames[]{TEX_PATH + "bricks.jpg", TEX_PATH + "defaultTexture.jpg"};
|
||||
Texture *texture = new Texture(frames, 2);
|
||||
textMat->addDiffuseMap(texture);
|
||||
|
||||
for(int i = 0; i < numTexts; i++){
|
||||
Text *text = new Text(FONT_PATH + fonts[i], texts[i]);
|
||||
text->setLeftToRight(leftToRight[i]);
|
||||
text->setScale(.5);
|
||||
text->setHorizontal(horizontal[i]);
|
||||
text->setMaterial(textMat);
|
||||
Node *textNode = new Node(Vector3(0, 50 * (i + 1), 0), Quaternion::QUAT_W, Vector3::VEC_IJK, "", new AnimationController());
|
||||
textNode->addText(text);
|
||||
guiNode->attachChild(textNode);
|
||||
|
||||
KeyframeChannel kcA;
|
||||
kcA.animatable = texture;
|
||||
kcA.type = KeyframeChannel::TEXTURE_FRAME_A;
|
||||
Keyframe k0;
|
||||
k0.interpolation = Keyframe::CONSTANT;
|
||||
k0.value = 0;
|
||||
k0.frame = 1;
|
||||
kcA.keyframes = vector<Keyframe>({k0});
|
||||
|
||||
KeyframeChannel kcB;
|
||||
kcB.animatable = texture;
|
||||
kcB.type = KeyframeChannel::TEXTURE_FRAME_B;
|
||||
Keyframe k1;
|
||||
k1.interpolation = Keyframe::CONSTANT;
|
||||
k1.value = 1;
|
||||
k1.frame = 1;
|
||||
kcB.keyframes = vector<Keyframe>({k1});
|
||||
|
||||
KeyframeChannel kcC;
|
||||
kcC.animatable = texture;
|
||||
kcC.type = KeyframeChannel::TEXTURE_MIX_RATIO;
|
||||
Keyframe k;
|
||||
k.interpolation = Keyframe::LINEAR;
|
||||
k.value = 0;
|
||||
k.frame = 1;
|
||||
Keyframe kk;
|
||||
kk.interpolation = Keyframe::LINEAR;
|
||||
kk.value = 1;
|
||||
kk.frame = 15;
|
||||
Keyframe kkk;
|
||||
kkk.interpolation = Keyframe::LINEAR;
|
||||
kkk.value = 0;
|
||||
kkk.frame = 29;
|
||||
kcC.keyframes = vector<Keyframe>({k, kk, kkk});
|
||||
Animation *anim = new Animation("tex");
|
||||
anim->addKeyframeChannel(kcA);
|
||||
anim->addKeyframeChannel(kcB);
|
||||
anim->addKeyframeChannel(kcC);
|
||||
|
||||
AnimationController *controller = textNode->getAnimationController();
|
||||
controller->addAnimation(anim);
|
||||
AnimationChannel *channel = new AnimationChannel(controller);
|
||||
channel->addAnimatable(texture);
|
||||
channel->setAnimationName("tex");
|
||||
channel->setLoop(true);
|
||||
controller->addAnimationChannel(channel);
|
||||
}
|
||||
|
||||
while(true){
|
||||
root->update();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||