title: How to make a sample 1D textures in modern opengl?
body: <p>I created this simple program. It creates two textures, a 2D and a 1D texture binds them, etc.</p>
  
  <p><em>I can sample and draw from the 2D texture in my shader program with no problems. Trying to sample and draw from the 1D texture, the quad turns out black.</em></p>
  
  <p>If I don't use the 1D texture sample in the fragment shader below in the if..else.. statement, everything renders in black and white. Trying to use the sample, it only renders a black screen.</p>
  
  <p><strong><em>If I do some hackery like this:</em></strong></p>
  
  <pre><code>if (i == maxIterations)
      {
         tcolor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
      }
      else if(i &lt;= 10)
      {
          tcolor = vec4(1.0f, 0.0f, 0.0f, 0.0f);
  
      } else if ( i &gt;= 11)
      {
          tcolor = vec4(1.0f, 1.0f, 0.0f, 0.0f);
      }
  </code></pre>
  
  <p><strong><em>it also works..... How do I sample 1D textures?</em></strong></p>
  
  <p><strong>source code below</strong></p>
  
  <pre><code>    glGenTextures(1, &amp;colorTextureID);
      glBindTexture(GL_TEXTURE_2D, colorTextureID);
  
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  
  
      glTexImage2D(GL_TEXTURE_2D, 0, Mode, colorSurface-&gt;w, colorSurface-&gt;h, 0, Mode, GL_UNSIGNED_BYTE, colorSurface-&gt;pixels);
      glGenerateMipmap(GL_TEXTURE_2D);
      glBindTexture(GL_TEXTURE_2D, 0);
      free(colorSurface);
  
      //mandi 1d texture
      glGenTextures(1, &amp;mandiTextureID);
      glBindTexture(GL_TEXTURE_1D, mandiTextureID);
  
      glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
      glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  
      glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
      glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  
  
      glTexImage1D(GL_TEXTURE_1D, 0, Mode1, mandiSurface-&gt;w, 0, Mode1, GL_UNSIGNED_BYTE, mandiSurface-&gt;pixels);
      glBindTexture(GL_TEXTURE_1D, 0);
      free(mandiSurface);
  
      //render
      void render()
  {
      glClearColor(0.2f, 0.3f, 0.3f, 1.0f);
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  
      //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glUseProgram(sp);
  
      glActiveTexture(GL_TEXTURE0);
      glBindTexture(GL_TEXTURE_2D, colorTextureID);//ourTexture
      ourTexture = getUniformLocation(sp, "ourTexture");
      glUniform1i(ourTexture, 0);
  
      glActiveTexture(GL_TEXTURE1);
      glBindTexture(GL_TEXTURE_1D, mandiTextureID);//mandiTexture
      mandiTexture = getUniformLocation(sp, "mandiTexture");
      glUniform1i(mandiTexture, 1);
  
  
      glBindVertexArray(verticesBuffer);
      viewMat = getUniformLocation(sp, "viewMat");
      modelMat = getUniformLocation(sp, "modelMat");
      projMat = getUniformLocation(sp, "projMat");
  
      maxIterLoc = getUniformLocation(sp, "maxIterations");
      centerLoc = getUniformLocation(sp, "center");
      scaleLoc = getUniformLocation(sp, "scale");
  
      glUniformMatrix4fv(viewMat, 1, GL_FALSE, vm.m);
      glUniformMatrix4fv(projMat, 1, GL_FALSE, opm.m);
      glUniformMatrix4fv(modelMat, 1, GL_FALSE, tm.m);
  
      glUniform1i(maxIterLoc, 20);
      glUniform1f(scaleLoc, scale);
      glUniform2f(centerLoc, cx, cy);
  
      glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
      glBindVertexArray(0);
  }
  </code></pre>
  
  <p><strong>Vertex shader</strong></p>
  
  <pre><code>#version 330 core
  
  layout (location = 0) in vec3 position;
  layout (location = 1) in vec3 icolor;
  layout (location = 2) in vec2 vTexCoord;
  
  uniform mat4 modelMat;
  uniform mat4 viewMat;
  uniform mat4 projMat;
  
  out vec4 fcolor;
  out vec2 fTexCoord;
  out vec2 fCoord;
  
  void main()
  {
      gl_Position =  projMat * viewMat * modelMat * vec4(position, 1.0);
  
      fCoord = vec2(position);
      fTexCoord = vTexCoord;
      fcolor = vec4(icolor, 1.0f);
  }
  </code></pre>
  
  <p><strong>Fragment shader</strong></p>
  
  <pre><code>#version 330 core
  
  in vec4 fcolor;
  in vec2 fTexCoord;
  in vec2 fCoord;
  
  uniform int maxIterations;
  uniform vec2 center;
  uniform float scale;
  
  uniform sampler2D ourTexture;
  uniform sampler1D mandiTexture;
  
  out vec4 color;
  
  void main()
  {
     vec2 c, z;
  
      c.x = 1.3333 * (fCoord.x - 0.5) - center.x;
      c.y = (fCoord.y - 0.5) - center.y;
  
          int i;
          z = c;
          for(i=0; i&lt;maxIterations; i++) {
              float x = (z.x * z.x - z.y * z.y) + c.x;
              float y = (z.y * z.x + z.x * z.y) + c.y;
  
              if((x * x + y * y) &gt; 4.0) break;
              z.x = x;
              z.y = y;
          }
  
      vec4 tcolor;
  
      if (i == maxIterations)
      {
         tcolor = vec4(0.0f, 0.0f, 0.0f, 1.0f);
      }
      else
      {
         /* tcolor = vec4(1.0f, 1.0f, 1.0f, 1.0f);  this works but only renders black and white */
         tcolor = texture(mandiTexture, float(i)).rgba; /* only renders black screen */
      }
  
      /* color = texture(ourTexture, fTexCoord) * fcolor; //this also works */
      color = tcolor;
  }
  </code></pre>