diff --git a/data/ofxGPUFont/shaders/GL3/font.frag b/data/ofxGPUFont/shaders/GL3/font.frag index 8c5f638..17964bd 100644 --- a/data/ofxGPUFont/shaders/GL3/font.frag +++ b/data/ofxGPUFont/shaders/GL3/font.frag @@ -123,10 +123,10 @@ void main() { alpha += computeCoverage(inverseDiameter.y, rotate(p0), rotate(p1), rotate(p2)); } } - vec4 debug = texelFetch(curves, int(uv.x * textureSize(curves))); - result = vec4(debug.rgb, 1.0); + //vec4 debug = texelFetch(glyphs, int(uv.x * textureSize(glyphs))); + //result = vec4(debug.rgb, 1.0); - return; + //return; if (enableSuperSamplingAntiAliasing) { alpha *= 0.5; diff --git a/example/src/gpufont/font.hpp b/example/src/gpufont/font.hpp index 8f6f0b6..d4e1078 100644 --- a/example/src/gpufont/font.hpp +++ b/example/src/gpufont/font.hpp @@ -4,6 +4,7 @@ // because both files have mostly the same dependencies (OpenGL, GLM, FreeType). #include "ofMain.h" +#include #include #ifdef TARGET_OPENGLES #include @@ -336,6 +337,7 @@ class Font { } private: + bool done = false; void uploadBuffers(){ cout << "bufferGlyphs.size(): " << bufferGlyphs.size() << endl; cout << "bufferCurves.size(): " << bufferCurves.size() << endl; @@ -355,7 +357,7 @@ class Font { //glBindBuffer(GL_TEXTURE_2D, curveBuffer); //glBufferData(GL_TEXTURE_2D, sizeof(BufferCurve) * bufferCurves.size(), bufferCurves.data(), GL_STATIC_DRAW); //glBindBuffer(GL_TEXTURE_2D, 0); - glActiveTexture(GL_TEXTURE0); + glActiveTexture(GL_TEXTURE2); glBindTexture(GL_TEXTURE_2D, glyphBuffer); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); @@ -364,7 +366,6 @@ class Font { GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RG32I, @@ -374,7 +375,39 @@ class Font { GL_RG_INTEGER, GL_INT, bufferGlyphs.data()); - glBindTexture(GL_TEXTURE_2D, 0); + + //int size = 2048; + //float * data = new float[3 * size * sizeof(float)]; + //for(unsigned int i = 0; i < size; i++){ + //data[i * 3] = (float)(0.1f); + //data[i * 3 + 1] = (float)(0.5f); + //data[i * 3 + 2] = (float)(1.0f); + //} + //glTexImage2D(GL_TEXTURE_2D, + //0, + //GL_RGB32F, + //size, + //1, + //0, + //GL_RGB, + //GL_FLOAT, + //data); + ///////////////////////////////////////// + //int size = 2048; + //uint32_t * data = new uint32_t[2 * size * sizeof(uint32_t)]; + //for(unsigned int i = 0; i < size; i++){ + //data[i * 2] = (uint32_t)(0.1f); + //data[i * 2 + 1] = (uint32_t)(255.0f); + //} + //glTexImage2D(GL_TEXTURE_2D, + //0, + //GL_RG32I, + //size, + //1, + //0, + //GL_RG_INTEGER, + //GL_INT, + //data); glActiveTexture(GL_TEXTURE1); glBindTexture(GL_TEXTURE_2D, curveBuffer); @@ -703,17 +736,17 @@ class Font { glActiveTexture(GL_TEXTURE0); #else glyphBuffer = glGetUniformLocation(program, "glyphs"); - glUniform1i(glyphBuffer, 0); + glUniform1i(glyphBuffer, 2); curveBuffer = glGetUniformLocation(program, "curves"); glUniform1i(curveBuffer, 1); - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_BUFFER, glyphBuffer); + //glActiveTexture(GL_TEXTURE0); + //glBindTexture(GL_TEXTURE_2D, glyphBuffer); - glActiveTexture(GL_TEXTURE1); - glBindTexture(GL_TEXTURE_BUFFER, curveBuffer); + //glActiveTexture(GL_TEXTURE1); + //glBindTexture(GL_TEXTURE_BUFFER, curveBuffer); - glActiveTexture(GL_TEXTURE0); + //glActiveTexture(GL_TEXTURE0); #endif } diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index 3f6a379..bbdf4b8 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -124,74 +124,76 @@ start. I hope to capture something essential.)DONE"; void ofApp::update(){ } - +bool hasDrawnOnce = false; //-------------------------------------------------------------- void ofApp::draw(){ - GLuint location; + if(!hasDrawnOnce){ + GLuint location; - int width = ofGetWidth(); - int height = ofGetHeight(); + int width = ofGetWidth(); + int height = ofGetHeight(); - glm::mat4 projection = transform.getProjectionMatrix((float)width / height); - glm::mat4 view = transform.getViewMatrix(); - glm::mat4 model = glm::mat4(1.0f); + glm::mat4 projection = transform.getProjectionMatrix((float)width / height); + glm::mat4 view = transform.getViewMatrix(); + glm::mat4 model = glm::mat4(1.0f); - //{ // Draw background. - //GLuint program = backgroundShader->program; - //glUseProgram(program); - //glBindVertexArray(emptyVAO); - //glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - //glBindVertexArray(0); - //glUseProgram(0); - //} + //{ // Draw background. + //GLuint program = backgroundShader->program; + //glUseProgram(program); + //glBindVertexArray(emptyVAO); + //glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + //glBindVertexArray(0); + //glUseProgram(0); + //} - ofBackground(ofColor::pink); + ofBackground(ofColor::pink); - // Uses premultiplied-alpha. - glEnable(GL_BLEND); - glBlendEquation(GL_FUNC_ADD); - glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); + // Uses premultiplied-alpha. + glEnable(GL_BLEND); + glBlendEquation(GL_FUNC_ADD); + glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA); - int currentProgram; - glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram); + int currentProgram; + glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram); - if(font){ - GLuint program = fontShader->program; - glUseProgram(program); + if(font){ + GLuint program = fontShader->program; + glUseProgram(program); - font->program = program; - font->drawSetup(); + font->program = program; + font->drawSetup(); - location = glGetUniformLocation(program, "projection"); - glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection)); + location = glGetUniformLocation(program, "projection"); + glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection)); - location = glGetUniformLocation(program, "view"); - glUniformMatrix4fv(location, 1, false, glm::value_ptr(view)); - location = glGetUniformLocation(program, "model"); - glUniformMatrix4fv(location, 1, false, glm::value_ptr(model)); - float z = 0; - location = glGetUniformLocation(program, "z"); - glUniform1f(location, z); + location = glGetUniformLocation(program, "view"); + glUniformMatrix4fv(location, 1, false, glm::value_ptr(view)); + location = glGetUniformLocation(program, "model"); + glUniformMatrix4fv(location, 1, false, glm::value_ptr(model)); + float z = 0; + location = glGetUniformLocation(program, "z"); + glUniform1f(location, z); - location = glGetUniformLocation(program, "color"); - glUniform4f(location, 1.0f, 0.0f, 1.0f, 1.0f); + location = glGetUniformLocation(program, "color"); + glUniform4f(location, 1.0f, 0.0f, 1.0f, 1.0f); - location = glGetUniformLocation(program, "antiAliasingWindowSize"); - glUniform1f(location, (float)antiAliasingWindowSize); - location = glGetUniformLocation(program, "enableSuperSamplingAntiAliasing"); - glUniform1i(location, enableSuperSamplingAntiAliasing); - location = glGetUniformLocation(program, "enableControlPointsVisualization"); - glUniform1i(location, enableControlPointsVisualization); + location = glGetUniformLocation(program, "antiAliasingWindowSize"); + glUniform1f(location, (float)antiAliasingWindowSize); + location = glGetUniformLocation(program, "enableSuperSamplingAntiAliasing"); + glUniform1i(location, enableSuperSamplingAntiAliasing); + location = glGetUniformLocation(program, "enableControlPointsVisualization"); + glUniform1i(location, enableControlPointsVisualization); - float cx = 0.5f * (bb.minX + bb.maxX); - float cy = 0.5f * (bb.minY + bb.maxY); - font->draw(-cx, -cy, 0, mainText); - glUseProgram(currentProgram); + float cx = 0.5f * (bb.minX + bb.maxX); + float cy = 0.5f * (bb.minY + bb.maxY); + font->draw(-cx, -cy, 0, mainText); + glUseProgram(currentProgram); + } + + glDisable(GL_BLEND); + + ofDrawBitmapStringHighlight("fps: " + ofToString(ofGetFrameRate()), 20, 20); } - - glDisable(GL_BLEND); - - ofDrawBitmapStringHighlight("fps: " + ofToString(ofGetFrameRate()), 20, 20); } //--------------------------------------------------------------