title: Using both phong and textures in glsl
body: <p>I have got problem with my shaders. I am trying to put textures and phong shading in my game using glsl but I can't get any good effect. </p>
  
  <p>I've been searching google for a long time, and I can't find any info how connect ligh and texture together, so I've decided to wrote and ask here.</p>
  
  <p>This is my game without texture:
  <img src="https://i.stack.imgur.com/4ElDy.jpg" alt="without texture"></p>
  
  <p>and this is with texture:</p>
  
  <p><img src="https://i.stack.imgur.com/dJd8n.jpg" alt="with texture"></p>
  
  <p>What I want to achive is to make this pinkish texture make better visible with spot on a center - just like without texture, and also repair those per vertex shading on gutters - make it per pixel shading, I don't know what is wrong now.</p>
  
  <p>I have checked about 10 shaders with phong shading and I have got also per vertex not per pixel shading.</p>
  
  <p>This is my fragment vertex code mayby someone can see there something?</p>
  
  <pre><code>    varying vec3 N;
      varying vec3 v; 
      uniform sampler2D myTexture;
  
      varying vec2 vTexCoord;    
  
      void main (void)  
      {  
         vec4 finalColor = vec4(0.0, 0.0, 0.0, 0.0);
  
  vec3 L = normalize(gl_LightSource[0].position.xyz - v);   
             vec3 E = normalize(-v); // we are in Eye Coordinates, so EyePos is (0,0,0)  
             vec3 R = normalize(-reflect(L,N));  
  
             //calculate Ambient Term:  
             vec4 Iamb = gl_FrontLightProduct[0].ambient;    
  
             //calculate Diffuse Term:  
             vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);    
  
             // calculate Specular Term:
             vec4 Ispec = gl_FrontLightProduct[0].specular 
                          * pow(max(dot(R,E),0.0),0.3*gl_FrontMaterial.shininess);
  
              finalColor+=Iamb + Idiff + Ispec;
         // write Total Color:
         gl_FragColor = gl_FrontLightModelProduct.sceneColor + (texture2D(myTexture, vTexCoord)) + finalColor;
      }
  </code></pre>
  
  <p>and my vertex shader</p>
  
  <pre><code>varying vec3 N;
  varying vec3 v;
  varying vec2 vTexCoord;
  
  void main(void)
  {
  
     v = vec3(gl_ModelViewMatrix * gl_Vertex);       
     N = normalize(gl_NormalMatrix * gl_Normal);
     vTexCoord = vec2(gl_MultiTexCoord0);
  
     gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  
  
  }
  </code></pre>
  
  <p><strong>I'll be glad for help.</strong></p>
  
  <p>EDIT:</p>
  
  <p>this is how I put my texture into shader. It works fine ( I think ) because I can edit texture values in shader - in some way.</p>
  
  <pre><code>int my_sampler_uniform_location = glGetUniformLocation(brickProg, "myTexture");
  
  glActiveTexture(GL_TEXTURE0);
  glBindTexture(GL_TEXTURE_2D, texture);
  
  glUniform1i(my_sampler_uniform_location,0);
  CUTIL::drawBox();
  glBindTexture(GL_TEXTURE_2D,0);
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <p>After Nicol Bolas suggestion about colors add I have edited my shader and change it like this:</p>
  
  <p>gl_FragColor = (texture2D(myTexture, vTexCoord)) + finalColor;</p>
  
  <p>Now it is only to bright, but now I have to chenge a little light on stage and would be great. But still I haven't got per pixel shading instead I have got per vertex shading. This is my current screen and I have marked on example what I mean talking about shading:</p>
  
  <p><img src="https://i.stack.imgur.com/xZphF.jpg" alt="enter image description here"></p>