Open Geistyp opened 11 years ago
Use vertex attribute and render with ofShader. https://github.com/Geistyp/ofxFontStash/blob/iOS-ProgrammableRender/libs/fontstash/src/fontstash.c
static void flush_draw(struct sth_stash* stash) { static ofShader sth_shader; if ( !sth_shader.isLoaded() ){ #define STRINGIFY(A) #A string vertexment = STRINGIFY( attribute vec4 position; attribute vec2 texcoord; varying vec2 texCoordVarying; uniform mat4 textureMatrix; uniform mat4 modelViewProjectionMatrix; void main(){ //get our current vertex position so we can modify it vec4 pos = modelViewProjectionMatrix * position; gl_Position = pos; texCoordVarying = (textureMatrix*vec4(texcoord.x,texcoord.y,0,1)).xy; } ); string fragment = STRINGIFY( precision highp float; uniform sampler2D tex; varying vec2 texCoordVarying; void main() { vec4 color = texture2D( tex, texCoordVarying ); gl_FragColor = color; } ); sth_shader.setupShaderFromSource(GL_VERTEX_SHADER, vertexment); sth_shader.setupShaderFromSource(GL_FRAGMENT_SHADER, fragment); sth_shader.bindAttribute(0, "position"); sth_shader.bindAttribute(1, "texcoord"); sth_shader.linkProgram(); } struct sth_texture* texture = stash->tt_textures; short tt = 1; while (texture) { if (texture->nverts > 0) { /* glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, texture->id); glEnable(GL_TEXTURE_2D); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(2, GL_FLOAT, VERT_STRIDE, texture->verts); glTexCoordPointer(2, GL_FLOAT, VERT_STRIDE, texture->verts+2); glDrawArrays(GL_TRIANGLES, 0, texture->nverts); glDisable(GL_TEXTURE_2D); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glBindTexture(GL_TEXTURE_2D, 0); texture->nverts = 0; */ glEnableVertexAttribArray(sth_shader.getAttributeLocation("position")); glVertexAttribPointer(sth_shader.getAttributeLocation("position"), 2, GL_FLOAT, GL_FALSE, VERT_STRIDE, texture->verts); glEnableVertexAttribArray(sth_shader.getAttributeLocation("texcoord")); glVertexAttribPointer(sth_shader.getAttributeLocation("texcoord"), 2, GL_FLOAT, GL_FALSE, VERT_STRIDE, texture->verts+2); sth_shader.begin(); sth_shader.setUniformTexture("tex", GL_TEXTURE_2D, texture->id, 0); glDrawArrays(GL_TRIANGLES, 0, texture->nverts); sth_shader.end(); glDisableVertexAttribArray(sth_shader.getAttributeLocation("texcoord")); glDisableVertexAttribArray(sth_shader.getAttributeLocation("position")); texture->nverts = 0; } texture = texture->next; if (!texture && tt) { texture = stash->bm_textures; tt = 0; } } }
Test in iOS. But seems like slower than ofDrawBitmapString(). And get diff run in simulator and device.
-SIMULATOR
-DEVICE
Yep, support for ofGLProgrammableRenderer would be handy!
Plus 1 to this!
Use vertex attribute and render with ofShader. https://github.com/Geistyp/ofxFontStash/blob/iOS-ProgrammableRender/libs/fontstash/src/fontstash.c
Test in iOS. But seems like slower than ofDrawBitmapString(). And get diff run in simulator and device.
-SIMULATOR
-DEVICE