draw debug sdfatlas
This commit is contained in:
parent
412c64298d
commit
d894c07d3e
4 changed files with 108 additions and 54 deletions
|
@ -12,6 +12,7 @@ struct Curve {
|
|||
|
||||
uniform isamplerBuffer glyphs;
|
||||
uniform samplerBuffer curves;
|
||||
uniform sampler2D iChannel0;
|
||||
uniform vec4 color;
|
||||
|
||||
|
||||
|
|
|
@ -735,8 +735,8 @@ class Font {
|
|||
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
#else
|
||||
glyphBuffer = glGetUniformLocation(program, "glyphs");
|
||||
glUniform1i(glyphBuffer, 2);
|
||||
GLint toast = glGetUniformLocation(program, "glyphs");
|
||||
glUniform1i(toast, 2);
|
||||
curveBuffer = glGetUniformLocation(program, "curves");
|
||||
glUniform1i(curveBuffer, 1);
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include "ofAppRunner.h"
|
||||
#include "ofGraphics.h"
|
||||
#include "ofTexture.h"
|
||||
#include "ofUtils.h"
|
||||
|
||||
#ifdef TARGET_EMSCRIPTEN
|
||||
#include <GLES/gl.h>
|
||||
|
@ -76,7 +77,7 @@ is going to be difficult. I don’t know yet where to
|
|||
start. I hope to capture something essential.)DONE";
|
||||
|
||||
#ifdef TARGET_EMSCRIPTEN
|
||||
string shaderDir = "data/ofxGPUFont/shaders/ES3";
|
||||
string shaderDir = "data/ofxGPUFont/shaders/DEBUG_ES3";
|
||||
#else
|
||||
string shaderDir = "data/ofxGPUFont/shaders/GL3";
|
||||
#endif
|
||||
|
@ -118,16 +119,20 @@ start. I hope to capture something essential.)DONE";
|
|||
<< " | Minor(" << ofToString(glMajor) << ")"
|
||||
<< endl;
|
||||
|
||||
auto & r = ofGetCurrentRenderer();
|
||||
cout << "Render type " << r->getType() << endl;
|
||||
backgroundColor = ofFloatColor::red;
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::update(){
|
||||
|
||||
}
|
||||
bool hasDrawnOnce = false;
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::draw(){
|
||||
if(!hasDrawnOnce){
|
||||
//ofBackground(backgroundColor);
|
||||
GLuint location;
|
||||
|
||||
int width = ofGetWidth();
|
||||
|
@ -146,8 +151,6 @@ void ofApp::draw(){
|
|||
//glUseProgram(0);
|
||||
//}
|
||||
|
||||
ofBackground(ofColor::pink);
|
||||
|
||||
// Uses premultiplied-alpha.
|
||||
glEnable(GL_BLEND);
|
||||
glBlendEquation(GL_FUNC_ADD);
|
||||
|
@ -184,16 +187,59 @@ void ofApp::draw(){
|
|||
location = glGetUniformLocation(program, "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 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);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
|
|
@ -69,6 +69,8 @@ class ofApp : public ofBaseApp {
|
|||
void dragEvent(ofDragInfo dragInfo);
|
||||
void gotMessage(ofMessage msg);
|
||||
|
||||
void exit();
|
||||
|
||||
unique_ptr <Font> font;
|
||||
FT_Library library;
|
||||
|
||||
|
@ -100,4 +102,9 @@ class ofApp : public ofBaseApp {
|
|||
bool enableControlPointsVisualization = false;
|
||||
|
||||
bool showHelp = true;
|
||||
|
||||
ofImage debug_font;
|
||||
GLuint debug_font_location;
|
||||
GLuint debug_font_name;
|
||||
ofFloatColor backgroundColor;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue