]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Fixed nvidia GLSL bug
authordrumsetmonkey <abelleisle@roadrunner.com>
Wed, 13 Jan 2016 02:28:22 +0000 (21:28 -0500)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Wed, 13 Jan 2016 02:28:22 +0000 (21:28 -0500)
main.cpp
test.frag

index 79c7250dab313f1b594452846281b9b80d6062dd..c3638757b02e6619c4bae62e506d04d1e4c3c5ac 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -341,43 +341,41 @@ int main(/*int argc, char *argv[]*/){
         *      Initializes our shaders so that the game has shadows.
        */
        
-       #ifdef SHADERS
-               std::cout << "Initializing shaders!" << std::endl;
+       std::cout << "Initializing shaders!" << std::endl;
 
-               fragShader = glCreateShader(GL_FRAGMENT_SHADER);
+       fragShader = glCreateShader(GL_FRAGMENT_SHADER);
 
-               std::string shaderFileContents = readFile("test.frag");
-               const GLchar *shaderSource = shaderFileContents.c_str();
+       std::string shaderFileContents = readFile("test.frag");
+       const GLchar *shaderSource = shaderFileContents.c_str();
 
-               GLint bufferln = GL_FALSE;
-               int logLength;  
+       GLint bufferln = GL_FALSE;
+       int logLength;  
 
 
-               glShaderSource(fragShader, 1, &shaderSource, NULL);
-               glCompileShader(fragShader);
+       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){
-                       std::cout << "Error compiling shader" << std::endl;
-               }
+       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){
+               std::cout << "Error compiling shader" << std::endl;
+       }
 
-               shaderProgram = glCreateProgram();              
-               glAttachShader(shaderProgram, fragShader);
-               glLinkProgram(shaderProgram);
-               glValidateProgram(shaderProgram);
+       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;
+       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;
                        
-       #endif //SHADERS
        
        //glEnable(GL_DEPTH_TEST); //THIS DOESN'T WORK ON LINUX
        glEnable(GL_MULTISAMPLE);
index 5c9054ea227b3bce951a7f48bdc5ae05698aae9f..07b4a8aaa43629d6beaa6bb7c13ae9adfb92d072 100644 (file)
--- a/test.frag
+++ b/test.frag
@@ -2,7 +2,7 @@
 uniform sampler2D sampler;\r
 \r
 uniform int numLight;\r
-uniform vec2 lightLocation[1024];\r
+uniform vec2 lightLocation[64];\r
 uniform vec3 lightColor;\r
 uniform float amb;\r
 \r
@@ -10,20 +10,22 @@ float b = .0005;
 float minLight = .05;\r
 float radius = sqrt(1.0 / (b * minLight));\r
 \r
+//float radius = b*minlight;\r
+\r
 void main(){\r
-       vec4 color = vec4(0.0f,0.0f,0.0f,0.0f);\r
+       vec4 color = vec4(0.0,0.0,0.0,0.0);\r
        for(int i = 0; i < numLight; i++){\r
                vec2 loc = lightLocation[i];\r
                float dist = length(loc - gl_FragCoord.xy);\r
                //float attenuation=1.0/(1.0+0.01*dist+0.00000000001*dist*dist);\r
                float attenuation = clamp(1.0 - dist*dist/(radius*radius), 0.0, 1.0); attenuation *= attenuation;\r
 \r
-               color += vec4(attenuation, attenuation, attenuation, 1.0f) * vec4(lightColor, 1.0f);\r
+               color += vec4(attenuation, attenuation, attenuation, 1.0) * vec4(lightColor, 1.0);\r
        }\r
        vec2 coords = gl_TexCoord[0].st;\r
        vec4 tex = texture2D(sampler, coords);\r
 \r
-       color += vec4(amb,amb,amb,1.0f+amb);\r
+       color += vec4(amb,amb,amb,1.0+amb);\r
        gl_FragColor = tex * vec4(color)*tex.a;\r
 }\r
 \r
@@ -34,4 +36,4 @@ void main(){
        .00008          500\r
        .00002          1000\r
        .00005          2000\r
-*/\r
+*/
\ No newline at end of file