Wrath of Zeus
Made by Torchlight Games for CSE 125 SP24
Loading...
Searching...
No Matches
shader.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <fstream>
5#include <sstream>
6#include <iostream>
7
8#include <GL/glew.h>
9#include <glm/glm.hpp>
10
11
12class Shader {
13 public:
18 Shader(const std::string& vertexPath, const std::string& fragmentPath);
19 ~Shader();
20
21 /*
22 * @return the shader program's ID which can be passed into OpenGL functions
23 */
24 GLuint getID();
25
26 /*
27 * Activate the shader program. Must be called before drawing.
28 * Calls glUseProgram under the hood.
29 */
30 void use();
31
32 static void clear() { glUseProgram(0); }
33
34 /*
35 * Sets a boolean unform variable of the shader program
36 * with the specified value
37 * @param name is the name of the uniform variable as written
38 * in the shader program
39 * @param value is the boolean value to write to that variable
40 */
41 void setBool(const std::string &name, bool value) const;
42
43 /*
44 * Sets an integer unform variable of the shader program
45 * with the specified value
46 * @param name is the name of the uniform variable as written
47 * in the shader program
48 * @param value is the integer value to write to that variable
49 */
50 void setInt(const std::string &name, int value) const;
51
52 /*
53 * Sets a float unform variable of the shader program
54 * with the specified value
55 * @param name is the name of the uniform variable as written
56 * in the shader program
57 * @param value is the float value to write to that variable
58 */
59 void setFloat(const std::string &name, float value) const;
60 void setMat4(const std::string &name, glm::mat4& value);
61 void setVec3(const std::string &name, glm::vec3& value);
62
63 glm::vec3 getVec3(const std::string &name);
64 private:
65 // the shader program ID
66 unsigned int ID;
67};
Definition: shader.hpp:12
glm::vec3 getVec3(const std::string &name)
Definition: shader.cpp:120
void use()
Definition: shader.cpp:96
void setVec3(const std::string &name, glm::vec3 &value)
Definition: shader.cpp:116
void setBool(const std::string &name, bool value) const
Definition: shader.cpp:100
GLuint getID()
Definition: shader.cpp:126
void setInt(const std::string &name, int value) const
Definition: shader.cpp:104
void setMat4(const std::string &name, glm::mat4 &value)
Definition: shader.cpp:112
static void clear()
Definition: shader.hpp:32
void setFloat(const std::string &name, float value) const
Definition: shader.cpp:108
~Shader()
Definition: shader.cpp:92
unsigned int GLuint
Definition: glad.h:115
GLsizei const GLfloat * value
Definition: glad.h:1960
GLuint const GLchar * name
Definition: glad.h:1846
#define glUseProgram
Definition: glad.h:1935