Okay, I did what you tell but the glyph is not rendering. Still is an white rectangle.
I cleared my code, so now you have full code:
#include <OpenGL/OpenGL.h>
#include <GLFW/glfw3.h>
#include <GLUT/glut.h>
#include <ft2build.h>
#include <freetype.h>
#include <iostream>
#include <string>
int main()
{
GLFWwindow *glfwWindow = NULL;
int width = 1280;
int height = 800;
std::string font = "/System/Library/Fonts/Menlo.ttc";
FT_Library library;
FT_Face face;
if(!glfwInit())
{
return -2;
}
/* Create a windowed mode window and its OpenGL context */
glfwWindow = glfwCreateWindow(width, height, "Sandbox", NULL, NULL);
if(!glfwWindow)
{
glfwTerminate();
return -1;
}
/* Make the window's context current */
glfwMakeContextCurrent(glfwWindow);
glMatrixMode(GL_PROJECTION);
glOrtho(0, width, 0, height, -1, 1);
glClearColor(0.22f, 0.23f, 0.24f, 1.0f);
FT_Init_FreeType(&library);
FT_New_Face(library, font.c_str(), 0, &face);
FT_Set_Char_Size(
face, /* handle to face object */
0, /* char_width in 1/64th of points */
16 * 64, /* char_height in 1/64th of points */
300, /* horizontal device resolution */
300 /* vertical device resolution */
);
FT_Load_Char(face, 'A', FT_LOAD_DEFAULT);
FT_Render_Glyph(face->glyph, FT_RENDER_MODE_NORMAL);
/* Loop until the user closes the window */
glMatrixMode(GL_MODELVIEW);
while (!glfwWindowShouldClose(glfwWindow))
{
/* Render here */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glEnable(GL_TEXTURE_2D);
GLuint texture;
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
// FreeType
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(
GL_TEXTURE_2D, 0, GL_LUMINANCE, face->glyph->bitmap.width, face->glyph->bitmap.rows, GL_LUMINANCE, 0,
GL_UNSIGNED_BYTE, face->glyph->bitmap.buffer
);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex2i(0, face->glyph->bitmap.rows);
glTexCoord2f(1.0, 0.0);
glVertex2i(face->glyph->bitmap.width, face->glyph->bitmap.rows);
glTexCoord2f(1.0, 1.0);
glVertex2i(face->glyph->bitmap.width, 0);
glTexCoord2f(0.0, 1.0);
glVertex2i(0, 0);
glEnd();
glPopMatrix();
glfwSwapBuffers(glfwWindow);
glfwPollEvents();
}
FT_Done_FreeType(library);
return 0;
}
Thanks for your patience!
Edit: My glGetError() returns 1281.
Edit: Error is after line
glTexImage2D(
GL_TEXTURE_2D, 0, GL_LUMINANCE, face->glyph->bitmap.width, face->glyph->bitmap.rows, GL_LUMINANCE, 0,
GL_UNSIGNED_BYTE, face->glyph->bitmap.buffer
);
Problem fixed. My mistake was I changed position with different parameters on glTexImage2D. Thanks!