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,82 +119,127 @@ 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();
int height = ofGetHeight(); int height = ofGetHeight();
glm::mat4 projection = transform.getProjectionMatrix((float)width / height); glm::mat4 projection = transform.getProjectionMatrix((float)width / height);
glm::mat4 view = transform.getViewMatrix(); glm::mat4 view = transform.getViewMatrix();
glm::mat4 model = glm::mat4(1.0f); glm::mat4 model = glm::mat4(1.0f);
//{ // Draw background. //{ // Draw background.
//GLuint program = backgroundShader->program; //GLuint program = backgroundShader->program;
//glUseProgram(program); //glUseProgram(program);
//glBindVertexArray(emptyVAO); //glBindVertexArray(emptyVAO);
//glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); //glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
//glBindVertexArray(0); //glBindVertexArray(0);
//glUseProgram(0); //glUseProgram(0);
//} //}
ofBackground(ofColor::pink); // Uses premultiplied-alpha.
glEnable(GL_BLEND);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
// Uses premultiplied-alpha. int currentProgram;
glEnable(GL_BLEND); glGetIntegerv(GL_CURRENT_PROGRAM, &currentProgram);
glBlendEquation(GL_FUNC_ADD);
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
int currentProgram; if(font){
glGetIntegerv(GL_CURRENT_PROGRAM, &currentProgram); GLuint program = fontShader->program;
glUseProgram(program);
if(font){ font->program = program;
GLuint program = fontShader->program; font->drawSetup();
glUseProgram(program);
font->program = program; location = glGetUniformLocation(program, "projection");
font->drawSetup(); glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection));
location = glGetUniformLocation(program, "projection"); location = glGetUniformLocation(program, "view");
glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection)); 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"); location = glGetUniformLocation(program, "color");
glUniformMatrix4fv(location, 1, false, glm::value_ptr(view)); glUniform4f(location, 1.0f, 0.0f, 1.0f, 1.0f);
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"); location = glGetUniformLocation(program, "antiAliasingWindowSize");
glUniform4f(location, 1.0f, 0.0f, 1.0f, 1.0f); glUniform1f(location, (float)antiAliasingWindowSize);
location = glGetUniformLocation(program, "enableSuperSamplingAntiAliasing");
glUniform1i(location, enableSuperSamplingAntiAliasing);
location = glGetUniformLocation(program, "enableControlPointsVisualization");
glUniform1i(location, enableControlPointsVisualization);
location = glGetUniformLocation(program, "antiAliasingWindowSize"); debug_font_location = glGetUniformLocation(program, "iChannel0");
glUniform1f(location, (float)antiAliasingWindowSize); glUniform1i(debug_font_location, 3);
location = glGetUniformLocation(program, "enableSuperSamplingAntiAliasing");
glUniform1i(location, enableSuperSamplingAntiAliasing);
location = glGetUniformLocation(program, "enableControlPointsVisualization");
glUniform1i(location, enableControlPointsVisualization);
float cx = 0.5f * (bb.minX + bb.maxX); if(!debug_font.isAllocated()){
float cy = 0.5f * (bb.minY + bb.maxY); debug_font.setUseTexture(false);
font->draw(-cx, -cy, 0, mainText); debug_font.load("sdfatlas.png");
glUseProgram(currentProgram); //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);
glDisable(GL_BLEND); 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);
ofDrawBitmapStringHighlight("fps: " + ofToString(ofGetFrameRate()), 20, 20); glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
float cx = 0.5f * (bb.minX + bb.maxX);
float cy = 0.5f * (bb.minY + bb.maxY);
font->draw(-cx, -cy, 0, mainText);
glUseProgram(currentProgram);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, 0);
} }
glDisable(GL_BLEND);
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;
}; };