I dislike shaders now

This commit is contained in:
Tulpen 2023-06-26 15:22:34 +02:00
parent 0e6c5d63c3
commit 493ab7eb6e
No known key found for this signature in database
GPG key ID: 12294D73B907E784
5 changed files with 38 additions and 31 deletions

View file

@ -13,9 +13,8 @@ To compile Hibis, you will need:
- Meson-compatible compiler (recommended: Ninja or ccache + G++) - Meson-compatible compiler (recommended: Ninja or ccache + G++)
- A few minutes of your time - A few minutes of your time
<!-- --> <!-- -->
Each non-core library also has specific dependencies, including: Each module also has specific dependencies, which include:
- (RSDL) SDL2 - (RGLCore) OpenGL drivers
- (RSDL) SDL2_ttf
<!-- --> <!-- -->
Linux users should be able to get all of these (except time) from their package manager.<br> Linux users should be able to get all of these (except time) from their package manager.<br>
Windows users will need to use vcpkg or similar to easily get these dependencies. 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 #### Customising
In the folder you cloned Hibis into, run `meson build` to create a folder where the magic happens.<br> In the folder you cloned Hibis into, run `meson build` to create a folder where the magic happens.<br>
Move into the build directory using CD and you can now use `meson configure` to adjust compile options.<br> Move into the build directory using CD and you can now use `meson configure` to adjust compile options.<br>
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.

View file

@ -6,8 +6,8 @@
#include "../pragmautil.hpp" #include "../pragmautil.hpp"
namespace hibis { namespace hibis {
TODO("Make this function") TODO("Make this function fully")
class Texture : Resource { class Texture : public Resource {
public: public:
Texture(const char* path); Texture(const char* path);
~Texture(); ~Texture();

View file

@ -12,8 +12,8 @@ namespace hibis::rglcore {
} }
mLogger(Information, "Creating GLFWwindow..."); mLogger(Information, "Creating GLFWwindow...");
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
mWindow = glfwCreateWindow(size.x, size.y, title.c_str(), NULL, NULL); mWindow = glfwCreateWindow(size.x, size.y, title.c_str(), NULL, NULL);
if (!mWindow) { if (!mWindow) {
@ -75,24 +75,11 @@ namespace hibis::rglcore {
} }
void RGLCore::useShader(Shader* shader, Point2D points[3]) { 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); glUseProgram(shader->mShaderProgram);
glBindVertexArray(shader->mShaderVAO); glBindVertexArray(shader->mShaderVAO);
glDrawArrays(GL_TRIANGLES, 0, 3); glDrawArrays(GL_TRIANGLES, 0, 3);
glBindVertexArray(0);
} }
void RGLCore::stopUsingShaders() { void RGLCore::stopUsingShaders() {
@ -116,8 +103,7 @@ namespace hibis::rglcore {
unsigned int shaderIDs[2] = {0, 0}; unsigned int shaderIDs[2] = {0, 0};
mLogger(Information, fmt::format("Compiling shader {}", shader->mShaderPaths[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); shaderIDs[0] = glCreateShader(GL_VERTEX_SHADER);
const std::string vertShaderStr = loadFile(shader->mShaderPaths[1]); const std::string vertShaderStr = loadFile(shader->mShaderPaths[1]);
const char* vertShader = vertShaderStr.c_str(); const char* vertShader = vertShaderStr.c_str();
@ -164,6 +150,28 @@ namespace hibis::rglcore {
glDeleteShader(shaderIDs[0]); glDeleteShader(shaderIDs[0]);
glDeleteShader(shaderIDs[1]); 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."); mLogger(Information, "Cleaned up leftover shader objects.");
} }

View file

@ -55,7 +55,9 @@ int main() {
#endif #endif
Texture image = Texture((char*)"test.png"); 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); renderer.compileShader(&shader);
uint8_t red = 0; uint8_t red = 0;
@ -90,12 +92,10 @@ int main() {
// Clear screen then sleep for ~16ms // Clear screen then sleep for ~16ms
renderer.clearScreen(Color {red, 0, 0, 255}); renderer.clearScreen(Color {red, 0, 0, 255});
renderer.useShader(&shader, points); //renderer.useShader(&shader, points);
renderer.stopUsingShaders();
//renderer.drawText(&font, "Testing Text", IntVec2 {0, 0}, Color {255, 255, 255, 255}); //renderer.drawText(&font, "Testing Text", IntVec2 {0, 0}, Color {255, 255, 255, 255});
//renderer.drawTexture(&image, 1.0f, IntVec2 {10, 10}); //renderer.drawTexture(&image, 1.0f, IntVec2 {10, 10});
engine.drawNodes();
renderer.renderCurrent(); renderer.renderCurrent();
renderer.update(); renderer.update();
std::this_thread::sleep_for(std::chrono::milliseconds(16)); std::this_thread::sleep_for(std::chrono::milliseconds(16));

View file

@ -2,5 +2,5 @@
out vec4 FragColor; out vec4 FragColor;
void main() { void main() {
FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f); FragColor = vec4(0.8f, 0.3f, 0.02f, 1.0f);
} }