259 lines
8.1 KiB
C++
259 lines
8.1 KiB
C++
#include "ofApp.h"
|
||
#include "ofAppRunner.h"
|
||
#include "ofGraphics.h"
|
||
#include "ofTexture.h"
|
||
|
||
#ifdef TARGET_EMSCRIPTEN
|
||
#include <GLES/gl.h>
|
||
#include <emscripten/emscripten.h>
|
||
#endif
|
||
|
||
/* validate webgl shaders like this:
|
||
const gl = document.getElementDyId('canvas').getContext('webgl2');
|
||
var get_shader=function(shadersource,shadertype)
|
||
{
|
||
var shader=gl.createShader(shadertype);
|
||
gl.shaderSource(shader,shadersource);
|
||
gl.compileShader(shader);
|
||
|
||
// Check for any compilation error
|
||
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
|
||
alert(gl.getShaderInfoLog(shader));
|
||
return null;
|
||
}
|
||
|
||
return shader;
|
||
}
|
||
get_shader(`#version 300 es
|
||
bla bla bla
|
||
`, gl.FRAGMENT_SHADER); // -> aaaand error
|
||
*/
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::setup(){
|
||
|
||
mainText = R"DONE(Some things are hard to write about. Take soil,
|
||
for instance. Soil, Oxford dictionary reads, “is the
|
||
upper layer of earth in which plants grow, a black or
|
||
dark brown material typically consisting of a mixture
|
||
of organic remains, clay, and rock particles”.
|
||
I wonder why I have chosen to write
|
||
about soil, as I don’t seem to have had many
|
||
encounters with it. Perhaps because of that?
|
||
Intuiting its importance, but never minding it?
|
||
So far it has appeared rather distant. Absent
|
||
from my thoughts and words. But now, when
|
||
I think of it, I see a charismatic substance.
|
||
Soil, according to Merriam-Webster, is
|
||
“1. firm land: earth;
|
||
2. a) the upper layer of earth that may be dug
|
||
or plowed and in which plants grow; and
|
||
b) the superficial unconsolidated and
|
||
usually weathered part of the mantle of
|
||
a planet and especially of the earth”.
|
||
|
||
The Soil Science Society of America defines soil
|
||
as “a mixture of minerals, dead and living
|
||
organisms (organic materials), air, and water.”
|
||
The “soil” entry in Encyclopaedia Britannica starts
|
||
with “soil is the biologically active,
|
||
porous medium […] serving as a reservoir of
|
||
water and nutrients, as a medium for the filtration
|
||
and breakdown of injurious wastes, and as
|
||
a participant in the cycling of carbon and other
|
||
elements through the global ecosystem.”
|
||
Such nebulous definitions, though, aren’t
|
||
most definitions unsettled? (all definitions are
|
||
blasphemy!)… like “soil is (a mix of) all and nothing,
|
||
doing anything and everything, everywhere”. How
|
||
one defines or translates soil by posing a question
|
||
always affects the answer. Soil can mean earth,
|
||
ground, dirt, clay, turf, humus, silt, loam, land,
|
||
clod, terra, territory, landscape, country, a political
|
||
power base, an aspect of divinity, a terrain
|
||
to cultivate, or a resource to be exploited… This
|
||
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";
|
||
#else
|
||
string shaderDir = "data/ofxGPUFont/shaders/GL3";
|
||
#endif
|
||
shaderCatalog = std::make_unique <ShaderCatalog>(shaderDir);
|
||
//backgroundShader = shaderCatalog->get("background");
|
||
fontShader = shaderCatalog->get("font");
|
||
|
||
{
|
||
FT_Error error = FT_Init_FreeType(&library);
|
||
if(error){
|
||
std::cerr << "ERROR: failed to initialize FreeType" << std::endl;
|
||
ofExit();
|
||
}
|
||
}
|
||
|
||
currentFontPath = "data/celines-fonts/Version-1-var.ttf";
|
||
tryUpdateMainFont(library,
|
||
currentFontPath,
|
||
mainText,
|
||
font,
|
||
bb);
|
||
|
||
transform = Transform();
|
||
|
||
int maxSamples;
|
||
glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
|
||
cout << "MAX_SAMPLES: " << ofToString(maxSamples) << endl;
|
||
int maxTexSize;
|
||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxTexSize);
|
||
cout << "MAX_TEXTURE_SIZE: " << ofToString(maxTexSize) << endl;
|
||
|
||
const unsigned char * glVersion = glGetString(GL_VERSION);
|
||
int glMajor, glMinor;
|
||
glGetIntegerv(GL_MAJOR_VERSION, &glMajor);
|
||
glGetIntegerv(GL_MINOR_VERSION, &glMinor);
|
||
|
||
cout << "GL_VERSION: " << glVersion
|
||
<< " | Major(" << ofToString(glMajor) << ")"
|
||
<< " | Minor(" << ofToString(glMajor) << ")"
|
||
<< endl;
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::update(){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::draw(){
|
||
GLuint location;
|
||
|
||
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);
|
||
|
||
//{ // 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);
|
||
|
||
int currentProgram;
|
||
glGetIntegerv(GL_CURRENT_PROGRAM, ¤tProgram);
|
||
|
||
if(font){
|
||
GLuint program = fontShader->program;
|
||
glUseProgram(program);
|
||
|
||
font->program = program;
|
||
font->drawSetup();
|
||
|
||
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, "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);
|
||
|
||
float cx = 0.5f * (bb.minX + bb.maxX);
|
||
float cy = 0.5f * (bb.minY + bb.maxY);
|
||
font->draw(-cx, -cy, 0, mainText);
|
||
glUseProgram(currentProgram);
|
||
}
|
||
|
||
glDisable(GL_BLEND);
|
||
|
||
ofDrawBitmapStringHighlight("fps: " + ofToString(ofGetFrameRate()), 20, 20);
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::keyPressed(int key){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::keyReleased(int key){
|
||
if(key == 'l'){
|
||
#ifdef TARGET_EMSCRIPTEN
|
||
string shaderDir = "data/ofxGPUFont/shaders/ES3";
|
||
#else
|
||
string shaderDir = "data/ofxGPUFont/shaders/GL3";
|
||
#endif
|
||
shaderCatalog = std::make_unique <ShaderCatalog>(shaderDir);
|
||
//backgroundShader = shaderCatalog->get("background");
|
||
fontShader = shaderCatalog->get("font");
|
||
}
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::mouseMoved(int x, int y){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::mouseDragged(int x, int y, int button){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::mousePressed(int x, int y, int button){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::mouseReleased(int x, int y, int button){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::mouseEntered(int x, int y){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::mouseExited(int x, int y){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::windowResized(int w, int h){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::gotMessage(ofMessage msg){
|
||
|
||
}
|
||
|
||
//--------------------------------------------------------------
|
||
void ofApp::dragEvent(ofDragInfo dragInfo){
|
||
|
||
}
|