wip: practica1
This commit is contained in:
		| @@ -1 +1,43 @@ | ||||
| #include "shader.h" | ||||
| #include "shader.h" | ||||
|  | ||||
| #include <vector> | ||||
| #include <fstream> | ||||
| #include <sstream> | ||||
|  | ||||
| #include "../lib/glew/GL/glew.h" | ||||
| #include "../lib/glfw/glfw3.h" | ||||
|  | ||||
| namespace { | ||||
| 	std::string readShaderFile(const std::string& filename) { | ||||
| 		std::ifstream file(filename); | ||||
| 		if (!file) | ||||
| 			throw std::runtime_error("Failed to open shader file: " + filename); | ||||
| 		std::stringstream buffer; | ||||
| 		buffer << file.rdbuf(); | ||||
| 		return buffer.str(); | ||||
| 	} | ||||
| } // namespace | ||||
|  | ||||
| Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) | ||||
| { | ||||
| 	std::string vertexCode = readShaderFile(vertexPath); | ||||
| 	std::string fragmentCode = readShaderFile(fragmentPath); | ||||
| 	const char* vShaderCode = vertexCode.c_str(); | ||||
| 	const char* fShaderCode = fragmentCode.c_str(); | ||||
|  | ||||
| 	const uint32_t vertex = glCreateShader(GL_VERTEX_SHADER); | ||||
| 	glShaderSource(vertex, 1, &vShaderCode, NULL); | ||||
| 	glCompileShader(vertex); | ||||
|  | ||||
| 	const uint32_t fragment = glCreateShader(GL_FRAGMENT_SHADER); | ||||
| 	glShaderSource(fragment, 1, &fShaderCode, NULL); | ||||
| 	glCompileShader(fragment); | ||||
|  | ||||
| 	program = glCreateProgram(); | ||||
| 	glAttachShader(program, vertex); | ||||
| 	glAttachShader(program, fragment); | ||||
| 	glLinkProgram(program); | ||||
|  | ||||
| 	glDeleteShader(vertex); | ||||
| 	glDeleteShader(fragment); | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 izenynn
					izenynn