draw debug sdfatlas

This commit is contained in:
jrkb 2023-04-02 16:14:14 +02:00
parent 412c64298d
commit d894c07d3e
4 changed files with 108 additions and 54 deletions

View file

@ -12,6 +12,7 @@ struct Curve {
uniform isamplerBuffer glyphs; uniform isamplerBuffer glyphs;
uniform samplerBuffer curves; uniform samplerBuffer curves;
uniform sampler2D iChannel0;
uniform vec4 color; uniform vec4 color;

View file

@ -735,8 +735,8 @@ class Font {
glActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0);
#else #else
glyphBuffer = glGetUniformLocation(program, "glyphs"); GLint toast = glGetUniformLocation(program, "glyphs");
glUniform1i(glyphBuffer, 2); glUniform1i(toast, 2);
curveBuffer = glGetUniformLocation(program, "curves"); curveBuffer = glGetUniformLocation(program, "curves");
glUniform1i(curveBuffer, 1); glUniform1i(curveBuffer, 1);

View file

@ -2,6 +2,7 @@
#include "ofAppRunner.h" #include "ofAppRunner.h"
#include "ofGraphics.h" #include "ofGraphics.h"
#include "ofTexture.h" #include "ofTexture.h"
#include "ofUtils.h"
#ifdef TARGET_EMSCRIPTEN #ifdef TARGET_EMSCRIPTEN
#include <GLES/gl.h> #include <GLES/gl.h>
@ -76,7 +77,7 @@ is going to be difficult. I dont know yet where to
start. I hope to capture something essential.)DONE"; start. I hope to capture something essential.)DONE";
#ifdef TARGET_EMSCRIPTEN #ifdef TARGET_EMSCRIPTEN
string shaderDir = "data/ofxGPUFont/shaders/ES3"; string shaderDir = "data/ofxGPUFont/shaders/DEBUG_ES3";
#else #else
string shaderDir = "data/ofxGPUFont/shaders/GL3"; string shaderDir = "data/ofxGPUFont/shaders/GL3";
#endif #endif
@ -118,16 +119,20 @@ start. I hope to capture something essential.)DONE";
<< " | Minor(" << ofToString(glMajor) << ")" << " | Minor(" << ofToString(glMajor) << ")"
<< endl; << endl;
auto & r = ofGetCurrentRenderer();
cout << "Render type " << r->getType() << endl;
backgroundColor = ofFloatColor::red;
} }
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::update(){ void ofApp::update(){
} }
bool hasDrawnOnce = false;
//-------------------------------------------------------------- //--------------------------------------------------------------
void ofApp::draw(){ void ofApp::draw(){
if(!hasDrawnOnce){ //ofBackground(backgroundColor);
GLuint location; GLuint location;
int width = ofGetWidth(); int width = ofGetWidth();
@ -146,8 +151,6 @@ void ofApp::draw(){
//glUseProgram(0); //glUseProgram(0);
//} //}
ofBackground(ofColor::pink);
// Uses premultiplied-alpha. // Uses premultiplied-alpha.
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD); glBlendEquation(GL_FUNC_ADD);
@ -184,16 +187,59 @@ void ofApp::draw(){
location = glGetUniformLocation(program, "enableControlPointsVisualization"); location = glGetUniformLocation(program, "enableControlPointsVisualization");
glUniform1i(location, enableControlPointsVisualization); glUniform1i(location, enableControlPointsVisualization);
debug_font_location = glGetUniformLocation(program, "iChannel0");
glUniform1i(debug_font_location, 3);
if(!debug_font.isAllocated()){
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);
}
//debug_font.bind(debug_font_location);
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);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
float cx = 0.5f * (bb.minX + bb.maxX); float cx = 0.5f * (bb.minX + bb.maxX);
float cy = 0.5f * (bb.minY + bb.maxY); float cy = 0.5f * (bb.minY + bb.maxY);
font->draw(-cx, -cy, 0, mainText); font->draw(-cx, -cy, 0, mainText);
glUseProgram(currentProgram); glUseProgram(currentProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
} }
glDisable(GL_BLEND); glDisable(GL_BLEND);
ofDrawBitmapStringHighlight("fps: " + ofToString(ofGetFrameRate()), 20, 20); ofDrawBitmapStringHighlight("fps: " + ofToString(ofGetFrameRate()), 20, 20);
} backgroundColor = ofFloatColor::pink;
}
void ofApp::exit(){
glDeleteTextures(1, &debug_font_location);
} }
//-------------------------------------------------------------- //--------------------------------------------------------------

View file

@ -69,6 +69,8 @@ class ofApp : public ofBaseApp {
void dragEvent(ofDragInfo dragInfo); void dragEvent(ofDragInfo dragInfo);
void gotMessage(ofMessage msg); void gotMessage(ofMessage msg);
void exit();
unique_ptr <Font> font; unique_ptr <Font> font;
FT_Library library; FT_Library library;
@ -100,4 +102,9 @@ class ofApp : public ofBaseApp {
bool enableControlPointsVisualization = false; bool enableControlPointsVisualization = false;
bool showHelp = true; bool showHelp = true;
ofImage debug_font;
GLuint debug_font_location;
GLuint debug_font_name;
ofFloatColor backgroundColor;
}; };