40 lines
1 KiB
C++
40 lines
1 KiB
C++
|
#include <fstream>
|
||
|
#include <iostream>
|
||
|
|
||
|
#include <GLES3/gl3.h>
|
||
|
#include <GL/glew.h>
|
||
|
|
||
|
#include <GL/gl.h>
|
||
|
#include <GLFW/glfw3.h>
|
||
|
#include <GL/glut.h>
|
||
|
|
||
|
unsigned int loadShader(std::string path) {
|
||
|
std::ifstream file(path);
|
||
|
|
||
|
if (file.is_open()) {
|
||
|
std::string line;
|
||
|
std::string code = "";
|
||
|
while (std::getline(file, line)) {
|
||
|
code += line + "\n";
|
||
|
}
|
||
|
file.close();
|
||
|
|
||
|
unsigned int shader = glCreateShader(GL_FRAGMENT_SHADER);
|
||
|
const char* code_cstr = code.c_str();
|
||
|
glShaderSource(shader, 1, &code_cstr, NULL);
|
||
|
glCompileShader(shader);
|
||
|
|
||
|
int success;
|
||
|
char infoLog[512];
|
||
|
glGetShaderiv(shader, GL_COMPILE_STATUS, &success);
|
||
|
if (!success) {
|
||
|
glGetShaderInfoLog(shader, 512, NULL, infoLog);
|
||
|
std::cout << "ERROR::SHADER::VERTEX::COMPILATION_FAILED\n" << infoLog << std::endl;
|
||
|
}
|
||
|
|
||
|
return shader;
|
||
|
} else {
|
||
|
std::cout << "ERROR::SHADER::VERTEX::FILE_NOT_SUCCESFULLY_READ" << std::endl;
|
||
|
return 0;
|
||
|
}
|
||
|
}
|