Reputation: 135
I'm trying to display text rotated by 90 degrees using rsgDrawText with Renderscript. The Font class and rsgDrawText call don't seem to support any text orientation. Ican't rotate the activity in portrait/landscape so Ineed to figure out another way to achieve this. I tried some experiments by using rsMatrixRotate to the vertex shader but text doesn't seem to be affected by this transformation. I'm using a transparent surface which only draws text with Renderscript on top of another activity. So anything like, changing the surface orientation itself, would probably work fine. What would be the best way to draw text rotated by 90 degrees with Renderscript?
Upvotes: 0
Views: 686
Reputation: 20262
You can use glMatrixRotate
to create a rotation matrix, and then use rsgProgramVertexLoadModelMatrix
to load that matrix as the model matrix. I suspect it's this latter part that you missed in your experiments.
For example, this simple renderscript will draw "Hello!" at (200, 200) on the screen and then again, rotated 90 degrees around the bottom left corner of the text.
int root() {
rsgClearColor(0.0, 0.0, 0.0, 0.0);
rsgFontColor(1.0, 1.0, 1.0, 1.0);
rsgDrawText("Hello!", 200, 200);
rs_matrix4x4 matrix;
rsMatrixLoadIdentity(&matrix);
rsMatrixTranslate(&matrix, 200, 200, 0);
rsMatrixRotate(&matrix, 90, 0, 0, 1);
rsgProgramVertexLoadModelMatrix(&matrix);
rsgDrawText("Hello!", 0, 0);
return 0;
}
Upvotes: 2