Changes to shaders
This commit is contained in:
parent
205919e1a9
commit
0e6c5d63c3
|
@ -9,8 +9,6 @@ namespace hibis {
|
|||
public:
|
||||
Shader(std::string vertexShaderPath, std::string fragShaderPath);
|
||||
~Shader();
|
||||
// Vertex then Frag shader
|
||||
unsigned int mShaderIDs[2] = {0, 0};
|
||||
unsigned int mShaderProgram = 0;
|
||||
unsigned int mShaderVAO = 0;
|
||||
unsigned int mShaderVBO = 0;
|
||||
|
|
|
@ -47,7 +47,7 @@ namespace hibis::rglcore {
|
|||
void RGLCore::clearScreen(Color col) {
|
||||
float r = (float)(col.r) / 255, g = (float)(col.g) / 255, b = (float)(col.b) / 255, a = (float)(col.a) / 255;
|
||||
glClearColor(r, g, b, a);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
}
|
||||
|
||||
void RGLCore::renderCurrent() {
|
||||
|
@ -110,32 +110,59 @@ namespace hibis::rglcore {
|
|||
|
||||
void RGLCore::compileShader(Shader* shader) {
|
||||
if (shader->mShaderProgram != 0) return;
|
||||
char infoLog[512];
|
||||
|
||||
int success;
|
||||
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);
|
||||
shader->mShaderIDs[0] = glCreateShader(GL_VERTEX_SHADER);
|
||||
const char* vertShader = loadFile(shader->mShaderPaths[0]);
|
||||
glShaderSource(shader->mShaderIDs[0], 1, &vertShader, NULL);
|
||||
glCompileShader(shader->mShaderIDs[0]);
|
||||
shaderIDs[0] = glCreateShader(GL_VERTEX_SHADER);
|
||||
const std::string vertShaderStr = loadFile(shader->mShaderPaths[1]);
|
||||
const char* vertShader = vertShaderStr.c_str();
|
||||
glShaderSource(shaderIDs[0], 1, &vertShader, NULL);
|
||||
glCompileShader(shaderIDs[0]);
|
||||
|
||||
glGetShaderiv(shaderIDs[0], GL_COMPILE_STATUS, &success);
|
||||
if(!success) {
|
||||
glGetShaderInfoLog(shaderIDs[0], 512, NULL, infoLog);
|
||||
printf("%s", infoLog);
|
||||
mLogger(Error, fmt::format("Couldn't compile shader '{}'! what: {}", shader->mShaderPaths[0], std::string(infoLog)));
|
||||
}
|
||||
|
||||
mLogger(Information, fmt::format("Compiling shader {}", shader->mShaderPaths[1]));
|
||||
|
||||
shader->mShaderIDs[1] = glCreateShader(GL_VERTEX_SHADER);
|
||||
const char* fragShader = loadFile(shader->mShaderPaths[1]);
|
||||
glShaderSource(shader->mShaderIDs[1], 1, &fragShader, NULL);
|
||||
glCompileShader(shader->mShaderIDs[1]);
|
||||
shaderIDs[1] = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
const std::string fragShaderStr = loadFile(shader->mShaderPaths[1]);
|
||||
const char* fragShader = fragShaderStr.c_str();
|
||||
glShaderSource(shaderIDs[1], 1, &fragShader, NULL);
|
||||
glCompileShader(shaderIDs[1]);
|
||||
|
||||
glGetShaderiv(shaderIDs[1], GL_COMPILE_STATUS, &success);
|
||||
if(!success) {
|
||||
glGetShaderInfoLog(shaderIDs[1], 512, NULL, infoLog);
|
||||
mLogger(Error, fmt::format("Couldn't compile shader '{}'! what: {}", shader->mShaderPaths[1], std::string(infoLog)));
|
||||
}
|
||||
|
||||
shader->mShaderProgram = glCreateProgram();
|
||||
|
||||
glAttachShader(shader->mShaderProgram, shader->mShaderIDs[0]);
|
||||
glAttachShader(shader->mShaderProgram, shader->mShaderIDs[1]);
|
||||
glAttachShader(shader->mShaderProgram, shaderIDs[0]);
|
||||
glAttachShader(shader->mShaderProgram, shaderIDs[1]);
|
||||
|
||||
glLinkProgram(shader->mShaderProgram);
|
||||
|
||||
mLogger(Information, "Linked shader.");
|
||||
glGetProgramiv(shader->mShaderProgram, GL_LINK_STATUS, &success);
|
||||
|
||||
glDeleteShader(shader->mShaderIDs[0]);
|
||||
glDeleteShader(shader->mShaderIDs[1]);
|
||||
if (!success) {
|
||||
TODO("what the fuck, this isn't helpful")
|
||||
glGetShaderInfoLog(shader->mShaderProgram, 512, NULL, infoLog);
|
||||
mLogger(Error, fmt::format("Couldn't link shader! what: {}", std::string(infoLog)));
|
||||
}
|
||||
else mLogger(Information, "Linked shader.");
|
||||
|
||||
glDeleteShader(shaderIDs[0]);
|
||||
glDeleteShader(shaderIDs[1]);
|
||||
|
||||
mLogger(Information, "Cleaned up leftover shader objects.");
|
||||
}
|
||||
|
@ -150,7 +177,7 @@ namespace hibis::rglcore {
|
|||
glfwSetWindowTitle(mWindow, title.c_str());
|
||||
}
|
||||
|
||||
const char* RGLCore::loadFile(std::string path) {
|
||||
std::string RGLCore::loadFile(std::string path) {
|
||||
std::string text, line;
|
||||
std::ifstream textFile(path);
|
||||
if (textFile.is_open()) {
|
||||
|
@ -163,8 +190,6 @@ namespace hibis::rglcore {
|
|||
mLogger(Error, fmt::format("Couldn't load file '{}'", path));
|
||||
}
|
||||
|
||||
const char* textChar = text.c_str();
|
||||
|
||||
return textChar;
|
||||
return text;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,6 @@ namespace hibis::rglcore {
|
|||
GLFWwindow* mWindow;
|
||||
std::unordered_map<Texture*, unsigned int> mTextures;
|
||||
|
||||
const char* loadFile(std::string path);
|
||||
std::string loadFile(std::string path);
|
||||
};
|
||||
}
|
||||
|
|
|
@ -91,6 +91,7 @@ int main() {
|
|||
// Clear screen then sleep for ~16ms
|
||||
renderer.clearScreen(Color {red, 0, 0, 255});
|
||||
renderer.useShader(&shader, points);
|
||||
renderer.stopUsingShaders();
|
||||
//renderer.drawText(&font, "Testing Text", IntVec2 {0, 0}, Color {255, 255, 255, 255});
|
||||
//renderer.drawTexture(&image, 1.0f, IntVec2 {10, 10});
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@
|
|||
out vec4 FragColor;
|
||||
|
||||
void main() {
|
||||
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f);
|
||||
FragColor = vec4(1.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue