J3D draw string draw_back_face
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 7m30s
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 7m30s
This commit is contained in:
@@ -209,7 +209,7 @@ namespace JGL {
|
||||
void WireframeCapsule(const Color3& color, const Capsule& cap, float thickness = 1);
|
||||
void FillTriangleMesh(const Color3& color, const TriangleMesh& mesh);
|
||||
void WireframeTriangleMesh(const Color3& color, const TriangleMesh& mesh, float thickness = 1);
|
||||
void DrawString(const Color4& color, const std::string& text, const Vector3& pos, const Vector3& angle, float scale, u32 size, const Font& font);
|
||||
void DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngle& angle = {0, 0, 0}, bool draw_back_face = false);
|
||||
void DrawSprite();
|
||||
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
|
||||
void DrawMatrixGizmo (const Matrix4x4&);
|
||||
|
2
main.cpp
2
main.cpp
@@ -174,7 +174,7 @@ public:
|
||||
J3D::Begin();
|
||||
J3D::DrawLine(Colors::Red, {-0.33,-0.125,1}, {-1,-0.125,1});
|
||||
J3D::DrawLine(Colors::Red, {-0.33,-0.125,1}, {-0.33,0.25,1});
|
||||
J3D::DrawString(Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f},textAngle, 1.f, 32, FreeSans);
|
||||
J3D::DrawString(Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f}, 1.f, 32, FreeSans, textAngle);
|
||||
J3D::End();
|
||||
|
||||
J2D::Begin();
|
||||
|
28
src/JGL.cpp
28
src/JGL.cpp
@@ -42,7 +42,7 @@ namespace JGL {
|
||||
|
||||
//Get what the draw color was before we did anything.
|
||||
glGetFloatv(GL_CURRENT_COLOR, oldColor);
|
||||
glColor4f(baseColor[0], baseColor[1], baseColor[2], baseColor[3]);
|
||||
glColor4fv(baseColor);
|
||||
|
||||
glGetIntegerv(GL_ACTIVE_TEXTURE,& activeTextureUnit);
|
||||
activeTextureUnit = activeTextureUnit - GL_TEXTURE0;
|
||||
@@ -50,42 +50,49 @@ namespace JGL {
|
||||
if (activeTextureUnit != 0)
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
|
||||
wasDepthTestEnabled = false;
|
||||
if (glIsEnabled(GL_DEPTH_TEST))
|
||||
wasDepthTestEnabled = true,
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
else
|
||||
wasDepthTestEnabled = false;
|
||||
|
||||
wasVertexArraysEnabled = true;
|
||||
if (!glIsEnabled(GL_VERTEX_ARRAY))
|
||||
wasVertexArraysEnabled = false,
|
||||
glEnableClientState(GL_VERTEX_ARRAY);
|
||||
else
|
||||
wasVertexArraysEnabled = true;
|
||||
|
||||
wasCullFaceEnabled = true;
|
||||
if (!glIsEnabled(GL_CULL_FACE))
|
||||
wasCullFaceEnabled = false,
|
||||
glEnable(GL_CULL_FACE),
|
||||
glCullFace(GL_BACK);
|
||||
else
|
||||
wasCullFaceEnabled = true;
|
||||
|
||||
wasBlendEnabled = true;
|
||||
if (!glIsEnabled(GL_BLEND))
|
||||
wasBlendEnabled = false,
|
||||
glEnable(GL_BLEND),
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
else
|
||||
wasBlendEnabled = true;
|
||||
|
||||
wasTexture2DEnabled = true;
|
||||
if (!glIsEnabled(GL_TEXTURE_2D))
|
||||
wasTexture2DEnabled = false,
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
else
|
||||
wasTexture2DEnabled = true;
|
||||
|
||||
wasTextureCoordArrayEnabled = true;
|
||||
if (!glIsEnabled(GL_TEXTURE_COORD_ARRAY))
|
||||
wasTextureCoordArrayEnabled = false,
|
||||
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
else
|
||||
wasTextureCoordArrayEnabled = true;
|
||||
|
||||
wasColorArrayEnabled = false;
|
||||
if (glIsEnabled(GL_COLOR_ARRAY))
|
||||
wasColorArrayEnabled = true,
|
||||
glDisableClientState(GL_COLOR_ARRAY);
|
||||
else
|
||||
wasColorArrayEnabled = false;
|
||||
|
||||
if (!inJ3D)
|
||||
inJ2D = true;
|
||||
@@ -123,7 +130,7 @@ namespace JGL {
|
||||
glActiveTexture(GL_TEXTURE0 + activeTextureUnit);
|
||||
|
||||
//Put the draw color back how it was before.
|
||||
glColor4f(oldColor[0], oldColor[1], oldColor[2], oldColor[3]);
|
||||
glColor4fv(oldColor);
|
||||
|
||||
inJ2D = false;
|
||||
}
|
||||
@@ -538,7 +545,7 @@ namespace JGL {
|
||||
|
||||
//Get what the draw color was before we did anything.
|
||||
glGetFloatv(GL_CURRENT_COLOR, oldColor);
|
||||
glColor4f(baseColor[0], baseColor[1], baseColor[2], baseColor[3]);
|
||||
glColor4fv(baseColor);
|
||||
|
||||
wasDepthTestEnabled = false;
|
||||
if (glIsEnabled(GL_DEPTH_TEST))
|
||||
@@ -555,7 +562,6 @@ namespace JGL {
|
||||
wasTexture2DEnabled = false,
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
|
||||
// TODO: implement bool drawBackface as DrawString parameter.
|
||||
wasCullFaceEnabled = false;
|
||||
if (glIsEnabled(GL_CULL_FACE))
|
||||
wasCullFaceEnabled = true,
|
||||
|
@@ -144,12 +144,12 @@ namespace JGL {
|
||||
|
||||
glVertexPointer(2, GL_FLOAT, sizeof(GLfloat) * 2, vertices.data());
|
||||
glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat) * 2, texcoords.data());
|
||||
glDrawArrays(GL_TRIANGLES, 0, vertices.size() * 6);
|
||||
glDrawArrays(GL_TRIANGLES, 0, (int) vertices.size() * 6);
|
||||
glBindTexture(GL_TEXTURE_2D, 0);
|
||||
glColor4f(1, 1, 1, 1);
|
||||
}
|
||||
|
||||
void J3D::DrawString(const Color4& color, const std::string& text, const Vector3& pos, const Vector3& angle, float scale, u32 size, const Font& font) {
|
||||
void J3D::DrawString(const Color4& color, const std::string& text, const Vector3& pos, float scale, u32 size, const Font& font, const EulerAngle& angle, bool draw_back_face) {
|
||||
//TODO figure out what the scale should actually be mathematically.
|
||||
scale = scale * 0.002f;
|
||||
scale = -scale;
|
||||
@@ -168,12 +168,11 @@ namespace JGL {
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, z);
|
||||
glRotatef(angle.x, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(angle.y, 0.0f, 1.0f, 0.0f);
|
||||
glRotatef(angle.z, 0.0f, 0.0f, 1.0f);
|
||||
x = 0;
|
||||
y = 0;
|
||||
z = 0;
|
||||
glRotatef(angle.pitch, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(angle.yaw, 0.0f, 1.0f, 0.0f);
|
||||
glRotatef(angle.roll, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
x = y = z = 0;
|
||||
|
||||
for (int i = 0; i < text.length(); i++)
|
||||
{
|
||||
@@ -197,6 +196,10 @@ namespace JGL {
|
||||
float w = g->bitmap.width * scale;
|
||||
float h = g->bitmap.rows * scale;
|
||||
|
||||
if (!draw_back_face)
|
||||
glEnable(GL_CULL_FACE),
|
||||
glCullFace(GL_BACK);
|
||||
|
||||
glBegin(GL_TRIANGLES);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
@@ -219,6 +222,9 @@ namespace JGL {
|
||||
|
||||
glEnd();
|
||||
|
||||
if (!draw_back_face)
|
||||
glDisable(GL_CULL_FACE);
|
||||
|
||||
x += (g->advance.x >> 6) * scale;
|
||||
y += (g->advance.y >> 6) * scale;
|
||||
}
|
||||
|
Reference in New Issue
Block a user