Draw text in openGL ES iPhone using only objective-c

It is necessary to draw some text in openGL, and then rotate and translate it. Only objective-c should be used. Any help?

+3
source share
2 answers

Use Photoshop or something to create a texture file as shown below.

|ABCDEFGH|
|IJKLMNOP|
|QRSTU...|

sample.png

Calculate the UV position of each character.

float eachCharHeight = 0.125f;
float eachCharWidth = 0.125f;
char charToDraw = 'a';
int indexOfChar = charToDraw - 65; // 'a' = 65
float uValueForCharA = (float)(indexOfChar / 8) * eachCharHeight;
float vValueForCharA = (float)(indexOfChar % 8) * eachCharWidth;

Set texcoords and draw.

glPushMatrix();
glRotatef(...);  // or translate

glEnable(GL_TEXTURE_2D);
glBindTexture(texture);

float vertices[8] = {0.0f, 0.0f, 1.0f, 0.0f, ...};
float texcoords[8] = {uValueForCharA, vValueForCharA, 
                      uValueForCharA + eachCharWidth, ...};

...

glPopMatrix();
+4
source

AFAIK (.), 2-D (Quartz), opengl, , , , UILabel opengl.

+2

Source: https://habr.com/ru/post/1750815/


All Articles