This commit is contained in:
@@ -94,7 +94,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 Color3& color, const std::string& text, const Vector3& pos, float scale, u32 size, unsigned int font_index);
|
||||
void DrawString(const Color3& color, const std::string& text, const Vector3& pos, const Vector3& angle, float scale, u32 size, unsigned int font_index);
|
||||
|
||||
void DrawMatrixGizmo (const Matrix3x3&, const Vector3&);
|
||||
void DrawMatrixGizmo (const Matrix4x4&);
|
||||
|
44
main.cpp
44
main.cpp
@@ -19,6 +19,35 @@ std::vector<GLfloat> perspective(float fov, float aspect, float nearPlane, float
|
||||
return result;
|
||||
}
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
Vector3 position = {0,0,0};
|
||||
Vector3 angle = {0,0,0};
|
||||
|
||||
std::array<GLfloat, 16> lookAt(const Vector3& eye, const Vector3& center, const Vector3& up) {
|
||||
Vector3 f = Vector3::Normalized((center - eye));
|
||||
Vector3 upN = Vector3::Normalized(up);
|
||||
Vector3 s = Vector3::Normalized(f.Cross(upN));
|
||||
Vector3 u = Vector3::Normalized(s.Cross(f));
|
||||
|
||||
std::array<GLfloat, 16> result = {
|
||||
s.x, u.x, -f.x, 0.0f,
|
||||
s.y, u.y, -f.y, 0.0f,
|
||||
s.z, u.z, -f.z, 0.0f,
|
||||
-s.Dot(eye), -u.Dot(eye), f.Dot(eye), 1.0f
|
||||
};
|
||||
return result;
|
||||
}
|
||||
|
||||
void render() {
|
||||
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);
|
||||
glMultMatrixf(lookAt({position.x, position.y, position.z}, {position.x, position.y, 100.f + position.z}, {0,1,0}).data());
|
||||
}
|
||||
};
|
||||
|
||||
Camera* camera;
|
||||
using J3ML::LinearAlgebra::Matrix4x4;
|
||||
|
||||
struct point {
|
||||
@@ -35,6 +64,7 @@ class JGLDemoWindow : public ReWindow::RWindow
|
||||
{
|
||||
public:
|
||||
void initGL() {
|
||||
camera = new Camera;
|
||||
auto window_size = getSize();
|
||||
auto aspect = (float) window_size[0] / (float) window_size[1];
|
||||
|
||||
@@ -56,17 +86,19 @@ public:
|
||||
glDepthMask(GL_TRUE);
|
||||
}
|
||||
|
||||
|
||||
Vector3 textAngle = {0,0,0};
|
||||
void display() {
|
||||
textAngle.y += 1.0f;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
//camera->angle.y += 1;
|
||||
camera->render();
|
||||
///All 3D elements of the scene and JGL elements *must* be rendered before the 2d stuff.
|
||||
J3D::Begin();
|
||||
J3D::DrawLine(JGL::Colors::Red, {0,0,-1}, {1,0,-1.5});
|
||||
J3D::DrawLine(JGL::Colors::Red, {0,0.0,-1}, {0,0.5,-1});
|
||||
J3D::DrawString(JGL::Colors::Red, "JGL Sample Text", {-13, 1, -10.0f}, 0.0225, 32, FreeSans);
|
||||
J3D::DrawLine(JGL::Colors::Red, {-0.33,-0.125,1}, {-1,-0.125,1});
|
||||
J3D::DrawLine(JGL::Colors::Red, {-0.33,-0.125,1}, {-0.33,0.25,1});
|
||||
J3D::DrawString(JGL::Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f},textAngle , 1.f, 32, FreeSans);
|
||||
J3D::End();
|
||||
|
||||
J2D::Begin();
|
||||
@@ -74,6 +106,8 @@ public:
|
||||
J2D::FillTriangle(JGL::Colors::Yellow, {{140, 200},{135, 100},{105, 100}});
|
||||
J2D::DrawLine(JGL::Colors::Greens::DarkGreen, {10, 10}, {200, 300});
|
||||
J2D::DrawString(JGL::Colors::Green, "Jupteroid Font", 0.f, -48.f, 1.f, 16, Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::White, "Position: " + std::to_string(camera->position.x) + " " + std::to_string(camera->position.y) + " " + std::to_string(camera->position.z), 0, -65, 1,16, Jupiteroid);
|
||||
J2D::DrawString(JGL::Colors::White, "ViewAngle: " + std::to_string(camera->angle.x) + " " + std::to_string(camera->angle.y) + " " + std::to_string(camera->angle.z), 0, -82, 1,16, Jupiteroid);
|
||||
J2D::End();
|
||||
}
|
||||
|
||||
|
@@ -162,7 +162,11 @@ namespace JGL {
|
||||
glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]); //Set draw color back to whatever it was before.
|
||||
}
|
||||
|
||||
void J3D::DrawString(const Color3& color, const std::string& text, const Vector3& pos, float scale, u32 size, unsigned int font_index) {
|
||||
void J3D::DrawString(const Color3& color, const std::string& text, const Vector3& pos, const Vector3& angle, float scale, u32 size, unsigned int font_index)
|
||||
{
|
||||
scale = scale * 0.002f;
|
||||
scale = -scale;
|
||||
|
||||
float x = pos.x;
|
||||
float y = pos.y;
|
||||
float z = pos.z;
|
||||
@@ -183,7 +187,17 @@ namespace JGL {
|
||||
|
||||
FT_Set_Pixel_Sizes(font.face, 0, size);
|
||||
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
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;
|
||||
|
||||
for (int i = 0; i < text.length(); i++)
|
||||
{
|
||||
if (FT_Load_Char(font.face, text.c_str()[i], FT_LOAD_RENDER))
|
||||
continue;
|
||||
|
||||
@@ -203,7 +217,7 @@ namespace JGL {
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, g->bitmap.width, g->bitmap.rows, 0, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap.buffer);
|
||||
|
||||
float x2 = x + g->bitmap_left * scale;
|
||||
float y2 = y + g->bitmap_top * scale; // Adjust y-coordinate to invert the text
|
||||
float y2 = y - g->bitmap_top * scale; // Adjust y-coordinate
|
||||
float z2 = z;
|
||||
float w = g->bitmap.width * scale;
|
||||
float h = g->bitmap.rows * scale;
|
||||
@@ -214,16 +228,16 @@ namespace JGL {
|
||||
glVertex3f(x2, y2, z2);
|
||||
|
||||
glTexCoord2f(0, 1);
|
||||
glVertex3f(x2, y2 - h, z2);
|
||||
glVertex3f(x2, y2 + h, z2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x2 + w, y2 - h, z2);
|
||||
glVertex3f(x2 + w, y2 + h, z2);
|
||||
|
||||
glTexCoord2f(0, 0);
|
||||
glVertex3f(x2, y2, z2);
|
||||
|
||||
glTexCoord2f(1, 1);
|
||||
glVertex3f(x2 + w, y2 - h, z2);
|
||||
glVertex3f(x2 + w, y2 + h, z2);
|
||||
|
||||
glTexCoord2f(1, 0);
|
||||
glVertex3f(x2 + w, y2, z2);
|
||||
@@ -240,6 +254,8 @@ namespace JGL {
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_BLEND);
|
||||
glBindTexture(GL_TEXTURE_2D, 0); // Unbind texture
|
||||
glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]); // Set draw color back to whatever it was before.
|
||||
glColor4f(currentColor[0], currentColor[1], currentColor[2], currentColor[3]); //Set draw color back to whatever it was before.
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user