diff --git a/README.md b/README.md index c0a156b..fa9c4c3 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,8 @@ To compile Hibis, you will need: - Meson-compatible compiler (recommended: Ninja or ccache + G++) - A few minutes of your time -Each non-core library also has specific dependencies, including: -- (RSDL) SDL2 -- (RSDL) SDL2_ttf +Each module also has specific dependencies, which include: +- (RGLCore) OpenGL drivers Linux users should be able to get all of these (except time) from their package manager.
Windows users will need to use vcpkg or similar to easily get these dependencies. @@ -25,4 +24,4 @@ Run `compile.sh` in the folder you cloned Hibis into. #### Customising In the folder you cloned Hibis into, run `meson build` to create a folder where the magic happens.
Move into the build directory using CD and you can now use `meson configure` to adjust compile options.
-Once you have configured everything, run `meson compile` in the build directory and it should finish successfully. +Once you have configured everything, run `ninja` or `meson compile` in the build directory and it should finish successfully. diff --git a/core/resources/texture.hpp b/core/resources/texture.hpp index 69b2937..ef7a28f 100644 --- a/core/resources/texture.hpp +++ b/core/resources/texture.hpp @@ -6,8 +6,8 @@ #include "../pragmautil.hpp" namespace hibis { - TODO("Make this function") - class Texture : Resource { + TODO("Make this function fully") + class Texture : public Resource { public: Texture(const char* path); ~Texture(); diff --git a/renderer/rglcore/rglcore.cpp b/renderer/rglcore/rglcore.cpp index 2de8032..ee1655f 100644 --- a/renderer/rglcore/rglcore.cpp +++ b/renderer/rglcore/rglcore.cpp @@ -12,8 +12,8 @@ namespace hibis::rglcore { } mLogger(Information, "Creating GLFWwindow..."); - glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); - glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); mWindow = glfwCreateWindow(size.x, size.y, title.c_str(), NULL, NULL); if (!mWindow) { @@ -75,24 +75,11 @@ namespace hibis::rglcore { } void RGLCore::useShader(Shader* shader, Point2D points[3]) { - float vertices[] = { - points[0].x, points[0].y, 0.0f, - points[1].x, points[1].y, 0.0f, - points[2].x, points[2].y, 0.0f - }; - if (shader->mShaderVAO == 0) { - glGenVertexArrays(1, &shader->mShaderVAO); - glBindVertexArray(shader->mShaderVAO); - glBindBuffer(GL_ARRAY_BUFFER, shader->mShaderVBO); - glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); - - glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); - glEnableVertexAttribArray(0); - } - glUseProgram(shader->mShaderProgram); glBindVertexArray(shader->mShaderVAO); glDrawArrays(GL_TRIANGLES, 0, 3); + + glBindVertexArray(0); } void RGLCore::stopUsingShaders() { @@ -116,8 +103,7 @@ namespace hibis::rglcore { unsigned int shaderIDs[2] = {0, 0}; mLogger(Information, fmt::format("Compiling shader {}", shader->mShaderPaths[0])); - glGenBuffers(1, &shader->mShaderVBO); - glBindBuffer(GL_ARRAY_BUFFER, shader->mShaderVBO); + shaderIDs[0] = glCreateShader(GL_VERTEX_SHADER); const std::string vertShaderStr = loadFile(shader->mShaderPaths[1]); const char* vertShader = vertShaderStr.c_str(); @@ -164,6 +150,28 @@ namespace hibis::rglcore { glDeleteShader(shaderIDs[0]); glDeleteShader(shaderIDs[1]); + GLfloat vertices[] = { + -0.5f, -0.5f * float(sqrt(3)) / 3, 0.0f, // Lower left corner + 0.5f, -0.5f * float(sqrt(3)) / 3, 0.0f, // Lower right corner + 0.0f, 0.5f * float(sqrt(3)) * 2 / 3, 0.0f // Upper corner + }; + + glGenVertexArrays(1, &shader->mShaderVAO); + glGenBuffers(1, &shader->mShaderVBO); + + glBindVertexArray(shader->mShaderVAO); + + glBindBuffer(GL_ARRAY_BUFFER, shader->mShaderVBO); + + glBindBuffer(GL_ARRAY_BUFFER, shader->mShaderVBO); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + + glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0); + glEnableVertexAttribArray(0); + + glBindBuffer(GL_ARRAY_BUFFER, 0); + glBindVertexArray(0); + mLogger(Information, "Cleaned up leftover shader objects."); } diff --git a/test/app.cpp b/test/app.cpp index 7e9dded..123d1ed 100644 --- a/test/app.cpp +++ b/test/app.cpp @@ -55,7 +55,9 @@ int main() { #endif Texture image = Texture((char*)"test.png"); - Shader shader = Shader("../test/test.vert", "../test/test.frag"); + + system("cp ../test/test.vert ./ && cp ../test/test.frag ./"); + Shader shader = Shader("test.vert", "test.frag"); renderer.compileShader(&shader); uint8_t red = 0; @@ -90,12 +92,10 @@ int main() { // Clear screen then sleep for ~16ms renderer.clearScreen(Color {red, 0, 0, 255}); - renderer.useShader(&shader, points); - renderer.stopUsingShaders(); + //renderer.useShader(&shader, points); //renderer.drawText(&font, "Testing Text", IntVec2 {0, 0}, Color {255, 255, 255, 255}); //renderer.drawTexture(&image, 1.0f, IntVec2 {10, 10}); - engine.drawNodes(); renderer.renderCurrent(); renderer.update(); std::this_thread::sleep_for(std::chrono::milliseconds(16)); diff --git a/test/test.frag b/test/test.frag index 9a1b7f9..98c4626 100644 --- a/test/test.frag +++ b/test/test.frag @@ -2,5 +2,5 @@ out vec4 FragColor; void main() { - FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f); -} + FragColor = vec4(0.8f, 0.3f, 0.02f, 1.0f); +}