make GLuint fontShaderProgram global, control point visualisation, etc
This commit is contained in:
parent
0ef89aac10
commit
5c4627f247
2 changed files with 33 additions and 60 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include "ofApp.h"
|
#include "ofApp.h"
|
||||||
#include "ofAppRunner.h"
|
#include "ofAppRunner.h"
|
||||||
#include "ofGraphics.h"
|
#include "ofGraphics.h"
|
||||||
|
#include "ofRectangle.h"
|
||||||
#include "ofTexture.h"
|
#include "ofTexture.h"
|
||||||
#include "ofUtils.h"
|
#include "ofUtils.h"
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@
|
||||||
/* validate webgl shaders like this:
|
/* validate webgl shaders like this:
|
||||||
const gl = document.getElementDyId('canvas').getContext('webgl2');
|
const gl = document.getElementDyId('canvas').getContext('webgl2');
|
||||||
var get_shader=function(shadersource,shadertype)
|
var get_shader=function(shadersource,shadertype)
|
||||||
{
|
|
||||||
var shader=gl.createShader(shadertype);
|
var shader=gl.createShader(shadertype);
|
||||||
gl.shaderSource(shader,shadersource);
|
gl.shaderSource(shader,shadersource);
|
||||||
gl.compileShader(shader);
|
gl.compileShader(shader);
|
||||||
|
@ -32,8 +33,11 @@ bla bla bla
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::setup(){
|
void ofApp::setup(){
|
||||||
|
mainText_full = "A";
|
||||||
mainText = R"DONE(Some things are hard to write about. Take soil,
|
mainText = R"DONE(abcdefghijklmnopqrstuvqxyz
|
||||||
|
ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||||
|
0123456789",.!@#$%^&*()_+=-[]{})DONE";
|
||||||
|
mainText_full = R"DONE(Some things are hard to write about. Take soil,
|
||||||
for instance. Soil, Oxford dictionary reads, “is the
|
for instance. Soil, Oxford dictionary reads, “is the
|
||||||
upper layer of earth in which plants grow, a black or
|
upper layer of earth in which plants grow, a black or
|
||||||
dark brown material typically consisting of a mixture
|
dark brown material typically consisting of a mixture
|
||||||
|
@ -93,7 +97,13 @@ start. I hope to capture something essential.)DONE";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
currentFontPath = "data/celines-fonts/Version-1-var.ttf";
|
currentFontPath = "data/celines-fonts/Version-2-var.ttf";
|
||||||
|
tryUpdateMainFont(library,
|
||||||
|
currentFontPath,
|
||||||
|
mainText,
|
||||||
|
font,
|
||||||
|
bb);
|
||||||
|
|
||||||
|
|
||||||
transform = Transform();
|
transform = Transform();
|
||||||
|
|
||||||
|
@ -128,7 +138,7 @@ void ofApp::update(){
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
void ofApp::draw(){
|
void ofApp::draw(){
|
||||||
//ofBackground(backgroundColor);
|
ofBackground(backgroundColor);
|
||||||
GLuint location;
|
GLuint location;
|
||||||
|
|
||||||
int width = ofGetWidth();
|
int width = ofGetWidth();
|
||||||
|
@ -154,78 +164,40 @@ void ofApp::draw(){
|
||||||
|
|
||||||
int currentProgram;
|
int currentProgram;
|
||||||
glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram);
|
glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram);
|
||||||
if(!font){
|
|
||||||
tryUpdateMainFont(library,
|
|
||||||
currentFontPath,
|
|
||||||
mainText,
|
|
||||||
font,
|
|
||||||
bb);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(font){
|
if(font){
|
||||||
GLuint program = fontShader->program;
|
fontShaderProgram = fontShader->program;
|
||||||
glUseProgram(program);
|
glUseProgram(fontShaderProgram);
|
||||||
|
|
||||||
font->program = program;
|
font->program = fontShaderProgram;
|
||||||
font->drawSetup();
|
font->drawSetup();
|
||||||
|
|
||||||
location = glGetUniformLocation(program, "projection");
|
location = glGetUniformLocation(fontShaderProgram, "projection");
|
||||||
glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection));
|
glUniformMatrix4fv(location, 1, false, glm::value_ptr(projection));
|
||||||
|
|
||||||
location = glGetUniformLocation(program, "view");
|
location = glGetUniformLocation(fontShaderProgram, "view");
|
||||||
glUniformMatrix4fv(location, 1, false, glm::value_ptr(view));
|
glUniformMatrix4fv(location, 1, false, glm::value_ptr(view));
|
||||||
location = glGetUniformLocation(program, "model");
|
location = glGetUniformLocation(fontShaderProgram, "model");
|
||||||
glUniformMatrix4fv(location, 1, false, glm::value_ptr(model));
|
glUniformMatrix4fv(location, 1, false, glm::value_ptr(model));
|
||||||
float z = 0;
|
float z = 0;
|
||||||
location = glGetUniformLocation(program, "z");
|
location = glGetUniformLocation(fontShaderProgram, "z");
|
||||||
glUniform1f(location, z);
|
glUniform1f(location, z);
|
||||||
|
|
||||||
location = glGetUniformLocation(program, "color");
|
location = glGetUniformLocation(fontShaderProgram, "color");
|
||||||
glUniform4f(location, 1.0f, 0.0f, 1.0f, 1.0f);
|
glUniform4f(location, 1.0f, 0.0f, 1.0f, 1.0f);
|
||||||
|
|
||||||
location = glGetUniformLocation(program, "antiAliasingWindowSize");
|
location = glGetUniformLocation(fontShaderProgram, "antiAliasingWindowSize");
|
||||||
glUniform1f(location, (float)antiAliasingWindowSize);
|
glUniform1f(location, (float)antiAliasingWindowSize);
|
||||||
location = glGetUniformLocation(program, "enableSuperSamplingAntiAliasing");
|
location = glGetUniformLocation(fontShaderProgram, "enableSuperSamplingAntiAliasing");
|
||||||
glUniform1i(location, enableSuperSamplingAntiAliasing);
|
glUniform1i(location, enableSuperSamplingAntiAliasing);
|
||||||
location = glGetUniformLocation(program, "enableControlPointsVisualization");
|
location = glGetUniformLocation(fontShaderProgram, "enableControlPointsVisualization");
|
||||||
glUniform1i(location, enableControlPointsVisualization);
|
glUniform1i(location, enableControlPointsVisualization);
|
||||||
|
|
||||||
//debug_font_location = glGetUniformLocation(program, "iChannel0");
|
|
||||||
//glUniform1i(debug_font_location, 3);
|
|
||||||
|
|
||||||
if(!debug_font.isAllocated() && false){
|
|
||||||
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);
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
//debug_font.bind(debug_font_location);
|
|
||||||
|
|
||||||
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);
|
||||||
|
//ofRectangle rectangle(0, 0, width, height);
|
||||||
|
//ofDrawRectangle(rectangle);
|
||||||
font->draw(-cx, -cy, 0, mainText);
|
font->draw(-cx, -cy, 0, mainText);
|
||||||
glUseProgram(currentProgram);
|
glUseProgram(currentProgram);
|
||||||
}
|
}
|
||||||
|
@ -237,7 +209,6 @@ void ofApp::draw(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void ofApp::exit(){
|
void ofApp::exit(){
|
||||||
glDeleteTextures(1, &debug_font_location);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
@ -257,6 +228,9 @@ void ofApp::keyReleased(int key){
|
||||||
//backgroundShader = shaderCatalog->get("background");
|
//backgroundShader = shaderCatalog->get("background");
|
||||||
fontShader = shaderCatalog->get("font");
|
fontShader = shaderCatalog->get("font");
|
||||||
}
|
}
|
||||||
|
if(key == 'c'){
|
||||||
|
enableControlPointsVisualization = !enableControlPointsVisualization;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------
|
//--------------------------------------------------------------
|
||||||
|
|
|
@ -88,6 +88,7 @@ class ofApp : public ofBaseApp {
|
||||||
|
|
||||||
string currentFontPath;
|
string currentFontPath;
|
||||||
string mainText;
|
string mainText;
|
||||||
|
string mainText_full;
|
||||||
|
|
||||||
float helpFontBaseSize = 20.0f;
|
float helpFontBaseSize = 20.0f;
|
||||||
|
|
||||||
|
@ -103,8 +104,6 @@ class ofApp : public ofBaseApp {
|
||||||
|
|
||||||
bool showHelp = true;
|
bool showHelp = true;
|
||||||
|
|
||||||
ofImage debug_font;
|
|
||||||
GLuint debug_font_location;
|
|
||||||
GLuint debug_font_name;
|
|
||||||
ofFloatColor backgroundColor;
|
ofFloatColor backgroundColor;
|
||||||
|
GLuint fontShaderProgram;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue