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,82 +119,127 @@ 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){
|
||||
GLuint location;
|
||||
//ofBackground(backgroundColor);
|
||||
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);
|
||||
// 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);
|
||||
debug_font_location = glGetUniformLocation(program, "iChannel0");
|
||||
glUniform1i(debug_font_location, 3);
|
||||
|
||||
float cx = 0.5f * (bb.minX + bb.maxX);
|
||||
float cy = 0.5f * (bb.minY + bb.maxY);
|
||||
font->draw(-cx, -cy, 0, mainText);
|
||||
glUseProgram(currentProgram);
|
||||
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);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
|
|
@ -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