diff --git a/.gitignore b/.gitignore index 05f4819..5f431dd 100644 --- a/.gitignore +++ b/.gitignore @@ -4,10 +4,14 @@ /.vscode/ /.vs/ /docs/ +/.cache/ **.log +**.ninja **.sln **.vcxproj* **.make **Makefile **dependencies.lua **linker.lua +/compile_commands/ +**compile_commands.json diff --git a/app/assets/textures/warhammer.jpg b/app/assets/textures/warhammer.jpg new file mode 100644 index 0000000..e02ac58 Binary files /dev/null and b/app/assets/textures/warhammer.jpg differ diff --git a/app/src/app.cpp b/app/src/app.cpp index e1875d0..c5d619e 100644 --- a/app/src/app.cpp +++ b/app/src/app.cpp @@ -1,114 +1,101 @@ -#include -#include -#include +#include "bakara/renderer/renderer.h" +#include "bakatools/logging/log.h" +#include "glm/ext/matrix_transform.hpp" +#include -long long int random(long long int max, long long int min = 0) -{ - long long int n = rand(); - while (n > max || n < min) n = rand(); - return n; -} +using namespace Bk; -std::vector prime_range(long long int max, long long int min = 2) +class TestLayer : public Layer { - //Sieve of Eratosthenes algo from https://www.baeldung.com/cs/prime-number-algorithms - std::vector primes; - std::vector primes_check(max); - std::fill(primes_check.begin(), primes_check.end(), true); - - for (long long int i = 2; i < sqrt(max); i++) - if (primes_check[i]) + public: + TestLayer() : Layer("Test") { - long long int j = i * i; - while (j <= max) - { - primes_check[j] = false; - j += i; - } - } + blueShader = Ref(Shader::Create(R"( + #version 420 core + layout (location = 0) in vec3 aPos; - for (long long int i = min; i < primes_check.size(); i++) - if (primes_check[i]) primes.push_back(i); + uniform mat4 viewProjection; + uniform mat4 transform; - return primes; -} + void main() { + gl_Position = viewProjection * transform * vec4(aPos, 1.0); + } + )", R"( + #version 420 core -long long int gcd(long long int a, long long int b) -{ - long long int temp; - while (b != 0) - { - temp = a % b; - a = b; - b = temp; - } - return a; -} - -long long int power(long long int val, long long int power) -{ - long long int res = val; - for(long long int i = 1; i < power; i++) res *= val; - return res; -} - - -void rsa() -{ - auto primes = prime_range(100, 50); - //long long int p = primes[random(primes.size())]; - //long long int q = primes[random(primes.size())]; - long long int p = 13; - long long int q = 17; - long long int n = p * q; - long long int phi = (p - 1) * (q - 1); - - long long int e = 2; - long long int k = 0; - while(e < phi) - { - if (gcd(e, phi) == 1) k += 1; - if (k >= 20) break; - e += 1; - } - - long long int d = 0; - long long int j = 0; - while (j < 2) - { - d += 1; - if (1 == (e * d) % phi) + out vec4 FragColor; + + void main() { + FragColor = vec4(0.0, 0.0, 0.5, 1.0); + } + )")); + + float squareVertices[7 * 3] = { + -0.5f, -0.5f, 0.0f, + 0.5f, -0.5f, 0.0f, + 0.5f, 0.5f, 0.0f, + -0.5f, 0.5f, 0.0f, + }; + + squareVA = Ref(VertexArray::Create()); + + Ref squareVB = Ref(VertexBuffer::Create(squareVertices, sizeof(squareVertices))); + squareVB->SetLayout({ + { ShaderType::Float3, "aPos" } + }); + squareVA->AddVertexBuffer(squareVB); + + u32 squareIndices[6] = { 0, 1, 2, 0, 2, 3 }; + squareVA->SetIndexbuffer(Ref(IndexBuffer::Create(squareIndices, sizeof(squareIndices) / sizeof(u32)))); + } + + void OnUpdate(DeltaTime dt) override { - j += 1; + if(Keyboard::KeyDown(KeyCode::W)) + cameraPos.y += cameraSpeed * dt; + if(Keyboard::KeyDown(KeyCode::S)) + cameraPos.y -= cameraSpeed * dt; + if(Keyboard::KeyDown(KeyCode::D)) + cameraPos.x += cameraSpeed * dt; + if(Keyboard::KeyDown(KeyCode::A)) + cameraPos.x -= cameraSpeed * dt; + if(Keyboard::KeyDown(KeyCode::Q)) + rotation -= rotationSpeed * dt; + if(Keyboard::KeyDown(KeyCode::E)) + rotation += rotationSpeed * dt; + + camera.SetPosition(cameraPos); + camera.SetRotation(rotation); + + Renderer::BeginScene(camera); + RenderCommand::Clear(0.1, 0.1, 0.1, 1.0); + for(int x = 0; x < 20; x += 2) + for(int y = 0; y < 20; y += 2) + Renderer::Submit(squareVA, blueShader, Math::translate(Mat4(1.0f), Vec3(x, y, 0))); } - } - BK_INFO("p:{4} q:{5} n:{0} phi:{1} e:{2} d:{3}", n, phi, e, d, p, q); - long long int msg = 20; - long long int C = power(msg, e) % n; - BK_INFO("{0} {1}", C, power(msg, e)); - long long int M = C ^ d % n; - BK_INFO(M); -} + private: + OrthographicCamera camera = { -10.0f, 10.0f, -10.0f, 10.0f }; + Ref blueShader; + Ref squareVA; + Vec3 cameraPos = {0, 0, 0}; + float cameraSpeed = 5.0f; + float rotation = 0.0f; + float rotationSpeed = 30.0f; +}; -void diffi() -{ - long long int a, b, g, p, ga, gb, gab, gba; - a = 10030; - b = 10294; - g = 10927; - p = prime_range(1000, 900)[3]; - ga = g^a % p; - gb = g^b % p; - gab = ga^b % p; - gba = gb^a % p; - BK_INFO("a{0} b{1} g{2} p{3} ga{4} gb{5} gab{6} gba{7}", a, b, g, p, ga, gb, gab, gba); - -} - -int main() +class Sandbox : public Application { - Bk::Log::init("Bakacypher"); - diffi(); - return 0; + public: + Sandbox() + { + h_window->SetVsync(true); + PushLayer(new TestLayer()); + } +}; + + + +Application* Bk::CreateApp(int argc, char** argv) { + return new Sandbox(); } \ No newline at end of file diff --git a/package.json b/package.json index 5ca00de..e9d1532 100644 --- a/package.json +++ b/package.json @@ -1,11 +1,11 @@ { - "name": "Bakacrypt", + "name": "graphics", "author": "anulax1225", "git": "", "packages": [ { "author": "anulax1225", - "name": "bakatools" + "name": "bakara" } ] } \ No newline at end of file diff --git a/premake5.lua b/premake5.lua index ee7cda0..ba93df2 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,4 +1,4 @@ -workspace "Bakacrypt" +workspace "graphics" architecture "x64" configurations { "Debug", "Release" } startproject "App" @@ -9,6 +9,7 @@ workspace "Bakacrypt" } linkgroups "On" + toolset "clang" outputdir = "%{cfg.system}-%{cfg.architecture}-%{cfg.buildcfg}" include "dependencies.lua"