Results 1 to 3 of 3

Thread: getting z-coordinate from elevation map

  1. #1

    getting z-coordinate from elevation map

    Hi All,
    please can you help me with this: - I'm trying to get a z-coordinate from a elevation map in vertex shader, but I'm missing something. After first drawElements I'm getting glError 1282. I think that something is wrong in my vertex shader, but can not figure out that what.

    Here is my code:
    fragment shader:
    Code :
    uniform vec4 uFSLevelColor;	
        void main(void) {
           	gl_FragColor = uFSLevelColor;
        }
    vertex shader:
    Code :
    attribute vec3 aVertexPosition;
      // elevation map variables definition:
      attribute vec2 aDEMcoordinate; // holding coordinate for elevation map
      uniform sampler2D uDEM_sampler; // DEM sampler
      // -----------------
      uniform vec2 blockOffset;
      uniform mat4 uMVMatrix;
      uniform mat4 uPMatrix;
     
      void main(void) {
      vec3 vtx = aVertexPosition;
      // getting only first parameter (since in grayscale rgb is the same)
      float zCoord = texture2D(uDEM_sampler, aDEMcoordinate).r;  
      vtx.z = zCoord; 
      gl_Position = uPMatrix * uMVMatrix  * (vec4(vtx, 1.0) + vec4(blockOffset, 0.0, 1.0));
      }
    getting attributes and uniform variables: - attrib arrays are created correctly - debuged and checked
    Code :
      shaderProgram.vertexPositionAttribute = gl.getAttribLocation(shaderProgram, "aVertexPosition");
      gl.enableVertexAttribArray(shaderProgram.vertexPositionAttribute);
      shaderProgram.DEMpositionAttribute = gl.getAttribLocation(shaderProgram, "aDEMcoordinate");
      gl.enableVertexAttribArray(shaderProgram.DEMpositionAttribute);
      shaderProgram.pMatrixUniform = gl.getUniformLocation(shaderProgram, "uPMatrix");
      shaderProgram.mvMatrixUniform = gl.getUniformLocation(shaderProgram, "uMVMatrix");
      shaderProgram.blockOffset = gl.getUniformLocation(shaderProgram, "blockOffset");
      shaderProgram.DEM_sampler = gl.getUniformLocation(shaderProgram, "uDEM_sampler");
    // function for loading texture I'm not going to copy here (I think that there should be not the problem)
    // texture VBO:
    Code :
    DEM_buffer = gl.createBuffer();  
      gl.bindBuffer(gl.ARRAY_BUFFER, DEM_buffer);    
      textureCoordinates = [ 0.0, 0.0,    1.0, 0.0,    1.0, 1.0,    0.0, 1.0];
      gl.bufferData(gl.ARRAY_BUFFER, new WebGLFloatArray(textureCoordinates), gl.STATIC_DRAW);
    // and finally the draw() / redraw() function
    Code :
        gl.bindBuffer(gl.ARRAY_BUFFER, DEM_buffer);
        gl.vertexAttribPointer(shaderProgram.DEMpositionAttribute, 2, gl.FLOAT, false, 0, 0);
        gl.activeTexture(gl.TEXTURE0);  
        gl.bindTexture(gl.TEXTURE_2D, testTexture); 
        gl.uniform1i(shaderProgram.DEM_sampler, 0);  
        gl.bindBuffer(gl.ARRAY_BUFFER, vbo_MxM);
        gl.vertexAttribPointer(shaderProgram.vertexPositionAttribute, 3, gl.FLOAT, false, 0, 0);	
        gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo_MxM);
        gl.uniform2f(shaderProgram.blockOffset, 64.0, 1.0);
        gl.drawElements(gl.TRIANGLE_STRIP, 8064, gl.UNSIGNED_SHORT, 0);
    After the last command - drawElements I'm getting the glError 1282
    any help/idea is more then welcomed, since I really don't know what is wrong..

  2. #2

    Re: getting z-coordinate from elevation map

    one thing - if I comment:
    Code :
    gl.enableVertexAttribArray(shaderProgram.DEMpositionAttribute);
    and comment the texture related code Iīm not getting the 1282 glError after the drawElements(). The shaderProgram.DEMpositionAttribute variable is generated correctly - that I have debuged.

    So most probably something in the aDEMcoordinate attribute? - can not figure out what

  3. #3

    Re: getting z-coordinate from elevation map

    Quote Originally Posted by miroslav_karpis
    So most probably something in the aDEMcoordinate attribute? - can not figure out what
    no, vertex shader was correct. The 1282 glError problem was that I didnīt disable/enable vertexAttribArray between the attribute usage calls.

    So now no glError, but still some problem with drawing/getting the z-coord.

Similar Threads

  1. about texture coordinate
    By freesui1984 in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 09-18-2008, 06:22 PM
  2. about texture coordinate
    By freesui1984 in forum OpenGL ES general technical discussions
    Replies: 0
    Last Post: 09-18-2008, 06:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •