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
|
||||
ofGLESWindowSettings settings;
|
||||
//settings.setSize(1920, 1080);
|
||||
settings.glesVersion = 2;
|
||||
settings.glesVersion = 3;
|
||||
#else
|
||||
ofGLWindowSettings settings;
|
||||
settings.setSize(1920, 1080);
|
||||
|
|
|
@ -2,25 +2,31 @@
|
|||
#include "conversion.h"
|
||||
#include "import-font.h"
|
||||
#include "ofAppRunner.h"
|
||||
#include "ofGraphics.h"
|
||||
#include "ofGraphicsBaseTypes.h"
|
||||
#include "ofUtils.h"
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::setup(){
|
||||
ofSetFrameRate(30);
|
||||
ofSetVerticalSync(false);
|
||||
//string fontName = "RobotoFlex.ttf";
|
||||
//string fontPath = "data/fonts/" + fontName;
|
||||
//string fontPath = "data/celines-fonts/testing2VF.ttf";
|
||||
string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
||||
string fontPath = "data/celines-fonts/testing2VF.ttf";
|
||||
//string fontPath = "data/celines-fonts/Cottagecore.ttf";
|
||||
ofxMsdfgen::AtlasSettings settings;
|
||||
//settings.characters = "ABCDEFGHIJKL";
|
||||
settings.characters = "ABCDEFGHIJKL";
|
||||
atlas.setup(fontPath, settings);
|
||||
atlasImage = atlas.getAtlasImage();
|
||||
glyphGeometries = atlas.getGlyphGeometries();
|
||||
#ifdef TARGET_EMSCRIPTEN
|
||||
shader.load("ofxMsdfgen/shaders/simple/ES3/shader");
|
||||
shader.load("ofxMsdfgen/shaders/unitRange/ES3/shader");
|
||||
#else
|
||||
shader.load("ofxMsdfgen/shaders/simple/GL3/shader");
|
||||
shader.load("ofxMsdfgen/shaders/unitRange/GL3/shader");
|
||||
#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(){
|
||||
ofBackground(ofColor::lightBlue);
|
||||
cam.begin();
|
||||
ofEnableDepthTest();
|
||||
ofEnableAlphaBlending();
|
||||
ofPushMatrix();
|
||||
ofTranslate(
|
||||
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++){
|
||||
//unicode_t character = word[c];
|
||||
//const ofxMsdfgen::GlyphGeometry & glyphGeometry = glyphGeometries[0];
|
||||
float pxRange = 2.0;
|
||||
for(const auto & glyphGeometry : glyphGeometries){
|
||||
//if(glyphGeometry.getCodepoint() == character){
|
||||
word += glyphGeometry.getCodepoint();
|
||||
float x = 0;
|
||||
float y = 0;
|
||||
float w = glyphGeometry.getBoxRect().w;
|
||||
float h = glyphGeometry.getBoxRect().h;
|
||||
glm::vec2 unitRange = glm::vec2(pxRange) / glm::vec2(w, h);
|
||||
shader.setUniform2f("unitRange", unitRange);
|
||||
float sx = glyphGeometry.getBoxRect().x;
|
||||
float sy = glyphGeometry.getBoxRect().y;
|
||||
float sw = glyphGeometry.getBoxRect().w;
|
||||
float sh = glyphGeometry.getBoxRect().h;
|
||||
if(tx + w > ofGetWidth()){
|
||||
ty += 100;
|
||||
tx = 0;
|
||||
int amount = 0;
|
||||
float mouser = ofGetMousePressed() ? ofMap(ofGetMouseX(), 0, ofGetWidth(), 0.001, 1) : 1;
|
||||
for(int iz = 0; iz < 3; iz++){
|
||||
tx = 0;
|
||||
ty = 0;
|
||||
for(int i = 0; i < 42; i++){
|
||||
for(const auto & glyphGeometry : glyphGeometries){
|
||||
word += glyphGeometry.getCodepoint();
|
||||
int x, y, w, h;
|
||||
glyphGeometry.getBoxRect(x, y, w, h);
|
||||
glm::vec2 unitRange = glm::vec2(atlas.settings.pixelRange) / glm::vec2(w, h);
|
||||
shader.setUniform2f("unitRange", unitRange * mouser);
|
||||
if(tx + w > ofGetWidth()){
|
||||
ty += atlas.settings.scale * 2;
|
||||
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(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;
|
||||
//}
|
||||
ofTranslate(0, 0, 100);
|
||||
}
|
||||
//}
|
||||
ofPopMatrix();
|
||||
ofDisableAlphaBlending();
|
||||
ofDisableDepthTest();
|
||||
cam.end();
|
||||
|
||||
shader.end();
|
||||
ofPushStyle();
|
||||
ofSetColor(ofColor::purple);
|
||||
ofDrawBitmapString("pxRange: " + ofToString(pxRange) + "\n"
|
||||
+ "glyph amount: " + ofToString(glyphGeometries.size()) + "\n"
|
||||
ofDrawBitmapString("glyph amount: " + ofToString(amount) + "\n"
|
||||
+ "word: " + word + "\n"
|
||||
+ "mouser: " + ofToString(mouser) + "\n"
|
||||
+ "fps: " + ofToString(ofGetFrameRate()), 20, 20);
|
||||
ofPopStyle();
|
||||
}
|
||||
|
|
|
@ -3,10 +3,26 @@
|
|||
#include "Atlas.h"
|
||||
#include "conversion.h"
|
||||
#include "ofMain.h"
|
||||
#include "ofQuaternion.h"
|
||||
#include "ofxMsdfgen.h"
|
||||
#include <unordered_map>
|
||||
|
||||
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 {
|
||||
|
||||
public:
|
||||
|
@ -30,4 +46,8 @@ class ofApp : public ofBaseApp {
|
|||
ofImage atlasImage;
|
||||
vector <ofxMsdfgen::GlyphGeometry> glyphGeometries;
|
||||
ofShader shader;
|
||||
ofEasyCam cam;
|
||||
unordered_map <char *, AtlasLetter> atlasLetters;
|
||||
std::vector <DrawnLetter> drawnLetters;
|
||||
std::vector <int> drawOrder;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue