Replaced GL_QUAD calls.

This commit is contained in:
Leonardo Zide 2017-02-11 08:30:57 -08:00
parent 9a2f4c6678
commit cfdfe30b40
3 changed files with 40 additions and 16 deletions

View file

@ -186,7 +186,7 @@ void TexFont::PrintText(lcContext* Context, float Left, float Top, float Z, cons
if (!Length) if (!Length)
return; return;
float* Verts = new float[4 * 5 * Length]; float* Verts = new float[6 * 5 * Length];
float* CurVert = Verts; float* CurVert = Verts;
while (*Text) while (*Text)
@ -211,12 +211,24 @@ void TexFont::PrintText(lcContext* Context, float Left, float Top, float Z, cons
*CurVert++ = mGlyphs[ch].right; *CurVert++ = mGlyphs[ch].right;
*CurVert++ = mGlyphs[ch].bottom; *CurVert++ = mGlyphs[ch].bottom;
*CurVert++ = Left + mGlyphs[ch].width;
*CurVert++ = Top - mFontHeight;
*CurVert++ = Z;
*CurVert++ = mGlyphs[ch].right;
*CurVert++ = mGlyphs[ch].bottom;
*CurVert++ = Left + mGlyphs[ch].width; *CurVert++ = Left + mGlyphs[ch].width;
*CurVert++ = Top; *CurVert++ = Top;
*CurVert++ = Z; *CurVert++ = Z;
*CurVert++ = mGlyphs[ch].right; *CurVert++ = mGlyphs[ch].right;
*CurVert++ = mGlyphs[ch].top; *CurVert++ = mGlyphs[ch].top;
*CurVert++ = Left;
*CurVert++ = Top;
*CurVert++ = Z;
*CurVert++ = mGlyphs[ch].left;
*CurVert++ = mGlyphs[ch].top;
Left += mGlyphs[ch].width; Left += mGlyphs[ch].width;
Text++; Text++;
} }
@ -224,14 +236,14 @@ void TexFont::PrintText(lcContext* Context, float Left, float Top, float Z, cons
Context->SetVertexBufferPointer(Verts); Context->SetVertexBufferPointer(Verts);
Context->SetVertexFormat(0, 3, 2, 0); Context->SetVertexFormat(0, 3, 2, 0);
Context->DrawPrimitives(GL_QUADS, 0, 4 * (GLsizei)Length); Context->DrawPrimitives(GL_TRIANGLES, 0, 6 * (GLsizei)Length);
Context->ClearVertexBuffer(); // context remove Context->ClearVertexBuffer(); // context remove
delete[] Verts; delete[] Verts;
} }
void TexFont::GetGlyphQuad(float Left, float Top, float Z, int Glyph, float* Buffer) const void TexFont::GetGlyphTriangles(float Left, float Top, float Z, int Glyph, float* Buffer) const
{ {
Left -= mGlyphs[Glyph].width / 2.0f; Left -= mGlyphs[Glyph].width / 2.0f;
Top += mFontHeight / 2.0f; Top += mFontHeight / 2.0f;
@ -254,9 +266,21 @@ void TexFont::GetGlyphQuad(float Left, float Top, float Z, int Glyph, float* Buf
*Buffer++ = mGlyphs[Glyph].right; *Buffer++ = mGlyphs[Glyph].right;
*Buffer++ = mGlyphs[Glyph].bottom; *Buffer++ = mGlyphs[Glyph].bottom;
*Buffer++ = Left + mGlyphs[Glyph].width;
*Buffer++ = Top - mFontHeight;
*Buffer++ = Z;
*Buffer++ = mGlyphs[Glyph].right;
*Buffer++ = mGlyphs[Glyph].bottom;
*Buffer++ = Left + mGlyphs[Glyph].width; *Buffer++ = Left + mGlyphs[Glyph].width;
*Buffer++ = Top; *Buffer++ = Top;
*Buffer++ = Z; *Buffer++ = Z;
*Buffer++ = mGlyphs[Glyph].right; *Buffer++ = mGlyphs[Glyph].right;
*Buffer++ = mGlyphs[Glyph].top; *Buffer++ = mGlyphs[Glyph].top;
*Buffer++ = Left;
*Buffer++ = Top;
*Buffer++ = Z;
*Buffer++ = mGlyphs[Glyph].left;
*Buffer++ = mGlyphs[Glyph].top;
} }

View file

@ -21,7 +21,7 @@ public:
void Release(); void Release();
void PrintText(lcContext* Context, float Left, float Top, float Z, const char* Text) const; void PrintText(lcContext* Context, float Left, float Top, float Z, const char* Text) const;
void GetGlyphQuad(float Left, float Top, float Z, int Glyph, float* Buffer) const; void GetGlyphTriangles(float Left, float Top, float Z, int Glyph, float* Buffer) const;
void GetStringDimensions(int* cx, int* cy, const char* Text) const; void GetStringDimensions(int* cx, int* cy, const char* Text) const;
protected: protected:

View file

@ -1383,17 +1383,17 @@ void View::DrawGrid()
*CurVert++ = 0.0f; *CurVert++ = 0.0f;
*CurVert++ = 0.0f; *CurVert++ = 0.0f;
*CurVert++ = Right;
*CurVert++ = Bottom;
*CurVert++ = Z;
*CurVert++ = U;
*CurVert++ = 0.0f;
*CurVert++ = Right; *CurVert++ = Right;
*CurVert++ = Top; *CurVert++ = Top;
*CurVert++ = Z; *CurVert++ = Z;
*CurVert++ = U; *CurVert++ = U;
*CurVert++ = V; *CurVert++ = V;
*CurVert++ = Right;
*CurVert++ = Bottom;
*CurVert++ = Z;
*CurVert++ = U;
*CurVert++ = 0.0f;
} }
if (Preferences.mDrawGridLines) if (Preferences.mDrawGridLines)
@ -1449,7 +1449,7 @@ void View::DrawGrid()
mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor)); mContext->SetColor(lcVector4FromColor(Preferences.mGridStudColor));
mContext->SetVertexFormat(0, 3, 2, 0); mContext->SetVertexFormat(0, 3, 2, 0);
mContext->DrawPrimitives(GL_QUADS, 0, 4); mContext->DrawPrimitives(GL_TRIANGLE_STRIP, 0, 4);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND); glDisable(GL_BLEND);
@ -1526,19 +1526,19 @@ void View::DrawAxes()
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND); glEnable(GL_BLEND);
float TextBuffer[4 * 5 * 3]; float TextBuffer[6 * 5 * 3];
lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix); lcVector3 PosX = lcMul30(lcVector3(25.0f, 0.0f, 0.0f), WorldViewMatrix);
gTexFont.GetGlyphQuad(PosX.x, PosX.y, PosX.z, 'X', TextBuffer); gTexFont.GetGlyphTriangles(PosX.x, PosX.y, PosX.z, 'X', TextBuffer);
lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix); lcVector3 PosY = lcMul30(lcVector3(0.0f, 25.0f, 0.0f), WorldViewMatrix);
gTexFont.GetGlyphQuad(PosY.x, PosY.y, PosY.z, 'Y', TextBuffer + 5 * 4); gTexFont.GetGlyphTriangles(PosY.x, PosY.y, PosY.z, 'Y', TextBuffer + 5 * 6);
lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix); lcVector3 PosZ = lcMul30(lcVector3(0.0f, 0.0f, 25.0f), WorldViewMatrix);
gTexFont.GetGlyphQuad(PosZ.x, PosZ.y, PosZ.z, 'Z', TextBuffer + 5 * 4 * 2); gTexFont.GetGlyphTriangles(PosZ.x, PosZ.y, PosZ.z, 'Z', TextBuffer + 5 * 6 * 2);
mContext->SetVertexBufferPointer(TextBuffer); mContext->SetVertexBufferPointer(TextBuffer);
mContext->SetVertexFormat(0, 3, 2, 0); mContext->SetVertexFormat(0, 3, 2, 0);
mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f); mContext->SetColor(0.0f, 0.0f, 0.0f, 1.0f);
mContext->DrawPrimitives(GL_QUADS, 0, 4 * 3); mContext->DrawPrimitives(GL_TRIANGLES, 0, 6 * 3);
glDisable(GL_BLEND); glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D); glDisable(GL_TEXTURE_2D);