Last active
August 29, 2015 14:24
-
-
Save moxuse/73cff10f4cfcace10121 to your computer and use it in GitHub Desktop.
ofTrueTypeFont to ofVbo Texture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SomeClass { | |
private: | |
string textString; | |
ofTrueTypeFont font; | |
ofTexture stringTexture; | |
ofVbo vbo; | |
ofMesh stringMesh; | |
ofVec3f verts[VERT_BUF_NUM]; | |
ofFloatColor colors[VERT_BUF_NUM]; | |
ofVec3f position; | |
float pointSizesX[VERT_BUF_NUM]; | |
float pointSizesY[VERT_BUF_NUM]; | |
float pointSizesZ[VERT_BUF_NUM]; | |
ofVec3f storePositions[VERT_BUF_NUM * 2]; | |
public: | |
SomeClass(){}; | |
~SomeClass(){ | |
stringTexture.clear(); | |
buf.clear(); | |
vbo.clear(); | |
}; | |
void setup(ofTrueTypeFont &_font, string fileName) { | |
textString = buf.getText(); | |
font = _font; | |
if (font.isLoaded()) { | |
stringMesh = font.getStringMesh(buf.getText(), -8002, -12280); | |
memset(storePositions, 0, sizeof(ofVec3f) * stringMesh.getNumVertices()); | |
memcpy(storePositions, stringMesh.getVerticesPointer(), sizeof(ofVec3f) * stringMesh.getNumVertices()); | |
stringTexture = font.getFontTexture(); | |
if (stringTexture.isAllocated()) { | |
for (int i = 0; i < VERT_BUF_NUM; i++) { | |
stringMesh.addColor(ofFloatColor(1.1, 1.1, 1.1, 0.8)); | |
if (0 == i%4) { | |
float x = (ofRandom(0, 2) * 4.0 - 2.0); | |
float y = (ofRandom(0, 2) * 7.0); | |
float z = 0; | |
pointSizesX[i] = x; | |
pointSizesX[i+1] = x; | |
pointSizesX[i+2] = x; | |
pointSizesX[i+3] = x; | |
pointSizesY[i] = y; | |
pointSizesY[i+1] = y; | |
pointSizesY[i+2] = y; | |
pointSizesY[i+3] = y; | |
pointSizesZ[i] = z; | |
pointSizesZ[i+1] = z; | |
pointSizesZ[i+2] = z; | |
pointSizesZ[i+3] = z; | |
} | |
} | |
vbo.setMesh(stringMesh, GL_DYNAMIC_DRAW); | |
} | |
} | |
cout << "setuped : " << stringMesh.getIndices().size() << endl; | |
} | |
void draw() { | |
if (NULL != &stringTexture && stringTexture.isAllocated()) { | |
vector<ofVec3f> targetVec = stringMesh.getVertices(); | |
///////////////////////////// | |
stringTexture.bind(); | |
vbo.draw(GL_QUADS, 0, stringMesh.getIndices().size()); | |
stringTexture.unbind(); | |
///////////////////////////// | |
}; | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment