0

I want to create a very basic 2D game engine to play around and learn. To accomplish this i came up with the idea to write an engine in c++ and compile it into a library together with a header file so i can just include these into my project, create an instance of the engine class and start from there. Basically i dont want to work with OpenGL code directly in the project itself.

Im using GLAD together with GLFW if that has any relevance

To draw the content to the screen i want to draw a full-screen quad and apply my pixels to it as texture but now comes the problem:

In modern OpenGL you have to use the programmable pipeline which involves shaders and im not sure on how to add the drawing to the screen into my library without having to add the shader itself to the project that uses the engine. I'd like to keep the includes etc to a minimum.

Basically the question comes down to: Can you compile shaders into a library somehow?

If not, or if anyone has a better suggestion for how to go about programming this drawing to the screen. Hints are welcome

DJSchaffner
  • 562
  • 7
  • 22
  • 1
    A simple shader is just a string of text. If all you need are simple quads you can use c-strings for the shaders. For more complex shaders these are usually game (application) specific so don't belong in the library code. The library should have the ability to load a shader from a text file, compile and manage the shader(s) / program(s). – Richard Critten Nov 02 '19 at 12:33

1 Answers1

2

There is no requirement that a shader has to be a file. You can store the shader code in a variable and thus have it compiled into the library. How you do this depends on you, you could, for example, use constexpr const char*:

constexpr const char *DefaultVertexShader = 
"#version 330 core\n"
"layout (location = 0) in vec3 aPos;\n"  
"out vec4 vertexColor;\n"
"void main() {\n"
"gl_Position = vec4(aPos, 1.0);\n"
"vertexColor = vec4(0.5, 0.0, 0.0, 1.0);\n"
"}\n";
DJSchaffner
  • 562
  • 7
  • 22
Lukas-T
  • 11,133
  • 3
  • 20
  • 30