aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--brice.dat4
-rw-r--r--include/common.hpp11
-rw-r--r--main.cpp83
-rw-r--r--shaders/world.frag26
4 files changed, 64 insertions, 60 deletions
diff --git a/brice.dat b/brice.dat
index 61d57c2..ea71945 100644
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,5 @@
2
-canJump
-0
canSprint
0
+canJump
+0
diff --git a/include/common.hpp b/include/common.hpp
index d080652..934ede5 100644
--- a/include/common.hpp
+++ b/include/common.hpp
@@ -218,9 +218,7 @@ constexpr const float PI = 3.1415926535f;
// references the variable in main.cpp, used for drawing with the player
extern vec2 offset;
-// the shader program created in main.cpp
-extern GLuint shaderProgram;
-
+// reference to the shader programs we use throughout
extern GLuint textShader;
extern GLint textShader_attribute_coord;
extern GLint textShader_attribute_tex;
@@ -231,8 +229,14 @@ extern GLuint worldShader;
extern GLint worldShader_attribute_coord;
extern GLint worldShader_attribute_tex;
extern GLint worldShader_uniform_texture;
+extern GLint worldShader_uniform_texture_normal;
extern GLint worldShader_uniform_color;
extern GLint worldShader_uniform_transform;
+extern GLint worldShader_uniform_ambient;
+extern GLint worldShader_uniform_light;
+extern GLint worldShader_uniform_light_color;
+extern GLint worldShader_uniform_light_impact;
+extern GLint worldShader_uniform_light_amt;
/**
* Prints a formatted debug message to the console, along with the callee's file and line
@@ -240,6 +244,7 @@ extern GLint worldShader_uniform_transform;
*/
void DEBUG_prints(const char* file, int line, const char *s,...);
+// TODO make sure we don't use these. Then burn them.
/**
* Sets color using glColor3ub(), but handles potential overflow.
*/
diff --git a/main.cpp b/main.cpp
index 375a270..2f094dc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -50,10 +50,6 @@ Menu *currentMenu;
// the player object
Player *player;
-// shaders for rendering
-GLuint fragShader;
-GLuint shaderProgram;
-
/**
* These are the source and index variables for our shader
* used to draw text and ui elements
@@ -75,9 +71,15 @@ GLuint worldShader;
GLint worldShader_attribute_coord;
GLint worldShader_attribute_tex;
GLint worldShader_uniform_texture;
+GLint worldShader_uniform_texture_normal;
GLint worldShader_uniform_transform;
GLint worldShader_uniform_ortho;
GLint worldShader_uniform_color;
+GLint worldShader_uniform_ambient;
+GLint worldShader_uniform_light;
+GLint worldShader_uniform_light_color;
+GLint worldShader_uniform_light_impact;
+GLint worldShader_uniform_light_amt;
// keeps a simple palette of colors for single-color draws
GLuint colorIndex;
@@ -181,58 +183,36 @@ int main(int argc, char *argv[]){
// initialize shaders
std::cout << "Initializing shaders!\n";
- const GLchar *shaderSource = readFile("frig.frag");
- GLint bufferln = GL_FALSE;
- int logLength;
-
- fragShader = glCreateShader(GL_FRAGMENT_SHADER);
- glShaderSource(fragShader, 1, &shaderSource, NULL);
- glCompileShader(fragShader);
-
- glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bufferln);
- glGetShaderiv(fragShader, GL_INFO_LOG_LENGTH, &logLength);
-
- std::vector<char> fragShaderError ((logLength > 1) ? logLength : 1);
-
- glGetShaderInfoLog(fragShader, logLength, NULL, &fragShaderError[0]);
- std::cout << &fragShaderError[0] << std::endl;
-
- if (bufferln == GL_FALSE)
- UserError("Error compiling shader");
-
- shaderProgram = glCreateProgram();
- glAttachShader(shaderProgram, fragShader);
- glLinkProgram(shaderProgram);
- glValidateProgram(shaderProgram);
-
- glGetProgramiv(shaderProgram, GL_LINK_STATUS, &bufferln);
- glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &logLength);
- std::vector<char> programError((logLength > 1) ? logLength : 1);
- glGetProgramInfoLog(shaderProgram, logLength, NULL, &programError[0]);
- std::cout << &programError[0] << std::endl;
-
- delete[] shaderSource;
-
/**
* Creating the text shader and its attributes/uniforms
*/
- textShader = create_program("shaders/new.vert", "shaders/new.frag");
- textShader_attribute_coord = get_attrib(textShader, "coord2d");
- textShader_attribute_tex = get_attrib(textShader, "tex_coord");
- textShader_uniform_texture = get_uniform(textShader, "sampler");
- textShader_uniform_transform = get_uniform(textShader, "ortho");
- textShader_uniform_color = get_uniform(textShader, "tex_color");
+ textShader = create_program("shaders/new.vert", "shaders/new.frag");
+
+ textShader_attribute_coord = get_attrib(textShader, "coord2d");
+ textShader_attribute_tex = get_attrib(textShader, "tex_coord");
+
+ textShader_uniform_texture = get_uniform(textShader, "sampler");
+ textShader_uniform_transform = get_uniform(textShader, "ortho");
+ textShader_uniform_color = get_uniform(textShader, "tex_color");
/**
* Creating the world's shader and its attributes/uniforms
*/
- worldShader = create_program("shaders/world.vert", "shaders/world.frag");
- worldShader_attribute_coord = get_attrib(worldShader, "coord2d");
- worldShader_attribute_tex = get_attrib(worldShader, "tex_coord");
- worldShader_uniform_texture = get_uniform(worldShader, "sampler");
- worldShader_uniform_transform = get_uniform(worldShader, "transform");
- worldShader_uniform_ortho = get_uniform(worldShader, "ortho");
- worldShader_uniform_color = get_uniform(worldShader, "tex_color");
+ worldShader = create_program("shaders/world.vert", "shaders/world.frag");
+
+ worldShader_attribute_coord = get_attrib(worldShader, "coord2d");
+ worldShader_attribute_tex = get_attrib(worldShader, "tex_coord");
+
+ worldShader_uniform_texture = get_uniform(worldShader, "texture");
+ worldShader_uniform_texture_normal = get_uniform(worldShader, "normalTex");
+ worldShader_uniform_transform = get_uniform(worldShader, "transform");
+ worldShader_uniform_ortho = get_uniform(worldShader, "ortho");
+ worldShader_uniform_color = get_uniform(worldShader, "tex_color");
+ worldShader_uniform_ambient = get_uniform(worldShader, "ambient");
+ worldShader_uniform_light = get_uniform(worldShader, "light");
+ worldShader_uniform_light_color = get_uniform(worldShader, "lightColor");
+ worldShader_uniform_light_impact = get_uniform(worldShader, "lightImpact");
+ worldShader_uniform_light_amt = get_uniform(worldShader, "lightSize");
//glEnable(GL_MULTISAMPLE);
@@ -392,7 +372,11 @@ void render() {
glUseProgram(worldShader);
glUniformMatrix4fv(worldShader_uniform_ortho, 1, GL_FALSE, glm::value_ptr(ortho));
glUniformMatrix4fv(worldShader_uniform_transform, 1, GL_FALSE, glm::value_ptr(glm::mat4(1.0f)));
+
glUniform4f(worldShader_uniform_color, 1.0, 1.0, 1.0, 1.0);
+ glUniform1f(worldShader_uniform_ambient, 1.0);
+ glUniform1i(worldShader_uniform_light_amt, 0);
+ glUniform1f(worldShader_uniform_light_impact, 1.0);
/**************************
**** RENDER STUFF HERE ****
**************************/
@@ -407,6 +391,7 @@ void render() {
// draw the player's inventory
player->inv->draw();
+
// draw the fade overlay
ui::drawFade();
diff --git a/shaders/world.frag b/shaders/world.frag
index c103433..d50e01d 100644
--- a/shaders/world.frag
+++ b/shaders/world.frag
@@ -1,11 +1,25 @@
-uniform sampler2D sampler;
+uniform sampler2D texture;
+uniform sampler2D normalTex;
varying vec2 texCoord;
varying vec4 color;
-void main(){
- vec4 pixTex = texture2D(sampler, vec2(texCoord.x, 1-texCoord.y));
- if(pixTex.a == 0.0)
- discard;
- gl_FragColor = pixTex * color;
+uniform vec4 ambientLight;
+uniform vec4 light[128];
+uniform vec4 lightColor[128];
+uniform float lightImpact;
+uniform int lightSize;
+
+void main()
+{
+
+ vec4 pixTex = texture2D(texture, vec2(texCoord.x, 1-texCoord.y));
+ if (pixTex.a < 0.1)
+ discard;
+
+ if (lightSize > 0) {
+
+ }
+
+ gl_FragColor = pixTex * color * pixTex.a;
}