2008-09-04, 00:59
Hi all,
I'm trying to migrate XBMC's GL code to use vertex/color/texcoord arrays instead of immediate mode and am running into some problems. To start, I am modifying the GUIFontTTF.cpp renderer. However, it seems to only render the last character, and the character doesn't look exactly correct.
I am pasting the diff below, please let me now if you see anything I'm doing wrong. Yes, I've added vertices[], texCoords[], and colorArray[] to the CGUIFontTTF class, didn't add that in the diff because I thought it was rather implied.
Thanks!
(btw, I'm new to the forums here, so hi everyone)
I'm trying to migrate XBMC's GL code to use vertex/color/texcoord arrays instead of immediate mode and am running into some problems. To start, I am modifying the GUIFontTTF.cpp renderer. However, it seems to only render the last character, and the character doesn't look exactly correct.
I am pasting the diff below, please let me now if you see anything I'm doing wrong. Yes, I've added vertices[], texCoords[], and colorArray[] to the CGUIFontTTF class, didn't add that in the diff because I thought it was rather implied.
Thanks!
(btw, I'm new to the forums here, so hi everyone)
Code:
Index: guilib/GUIFontTTF.cpp
===================================================================
--- guilib/GUIFontTTF.cpp (revision 14611)
+++ guilib/GUIFontTTF.cpp (working copy)
@@ -19,6 +19,8 @@
*
*/
+#define USE_VERTEX_ARRAYS 1
+
#include "include.h"
#include "GUIFontTTF.h"
#include "GUIFontManager.h"
@@ -822,6 +824,7 @@
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
VerifyGLState();
+#ifndef USE_VERTEX_ARRAYS
glBegin(GL_QUADS);
#endif
}
@@ -841,8 +844,22 @@
m_pD3DDevice->SetTexture(0, NULL);
m_pD3DDevice->SetTextureStageState( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
#elif defined(HAS_SDL_OPENGL)
+#ifndef USE_VERTEX_ARRAYS
glEnd();
+#else
+
+ glEnableClientState(GL_VERTEX_ARRAY);
+ glEnableClientState(GL_COLOR_ARRAY);
+ glEnableClientState(GL_TEXTURE_COORD_ARRAY);
+ glColorPointer(4, GL_UNSIGNED_BYTE, 0, colorArray);
+ glTexCoordPointer(2, GL_FLOAT, 0, texCoords);
+ glVertexPointer(3, GL_FLOAT, 0, vertices);
+ glDrawArrays(GL_QUADS, 0, 4);
+ glDisableClientState(GL_TEXTURE_COORD_ARRAY);
+ glDisableClientState(GL_COLOR_ARRAY);
+ glDisableClientState(GL_VERTEX_ARRAY);
#endif
+#endif
}
void CGUIFontTTF::RenderCharacter(float posX, float posY, const Character *ch, D3DCOLOR dwColor)
@@ -937,6 +954,8 @@
SDL_FreeSurface(tempSurface);
#elif defined(HAS_SDL_OPENGL)
+
+
// tex coords converted to 0..1 range
float tl = texture.x1 / m_textureWidth;
float tr = texture.x2 / m_textureWidth;
@@ -945,27 +964,69 @@
GLubyte colors[4] = { (GLubyte)((dwColor >> 16) & 0xff), (GLubyte)((dwColor >> 8) & 0xff), (GLubyte)(dwColor & 0xff), (GLubyte)(dwColor >> 24) };
+#ifndef USE_VERTEX_ARRAYS
// Top-left vertex (corner)
glColor4ubv(colors);
glTexCoord2f(tl, tt);
- glVertex3f(x1, y1, z1);
+ glVertex3f(x1, y1, z1); // v0
// Bottom-left vertex (corner)
glColor4ubv(colors);
glTexCoord2f(tr, tt);
- glVertex3f(x2, y2, z2);
+ glVertex3f(x2, y2, z2); // v1
// Bottom-right vertex (corner)
glColor4ubv(colors);
glTexCoord2f(tr, tb);
- glVertex3f(x3, y3, z3);
+ glVertex3f(x3, y3, z3); // v2
// Top-right vertex (corner)
glColor4ubv(colors);
glTexCoord2f(tl, tb);
- glVertex3f(x4, y4, z4);
+ glVertex3f(x4, y4, z4); // v3
+#else
+ vertices[0] = x1; // v0
+ vertices[1] = y1;
+ vertices[2] = z1;
+ texCoords[0] = tl;
+ texCoords[1] = tt;
+ colorArray[0] = colors[0];
+ colorArray[1] = colors[1];
+ colorArray[2] = colors[2];
+ colorArray[3] = colors[3];
+ vertices[3] = x2; // v1
+ vertices[4] = y2;
+ vertices[5] = z2;
+ texCoords[2] = tr;
+ texCoords[3] = tl;
+ colorArray[4] = colors[0];
+ colorArray[5] = colors[1];
+ colorArray[6] = colors[2];
+ colorArray[7] = colors[3];
+
+ vertices[6] = x3; // v2
+ vertices[7] = y3;
+ vertices[8] = z3;
+ texCoords[4] = tr;
+ texCoords[5] = tb;
+ colorArray[8] = colors[0];
+ colorArray[9] = colors[1];
+ colorArray[10] = colors[2];
+ colorArray[11] = colors[3];
+
+ vertices[9] = x4; // v3
+ vertices[10] = y4;
+ vertices[11] = z4;
+ texCoords[6] = tl;
+ texCoords[7] = tb;
+ colorArray[12] = colors[0];
+ colorArray[13] = colors[1];
+ colorArray[14] = colors[2];
+ colorArray[15] = colors[3];
#endif
+
+#endif
}
// Oblique code - original taken from freetype2 (ftsynth.c)