]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixing layer bugs
authordrumsetmonkey <abelleisle@roadrunner.com>
Mon, 23 May 2016 11:37:45 +0000 (07:37 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Mon, 23 May 2016 11:37:45 +0000 (07:37 -0400)
brice.dat
include/common.hpp
main.cpp
shaders/world.frag

index 61d57c2785952fa6cb22f35f6db947ff5ddf91d2..ea71945339f7a7cd6d35324a11df49578bb93bfc 100644 (file)
--- a/brice.dat
+++ b/brice.dat
@@ -1,5 +1,5 @@
 2
-canJump
-0
 canSprint
 0
+canJump
+0
index d0806523b1b23ab7b8f4d86d431cb778433d026b..934ede5f91222037f8e2d3a3d60a7a4911ac8703 100644 (file)
@@ -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.
  */
index 375a2706235ea19cf94895c35da1ac013afdfff1..2f094dc1d6573971f80f8dbfcdc26edb3197b6f4 100644 (file)
--- 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();
 
index c10343350f79d413720df7ee4f89343b002dfed7..d50e01dbc39b7b041014f61e4d48d8ed46df559c 100644 (file)
@@ -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;
 }