PhantomEngine/RHI/OpenGL/OpenGLGraphicsManager.cpp
//need to go further ; pack all glyphs into one texture and record uvs.
need to go further ; pack all glyphs into one texture and record uvs.
need to go further ; pack all glyphs into one texture and record uvs .
bool OpenGLGraphicsManager::initializeTextVao()
	{
		glGenTextures(1, &m_TextTextureId);
		glBindTexture(GL_TEXTURE_2D, m_TextTextureId);
		glTexImage2D(
			GL_TEXTURE_2D,
			0,
			GL_RED,
			TextCore::K_TEXTURE_SIZE,
			TextCore::K_TEXTURE_SIZE,
			0,
			GL_RED,
			GL_UNSIGNED_BYTE,
			0
		);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
		int xStart = 0;
		int yStart = 0;
		for (int i = 0; i < 128; i++) {
			if (xStart + TextCore::K_FONT_SIZE > TextCore::K_TEXTURE_SIZE)
			{
				xStart = 0;
				yStart += TextCore::K_FONT_SIZE;
			}
			fontEngine.RenderGlyphToTextureData(i);
			TextCore::Character &c = fontEngine.m_Characters.at(i);
			glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
			glTexSubImage2D(
				GL_TEXTURE_2D,
				0,
				xStart,
				yStart,
				c.Size.x,
				c.Size.y,
				GL_RED,
				GL_UNSIGNED_BYTE,
				c.buffer
			);
			c.offset.x = xStart;
			c.offset.y = yStart;
			xStart += c.Size.x + 1;
		}
		glBindTexture(GL_TEXTURE_2D, 0);
		glGenVertexArrays(1, &m_TextVaoId);
		glGenBuffers(1, &m_TextVboId);
		glBindVertexArray(m_TextVaoId);
		glBindBuffer(GL_ARRAY_BUFFER, m_TextVboId);
		glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * 6 * 4, NULL, GL_DYNAMIC_DRAW);
		glEnableVertexAttribArray(0);
		glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GLfloat), 0);
		glBindBuffer(GL_ARRAY_BUFFER, 0);
		glBindVertexArray(0);
		return true;
	}
bool OpenGLGraphicsManager :: initializeTextVao ( ) { glGenTextures ( 1 , & m_TextTextureId ) ; glBindTexture ( GL_TEXTURE_2D , m_TextTextureId ) ; glTexImage2D ( GL_TEXTURE_2D , 0 , GL_RED , TextCore :: K_TEXTURE_SIZE , TextCore :: K_TEXTURE_SIZE , 0 , GL_RED , GL_UNSIGNED_BYTE , 0 ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_S , GL_CLAMP_TO_EDGE ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_WRAP_T , GL_CLAMP_TO_EDGE ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MIN_FILTER , GL_LINEAR ) ; glTexParameteri ( GL_TEXTURE_2D , GL_TEXTURE_MAG_FILTER , GL_LINEAR ) ; glPixelStorei ( GL_UNPACK_ALIGNMENT , 1 ) ; int xStart = 0 ; int yStart = 0 ; for ( int i = 0 ; i < 128 ; i ++ ) { if ( xStart + TextCore :: K_FONT_SIZE > TextCore :: K_TEXTURE_SIZE ) { xStart = 0 ; yStart += TextCore :: K_FONT_SIZE ; } fontEngine . RenderGlyphToTextureData ( i ) ; TextCore :: Character & c = fontEngine . m_Characters . at ( i ) ; glPixelStorei ( GL_UNPACK_ALIGNMENT , 1 ) ; glTexSubImage2D ( GL_TEXTURE_2D , 0 , xStart , yStart , c . Size . x , c . Size . y , GL_RED , GL_UNSIGNED_BYTE , c . buffer ) ; c . offset . x = xStart ; c . offset . y = yStart ; xStart += c . Size . x + 1 ; } glBindTexture ( GL_TEXTURE_2D , 0 ) ; glGenVertexArrays ( 1 , & m_TextVaoId ) ; glGenBuffers ( 1 , & m_TextVboId ) ; glBindVertexArray ( m_TextVaoId ) ; glBindBuffer ( GL_ARRAY_BUFFER , m_TextVboId ) ; glBufferData ( GL_ARRAY_BUFFER , sizeof ( GLfloat ) * 6 * 4 , NULL , GL_DYNAMIC_DRAW ) ; glEnableVertexAttribArray ( 0 ) ; glVertexAttribPointer ( 0 , 4 , GL_FLOAT , GL_FALSE , 4 * sizeof ( GLfloat ) , 0 ) ; glBindBuffer ( GL_ARRAY_BUFFER , 0 ) ; glBindVertexArray ( 0 ) ; return true ; }
need to go further ; pack all glyphs into one texture and record uvs.
need to go further ; pack all glyphs into one texture and record uvs .
// Disable byte-alignment restriction // Set texture options // Configure VAO/VBO for texture quads