//#include #include #include #include #include #include #include #include using J3ML::LinearAlgebra::Vector2; #if defined(_WIN32) || defined(_WIN64) #include #endif struct Character { unsigned int TextureID; // ID handle of the glyph texture Vector2 Size; // Size of glyph Vector2 Bearing; // Offset from baseline to left/top of glyph unsigned int Advance; // Offset to advance to next glyph }; std::map Characters; GLuint VAO, VBO; const std::string vertexShader = "attribute vec4 coord;\n" "varying vec2 texpos;\n" "\n" "void main(void) {\n" " gl_Position = vec4(coord.xy, 0, 1);\n" " texpos = coord.zw;\n" "}\n" ""; const std::string fragmentShader = "varying vec2 texpos;\n" "uniform sampler2D tex;\n" "uniform vec4 color;\n" "\n" "void main(void) {\n" " gl_FragColor = vec4(1, 1, 1, texture2D(tex, texpos).a) * color;\n" "}"; using J3ML::LinearAlgebra::Matrix4x4; struct point { GLfloat x; GLfloat y; GLfloat s; GLfloat t; }; class JGLDemoWindow : public ReWindow::RWindow { public: LearnOpenGL::Shader shader; JGLDemoWindow() : ReWindow::RWindow() {} JGLDemoWindow(const std::string& title, int width, int height) : ReWindow::RWindow(title, width, height) { } void initGL() { gladLoadGL(); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, getSize().x, getSize().y, 0, -1, 1); glMatrixMode(GL_MODELVIEW); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glEnable(GL_CULL_FACE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_TEXTURE_2D); JGL::InitTextEngine(); } void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, getSize().x, getSize().y, 0, -1, 1); glMatrixMode(GL_MODELVIEW); JGL::J2D::FillRect2D(JGL::Colors::Blue, {32, 32}, {100.5, 100.5}); JGL::J2D::FillRect2D(JGL::Colors::Blue, {32, 32}, {100.5, 100.5}); JGL::Triangle2D tri { {140, 200}, {135, 100}, {105, 100} }; JGL::J2D::FillTriangle2D(JGL::Colors::Yellow, tri); JGL::J3D::DrawString3D(JGL::Colors::White, "JGL Sample Text", {1, -120, 0.5f}, 2.f); JGL::J2D::DrawString2D(JGL::Colors::Green, "William J. Tomasine II ", 0.f, -120.f, 1.f); JGL::J2D::DrawLine2D(JGL::Colors::Greens::DarkGreen, {10, 10}, {200, 300}); JGL::J3D::DrawLine3D(JGL::Colors::Red, {0,0,0}, {1,0,0}); JGL::J3D::DrawLine3D(JGL::Colors::Red, {0,0,0}, {1,0,0}); //glFlush(); } void OnRefresh(float elapsed) override { display(); this->glSwapBuffers(); } bool OnResizeRequest(const ReWindow::WindowResizeRequestEvent& e) override { return true; } }; int main(int argc, char** argv) { auto* window = new JGLDemoWindow("JGL Demo Window", 1280, 720); window->setRenderer(RenderingAPI::OPENGL); window->Open(); window->initGL(); window->setResizable(true); while (window->isAlive()) { window->pollEvents(); window->refresh(); } return 0; }