feat: assignment 3
This commit is contained in:
		| @@ -10,11 +10,11 @@ | ||||
| #include "logger.h" | ||||
| #include "vertex.h" | ||||
|  | ||||
| Shader::Shader(const std::string& vertexPath, const std::string& fragmentPath) | ||||
| Shader::Shader(const std::string& vertex_path, const std::string& fragment_path) | ||||
| { | ||||
| 	const uint32_t vshader = compile_shader(GL_VERTEX_SHADER, vertexPath); | ||||
| 	const uint32_t vshader = compile_shader(GL_VERTEX_SHADER, vertex_path); | ||||
| 	const uint32_t fshader = | ||||
| 	    compile_shader(GL_FRAGMENT_SHADER, fragmentPath); | ||||
| 	    compile_shader(GL_FRAGMENT_SHADER, fragment_path); | ||||
|  | ||||
| 	if (vshader == 0 || fshader == 0) { | ||||
| 		program_id_ = 0; | ||||
| @@ -65,6 +65,14 @@ void Shader::setup_attribs() const | ||||
| 		    loc, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), | ||||
| 		    reinterpret_cast<const void*>(offsetof(Vertex, color))); | ||||
| 	} | ||||
|  | ||||
| 	loc = glGetAttribLocation(program_id_, "vtexcoord"); | ||||
| 	if (loc != -1) { | ||||
| 		glEnableVertexAttribArray(loc); | ||||
| 		glVertexAttribPointer( | ||||
| 		    loc, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), | ||||
| 		    reinterpret_cast<const void*>(offsetof(Vertex, tex_coord))); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| int Shader::uniform_location(const char* key) const | ||||
| @@ -141,9 +149,8 @@ uint32_t Shader::compile_shader(uint32_t type, const std::string& source_path) | ||||
| 		char buffer[1024]; | ||||
| 		glGetShaderInfoLog(shader, sizeof(buffer), nullptr, buffer); | ||||
| 		error_ = buffer; | ||||
| 		Logger::error( | ||||
| 		    sstr("Shader compilation failed (", shader_type_name, "): ", | ||||
| 			 buffer)); | ||||
| 		Logger::error(sstr("Shader compilation failed (", | ||||
| 				   shader_type_name, "): ", buffer)); | ||||
| 		glDeleteShader(shader); | ||||
| 		return 0; | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user