PROTO::KLUDGE  0.1
Quick prototyping library for games using SDL and OpenGL.
Shader.hpp
Go to the documentation of this file.
1 #ifndef SHADER_HPP
2 #define SHADER_HPP
3 
4 #include <stdio.h>
5 #include <string.h>
6 #include <iostream>
7 #include <fstream>
8 
9 #include <GL\glew.h>
10 
11 namespace pk
12 {
18  class Shader
19  {
20  private:
26  void compile(const char* vertexCode, const char* fragmentCode);
27 
34  void attach(GLuint theProgram, const char* shaderCode, GLenum shaderType);
35 
36  public:
45  Shader();
46 
53  Shader(const char* vertexLocation, const char* fragmentLocation);
54 
55  ~Shader();
56 
64  void loadFromString(const char* vertexCode, const char* fragmentCode);
65 
73  void load(const char* vertexLocation, const char* fragmentLocation);
74 
81  std::string read(const char* fileLocation);
82 
91 
99  GLuint &getModelLocation() { return m_uniformModel; };
100 
108  GLuint &getViewLocation() { return m_uniformView; };
109 
118 
127 
136 
145 
154 
163 
172 
179  void use();
180 
187  void clear();
188 
189  private:
190  GLuint m_shaderID;
192  GLuint m_uniformModel;
193  GLuint m_uniformView;
201  };
202 }
203 
204 #endif // SHADER_HPP
GLuint m_uniformSpecularIntensity
A memory location for the specular intensity of the material.
Definition: Shader.hpp:199
GLuint & getProjectionLocation()
Get the memory location of the OpenGL Projection matrix in use.
Definition: Shader.hpp:90
GLuint m_uniformProjection
An OpenGL Projection matrix memory location.
Definition: Shader.hpp:191
std::string read(const char *fileLocation)
Read the contents of a shader file and output a std::string to be loaded as an OpenGL GLSL shader...
GLuint & getDiffuseIntensityLocation()
Get the memory location of the diffuse intensity for lighting.
Definition: Shader.hpp:135
Definition: Game.hpp:7
void compile(const char *vertexCode, const char *fragmentCode)
Internal function that compiles and validates the GLSL shaders being loaded.
GLuint m_uniformDirection
A memory location for direction.
Definition: Shader.hpp:197
void load(const char *vertexLocation, const char *fragmentLocation)
Load OpenGL shader programs from file locations specified with C-style strings.
GLuint & getAmbientIntensityLocation()
Get the memory location of the ambient intensity for lighting.
Definition: Shader.hpp:117
GLuint m_uniformAmbientIntensity
A memory location for ambient intensity.
Definition: Shader.hpp:194
GLuint & getModelLocation()
Get the memory location of the OpenGL Model matrix in use.
Definition: Shader.hpp:99
GLuint & getViewLocation()
Get the memory location of the OpenGL View matrix in use.
Definition: Shader.hpp:108
GLuint m_uniformModel
An OpenGL Model matrix memory location.
Definition: Shader.hpp:192
GLuint m_uniformShininess
A memory location for the shininess of the material.
Definition: Shader.hpp:200
GLuint & getDirectionLocation()
Get the memory location of the direction of the lighting.
Definition: Shader.hpp:144
Shader()
Default constructor - in most cases you should be using the other constructor! Use this in the event ...
GLuint & getEyePositionLocation()
Get the memory location of the eye position of the lighting.
Definition: Shader.hpp:153
void use()
Call the necessary OpenGL code to use the shader. Needs to be called before drawing occurs in the gam...
Definition: Shader.hpp:171
GLuint & getAmbientColorLocation()
Get the memory location of the ambient color for lighting.
Definition: Shader.hpp:126
Class for supporting OpenGL GLSL shaders.
Definition: Shader.hpp:18
GLuint m_uniformView
An OpenGL View matrix memory location.
Definition: Shader.hpp:193
GLuint m_uniformDiffuseIntensity
A memory location for diffuse intensity.
Definition: Shader.hpp:196
GLuint m_uniformAmbientColor
A memory location for lighting ambient color.
Definition: Shader.hpp:195
GLuint & getShininessLocation()
Get the memory location of the shininess of the lighting.
Definition: Shader.hpp:171
GLuint & getSpecularIntensityLocation()
Get the memory location of the specular intensity of the lighting.
Definition: Shader.hpp:162
void attach(GLuint theProgram, const char *shaderCode, GLenum shaderType)
Internal function that performs the necessary actions to attach a shader to the OpenGL program...
void loadFromString(const char *vertexCode, const char *fragmentCode)
Load OpenGL shader programs from C-strings.
GLuint m_uniformEyePosition
A memory location for eye position (camera).
Definition: Shader.hpp:198
void clear()
Resets all states and data contained in the Shader class. Calls glDeleteProgram(...) because Shader class owns the shader program.
GLuint m_shaderID
The OpenGL GLSL shader ID.
Definition: Shader.hpp:190