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;
|
||||||
|
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){
|
for(const auto & glyphGeometry : glyphGeometries){
|
||||||
//if(glyphGeometry.getCodepoint() == character){
|
|
||||||
word += glyphGeometry.getCodepoint();
|
word += glyphGeometry.getCodepoint();
|
||||||
float x = 0;
|
int x, y, w, h;
|
||||||
float y = 0;
|
glyphGeometry.getBoxRect(x, y, w, h);
|
||||||
float w = glyphGeometry.getBoxRect().w;
|
glm::vec2 unitRange = glm::vec2(atlas.settings.pixelRange) / glm::vec2(w, h);
|
||||||
float h = glyphGeometry.getBoxRect().h;
|
shader.setUniform2f("unitRange", unitRange * mouser);
|
||||||
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()){
|
if(tx + w > ofGetWidth()){
|
||||||
ty += 100;
|
ty += atlas.settings.scale * 2;
|
||||||
tx = 0;
|
tx = 0;
|
||||||
}
|
}
|
||||||
ofPushMatrix();
|
ofPushMatrix();
|
||||||
//ofTranslate(tx, ty, 0);
|
ofTranslate(tx, ty, 0);
|
||||||
atlasImage.drawSubsection(x, y, w, h, sx, sy, sw, sh);
|
atlasImage.drawSubsection(0, 0, w, h, x, y, w, h);
|
||||||
ofPopMatrix();
|
ofPopMatrix();
|
||||||
//ofTranslate(glyphGeometry.getAdvance() * atlas.settings.scale, 0, 0);
|
tx += atlas.settings.scale;
|
||||||
ofTranslate(atlas.settings.scale, 0, 0);
|
amount++;
|
||||||
tx += glyphGeometry.getAdvance() * atlas.settings.scale;
|
}
|
||||||
//}
|
}
|
||||||
|
ofTranslate(0, 0, 100);
|
||||||
}
|
}
|
||||||
//}
|
|
||||||
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