Domanda

I've got a question about using freetype fonts in opengl. I am currently reading this tutorial http://www.freetype.org/freetype2/docs/tutorial/step1.html and there is code example http://www.freetype.org/freetype2/docs/tutorial/example1.c

In method draw_bitmap

FT_Int  i, j, p, q;
FT_Int  x_max = x + bitmap->width;
FT_Int  y_max = y + bitmap->rows;


for ( i = x, p = 0; i < x_max; i++, p++ )
{
  for ( j = y, q = 0; j < y_max; j++, q++ )
  {
    if ( i < 0      || j < 0       ||
         i >= WIDTH || j >= HEIGHT )
      continue;

    image[j][i] |= bitmap->buffer[q * bitmap->width + p];
  }
}

they fill array unsigned char image[HEIGHT][WIDTH]; with data and then show image in console using putchar.

int  i, j;


for ( i = 0; i < HEIGHT; i++ )
{
  for ( j = 0; j < WIDTH; j++ )
    putchar( image[i][j] == 0 ? ' '
                              : image[i][j] < 128 ? '+'
                                                  : '*' );
  putchar( '\n' );
}

So the question is - this array image is matrix, which contains the coordinates of pixels on the screen? And in order to draw pixel I need to use glRasterPos2i?

È stato utile?

Soluzione

You can try loading image as a texture, then render that texture on a quad.

This guy had issues, and solved them, should be the code you're looking for:

Problems copying freetype bitmap to opengl texture

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top