diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index 4185b58..51e927d 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -1,6 +1,7 @@ #include "ofApp.h" #include "ofAppRunner.h" #include "ofGraphics.h" +#include "ofRectangle.h" #include "ofTexture.h" #include "ofUtils.h" @@ -12,7 +13,7 @@ /* validate webgl shaders like this: const gl = document.getElementDyId('canvas').getContext('webgl2'); var get_shader=function(shadersource,shadertype) -{ + var shader=gl.createShader(shadertype); gl.shaderSource(shader,shadersource); gl.compileShader(shader); @@ -32,8 +33,11 @@ bla bla bla //-------------------------------------------------------------- void ofApp::setup(){ - - mainText = R"DONE(Some things are hard to write about. Take soil, + mainText_full = "A"; + mainText = R"DONE(abcdefghijklmnopqrstuvqxyz +ABCDEFGHIJKLMNOPQRSTUVWXYZ +0123456789",.!@#$%^&*()_+=-[]{})DONE"; + mainText_full = R"DONE(Some things are hard to write about. Take soil, for instance. Soil, Oxford dictionary reads, “is the upper layer of earth in which plants grow, a black or dark brown material typically consisting of a mixture @@ -93,7 +97,13 @@ start. I hope to capture something essential.)DONE"; } } - currentFontPath = "data/celines-fonts/Version-1-var.ttf"; + currentFontPath = "data/celines-fonts/Version-2-var.ttf"; + tryUpdateMainFont(library, + currentFontPath, + mainText, + font, + bb); + transform = Transform(); @@ -128,7 +138,7 @@ void ofApp::update(){ //-------------------------------------------------------------- void ofApp::draw(){ - //ofBackground(backgroundColor); + ofBackground(backgroundColor); GLuint location; int width = ofGetWidth(); @@ -154,78 +164,40 @@ void ofApp::draw(){ int currentProgram; glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram); - if(!font){ - tryUpdateMainFont(library, - currentFontPath, - mainText, - font, - bb); - } if(font){ - GLuint program = fontShader->program; - glUseProgram(program); + fontShaderProgram = fontShader->program; + glUseProgram(fontShaderProgram); - font->program = program; + font->program = fontShaderProgram; font->drawSetup(); - location = glGetUniformLocation(program, "projection"); + location = glGetUniformLocation(fontShaderProgram, "projection"); glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection)); - location = glGetUniformLocation(program, "view"); + location = glGetUniformLocation(fontShaderProgram, "view"); glUniformMatrix4fv(location, 1, false, glm::value_ptr(view)); - location = glGetUniformLocation(program, "model"); + location = glGetUniformLocation(fontShaderProgram, "model"); glUniformMatrix4fv(location, 1, false, glm::value_ptr(model)); float z = 0; - location = glGetUniformLocation(program, "z"); + location = glGetUniformLocation(fontShaderProgram, "z"); glUniform1f(location, z); - location = glGetUniformLocation(program, "color"); + location = glGetUniformLocation(fontShaderProgram, "color"); glUniform4f(location, 1.0f, 0.0f, 1.0f, 1.0f); - location = glGetUniformLocation(program, "antiAliasingWindowSize"); + location = glGetUniformLocation(fontShaderProgram, "antiAliasingWindowSize"); glUniform1f(location, (float)antiAliasingWindowSize); - location = glGetUniformLocation(program, "enableSuperSamplingAntiAliasing"); + location = glGetUniformLocation(fontShaderProgram, "enableSuperSamplingAntiAliasing"); glUniform1i(location, enableSuperSamplingAntiAliasing); - location = glGetUniformLocation(program, "enableControlPointsVisualization"); + location = glGetUniformLocation(fontShaderProgram, "enableControlPointsVisualization"); glUniform1i(location, enableControlPointsVisualization); - //debug_font_location = glGetUniformLocation(program, "iChannel0"); - //glUniform1i(debug_font_location, 3); - - if(!debug_font.isAllocated() && false){ - debug_font.setUseTexture(false); - debug_font.load("sdfatlas.png"); - //debug_font.getTexture().getTextureData().textureID = debug_font_location; - //debug_font.getTexture().getTextureData().textureTarget = GL_TEXTURE_2D; - //debug_font.bind(debug_font_location); - //debug_font.update(); - //debug_font.unbind(debug_font_location); - glGenTextures(1, &debug_font_name); - glActiveTexture(GL_TEXTURE3); - glBindTexture(GL_TEXTURE_2D, debug_font_name); - - ofPixels & pixels = debug_font.getPixels(); - glTexImage2D(GL_TEXTURE_2D, - 0, - GL_RGBA, - pixels.getWidth(), - pixels.getHeight(), - 0, - GL_RGBA, - GL_UNSIGNED_BYTE, - pixels.getData()); - glGenerateMipmap(GL_TEXTURE_2D); - - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); - } - //debug_font.bind(debug_font_location); float cx = 0.5f * (bb.minX + bb.maxX); float cy = 0.5f * (bb.minY + bb.maxY); + //ofRectangle rectangle(0, 0, width, height); + //ofDrawRectangle(rectangle); font->draw(-cx, -cy, 0, mainText); glUseProgram(currentProgram); } @@ -237,7 +209,6 @@ void ofApp::draw(){ } void ofApp::exit(){ - glDeleteTextures(1, &debug_font_location); } //-------------------------------------------------------------- @@ -257,6 +228,9 @@ void ofApp::keyReleased(int key){ //backgroundShader = shaderCatalog->get("background"); fontShader = shaderCatalog->get("font"); } + if(key == 'c'){ + enableControlPointsVisualization = !enableControlPointsVisualization; + } } //-------------------------------------------------------------- diff --git a/example/src/ofApp.h b/example/src/ofApp.h index 33c6999..4cb25d8 100644 --- a/example/src/ofApp.h +++ b/example/src/ofApp.h @@ -88,6 +88,7 @@ class ofApp : public ofBaseApp { string currentFontPath; string mainText; + string mainText_full; float helpFontBaseSize = 20.0f; @@ -103,8 +104,6 @@ class ofApp : public ofBaseApp { bool showHelp = true; - ofImage debug_font; - GLuint debug_font_location; - GLuint debug_font_name; ofFloatColor backgroundColor; + GLuint fontShaderProgram; };