Drawing Text using glTextImage2D + FreeType : GL_INVALID_ENUM error

Hello,

So, fresh off of my last post I am running into an issue with using code that normally works. Essentially I am working off of this example online: http://en.wikibooks.org/wiki/OpenGL_Programming/Modern_OpenGL_Tutorial_Text_Rendering_01

And here is the code snippet that is giving me the GL_INVALID_ENUM error. The actual error occurs on the glTextImage2D() call.

glDisable(GL_CULL_FACE);
glUseProgram(TextProgramShaderID);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, tex);
glUniform1i(TextureUniform, 0);
glBindVertexArray(TextureVertexArrayObjectID);
const char *p;
glBindBuffer(GL_ARRAY_BUFFER, TextureVertexBufferObjectID);
for (p = text; *p; p++) {
	if (FT_Load_Char(face, *p, FT_LOAD_RENDER))
		continue;
	glTexImage2D(
		GL_TEXTURE_2D,
		0,
		GL_ALPHA,
		gFont->bitmap.width,
		gFont->bitmap.rows,
		0,
		GL_ALPHA,
		GL_UNSIGNED_BYTE,
		gFont->bitmap.buffer
		);
	float x2 = x + gFont->bitmap_left * sx;
	float y2 = -y - gFont->bitmap_top * sy;
	float w = gFont->bitmap.width * sx;
	float h = gFont->bitmap.rows * sy;
	GLfloat box[4][4] = {
		{ x2, -y2, 0, 0 },
		{ x2 + w, -y2, 1, 0 },
		{ x2, -y2 - h, 0, 1 },
		{ x2 + w, -y2 - h, 1, 1 },
	};
	glBufferData(GL_ARRAY_BUFFER, sizeof box, box, GL_DYNAMIC_DRAW);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	x += (gFont->advance.x >> 6) * sx;
	y += (gFont->advance.y >> 6) * sy;

}
glBindBuffer(GL_ARRAY_BUFFER, NULL);
glBindVertexArray(NULL);
glBindTexture(GL_TEXTURE_2D, NULL);
glUseProgram(PrimaryProgramShaderID);
glEnable(GL_CULL_FACE);

I am not sure what is happening here to cause the error; I stepped through the code and each of the uniforms have values associated with the bound shader and there is data coming into the supplied arguments.

Any ideas?

Thank you.

IIRC GL_ALPHA is not a valid internal format (3rd parameter to glTexImage2D), for a single channel texture use GL_RED or a sized variant of it, e.g. GL_R8. The glTexImage2D man page has tables with the various valid values.

Thank you for your quick reply!

What about the 7th parameter? Same thing applies with using GL_RED or the variant?