gles 3, use cam
This commit is contained in:
parent
7300658629
commit
51bb04dd80
3 changed files with 64 additions and 34 deletions
|
@ -6,7 +6,7 @@ int main(){
|
||||||
#ifdef OF_TARGET_OPENGLES
|
#ifdef OF_TARGET_OPENGLES
|
||||||
ofGLESWindowSettings settings;
|
ofGLESWindowSettings settings;
|
||||||
//settings.setSize(1920, 1080);
|
//settings.setSize(1920, 1080);
|
||||||
settings.glesVersion = 2;
|
settings.glesVersion = 3;
|
||||||
#else
|
#else
|
||||||
ofGLWindowSettings settings;
|
ofGLWindowSettings settings;
|
||||||
settings.setSize(1920, 1080);
|
settings.setSize(1920, 1080);
|
||||||
|
|
|
@ -2,25 +2,31 @@
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
#include "import-font.h"
|
#include "import-font.h"
|
||||||
#include "ofAppRunner.h"
|
#include "ofAppRunner.h"
|
||||||
|
#include "ofGraphics.h"
|
||||||
#include "ofGraphicsBaseTypes.h"
|
#include "ofGraphicsBaseTypes.h"
|
||||||
#include "ofUtils.h"
|
#include "ofUtils.h"
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::setup(){
|
void ofApp::setup(){
|
||||||
|
ofSetFrameRate(30);
|
||||||
|
ofSetVerticalSync(false);
|
||||||
//string fontName = "RobotoFlex.ttf";
|
//string fontName = "RobotoFlex.ttf";
|
||||||
//string fontPath = "data/fonts/" + fontName;
|
//string fontPath = "data/fonts/" + fontName;
|
||||||
//string fontPath = "data/celines-fonts/testing2VF.ttf";
|
string fontPath = "data/celines-fonts/testing2VF.ttf";
|
||||||
string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
//string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
||||||
ofxMsdfgen::AtlasSettings settings;
|
ofxMsdfgen::AtlasSettings settings;
|
||||||
//settings.characters = "ABCDEFGHIJKL";
|
settings.characters = "ABCDEFGHIJKL";
|
||||||
atlas.setup(fontPath, settings);
|
atlas.setup(fontPath, settings);
|
||||||
atlasImage = atlas.getAtlasImage();
|
atlasImage = atlas.getAtlasImage();
|
||||||
glyphGeometries = atlas.getGlyphGeometries();
|
glyphGeometries = atlas.getGlyphGeometries();
|
||||||
#ifdef TARGET_EMSCRIPTEN
|
#ifdef TARGET_EMSCRIPTEN
|
||||||
shader.load("ofxMsdfgen/shaders/simple/ES3/shader");
|
shader.load("ofxMsdfgen/shaders/unitRange/ES3/shader");
|
||||||
#else
|
#else
|
||||||
shader.load("ofxMsdfgen/shaders/simple/GL3/shader");
|
shader.load("ofxMsdfgen/shaders/unitRange/GL3/shader");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
cam.setPosition(ofGetWidth() / 2, ofGetHeight() / 2, -1000);
|
||||||
|
cam.lookAt(glm::vec3(ofGetWidth() / 2, ofGetHeight() / 2, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
@ -31,6 +37,9 @@ void ofApp::update(){
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::draw(){
|
void ofApp::draw(){
|
||||||
ofBackground(ofColor::lightBlue);
|
ofBackground(ofColor::lightBlue);
|
||||||
|
cam.begin();
|
||||||
|
ofEnableDepthTest();
|
||||||
|
ofEnableAlphaBlending();
|
||||||
ofPushMatrix();
|
ofPushMatrix();
|
||||||
ofTranslate(
|
ofTranslate(
|
||||||
ofMap(sin(ofGetElapsedTimeMillis() * 0.0001), -1, 1, 0, ofGetWidth() - atlasImage.getWidth()),
|
ofMap(sin(ofGetElapsedTimeMillis() * 0.0001), -1, 1, 0, ofGetWidth() - atlasImage.getWidth()),
|
||||||
|
@ -52,42 +61,43 @@ void ofApp::draw(){
|
||||||
//for(int c = 0; c < word.length(); c++){
|
//for(int c = 0; c < word.length(); c++){
|
||||||
//unicode_t character = word[c];
|
//unicode_t character = word[c];
|
||||||
//const ofxMsdfgen::GlyphGeometry & glyphGeometry = glyphGeometries[0];
|
//const ofxMsdfgen::GlyphGeometry & glyphGeometry = glyphGeometries[0];
|
||||||
float pxRange = 2.0;
|
int amount = 0;
|
||||||
for(const auto & glyphGeometry : glyphGeometries){
|
float mouser = ofGetMousePressed() ? ofMap(ofGetMouseX(), 0, ofGetWidth(), 0.001, 1) : 1;
|
||||||
//if(glyphGeometry.getCodepoint() == character){
|
for(int iz = 0; iz < 3; iz++){
|
||||||
word += glyphGeometry.getCodepoint();
|
tx = 0;
|
||||||
float x = 0;
|
ty = 0;
|
||||||
float y = 0;
|
for(int i = 0; i < 42; i++){
|
||||||
float w = glyphGeometry.getBoxRect().w;
|
for(const auto & glyphGeometry : glyphGeometries){
|
||||||
float h = glyphGeometry.getBoxRect().h;
|
word += glyphGeometry.getCodepoint();
|
||||||
glm::vec2 unitRange = glm::vec2(pxRange) / glm::vec2(w, h);
|
int x, y, w, h;
|
||||||
shader.setUniform2f("unitRange", unitRange);
|
glyphGeometry.getBoxRect(x, y, w, h);
|
||||||
float sx = glyphGeometry.getBoxRect().x;
|
glm::vec2 unitRange = glm::vec2(atlas.settings.pixelRange) / glm::vec2(w, h);
|
||||||
float sy = glyphGeometry.getBoxRect().y;
|
shader.setUniform2f("unitRange", unitRange * mouser);
|
||||||
float sw = glyphGeometry.getBoxRect().w;
|
if(tx + w > ofGetWidth()){
|
||||||
float sh = glyphGeometry.getBoxRect().h;
|
ty += atlas.settings.scale * 2;
|
||||||
if(tx + w > ofGetWidth()){
|
tx = 0;
|
||||||
ty += 100;
|
}
|
||||||
tx = 0;
|
ofPushMatrix();
|
||||||
|
ofTranslate(tx, ty, 0);
|
||||||
|
atlasImage.drawSubsection(0, 0, w, h, x, y, w, h);
|
||||||
|
ofPopMatrix();
|
||||||
|
tx += atlas.settings.scale;
|
||||||
|
amount++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ofPushMatrix();
|
ofTranslate(0, 0, 100);
|
||||||
//ofTranslate(tx, ty, 0);
|
|
||||||
atlasImage.drawSubsection(x, y, w, h, sx, sy, sw, sh);
|
|
||||||
ofPopMatrix();
|
|
||||||
//ofTranslate(glyphGeometry.getAdvance() * atlas.settings.scale, 0, 0);
|
|
||||||
ofTranslate(atlas.settings.scale, 0, 0);
|
|
||||||
tx += glyphGeometry.getAdvance() * atlas.settings.scale;
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
ofPopMatrix();
|
ofPopMatrix();
|
||||||
|
ofDisableAlphaBlending();
|
||||||
|
ofDisableDepthTest();
|
||||||
|
cam.end();
|
||||||
|
|
||||||
shader.end();
|
shader.end();
|
||||||
ofPushStyle();
|
ofPushStyle();
|
||||||
ofSetColor(ofColor::purple);
|
ofSetColor(ofColor::purple);
|
||||||
ofDrawBitmapString("pxRange: " + ofToString(pxRange) + "\n"
|
ofDrawBitmapString("glyph amount: " + ofToString(amount) + "\n"
|
||||||
+ "glyph amount: " + ofToString(glyphGeometries.size()) + "\n"
|
|
||||||
+ "word: " + word + "\n"
|
+ "word: " + word + "\n"
|
||||||
|
+ "mouser: " + ofToString(mouser) + "\n"
|
||||||
+ "fps: " + ofToString(ofGetFrameRate()), 20, 20);
|
+ "fps: " + ofToString(ofGetFrameRate()), 20, 20);
|
||||||
ofPopStyle();
|
ofPopStyle();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,26 @@
|
||||||
#include "Atlas.h"
|
#include "Atlas.h"
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
|
#include "ofQuaternion.h"
|
||||||
#include "ofxMsdfgen.h"
|
#include "ofxMsdfgen.h"
|
||||||
|
#include <unordered_map>
|
||||||
|
|
||||||
using namespace msdfgen;
|
using namespace msdfgen;
|
||||||
|
|
||||||
|
struct AtlasLetter {
|
||||||
|
int x, y, w, h;
|
||||||
|
glm::vec2 unitRange;
|
||||||
|
void draw(const ofImage & image,
|
||||||
|
const ofShader & shader){
|
||||||
|
shader.setUniform2f("unitRange", unitRange);
|
||||||
|
image.drawSubsection(0, 0, w, h, x, y, w, h);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
struct DrawnLetter {
|
||||||
|
glm::vec3 position;
|
||||||
|
glm::quat orientation;
|
||||||
|
};
|
||||||
|
|
||||||
class ofApp : public ofBaseApp {
|
class ofApp : public ofBaseApp {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -30,4 +46,8 @@ class ofApp : public ofBaseApp {
|
||||||
ofImage atlasImage;
|
ofImage atlasImage;
|
||||||
vector <ofxMsdfgen::GlyphGeometry> glyphGeometries;
|
vector <ofxMsdfgen::GlyphGeometry> glyphGeometries;
|
||||||
ofShader shader;
|
ofShader shader;
|
||||||
|
ofEasyCam cam;
|
||||||
|
unordered_map <char *, AtlasLetter> atlasLetters;
|
||||||
|
std::vector <DrawnLetter> drawnLetters;
|
||||||
|
std::vector <int> drawOrder;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue