Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Regarding glMapBuffferRange

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    190

    Regarding glMapBuffferRange

    Code :
     GLfloat vertices4[]={-0.9,0.6, -0.9,0.2, -0.6,0.2, -0.6,0.6,
                                      -0.4,0.6, -0.4,0.2,  0.1,0.2,  0.1,0.6,
                            0.3,0.6,  0.3,0.2,  0.6,0.2,  0.6,0.6  };
     
         GLushort indices[]={0,1,2,3, 120, 4,5,6,7, 120, 8,9,10,11};
          GLenum *value=GL_STREAM_DRAW;  
           GLfloat temp_err;
           glEnable(GL_PRIMITIVE_RESTART);
            nResult =GL_ERROR_CHECK((GL_NO_ERROR,"glEnable(GL_PRIMITIVE_RESTART)"));
     
         glPrimitiveRestartIndex(120);
             nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glPrimitiveRestartIndex(120);"));
     
           glGenBuffers(1,&bufferid1);
            nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGenBuffers(1,&bufferid1)"));
     
            glGenBuffers(1,bufferid);
     
            glBindBuffer(GL_TEXTURE_BUFFER,bufferid);
     
           glBufferData(GL_TEXTURE_BUFFER,sizeof(vertices4),vertices4,*value);
     
          temp_err=(GLfloat*)glMapBufferRange(GL_TEXTURE_BUFFER,0,8*sizeof(GLfloat),GL_MAP_READ_BIT);
     
     
        glBindBuffer(GL_ARRAY_BUFFER,bufferid1);
        nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glBindBuffer(GL_ARRAY_BUFFER,bufferid1);")); 
     
        glBufferData(GL_ARRAY_BUFFER,8*sizeof(GLfloat),temp_err,*value);
     
     
       *attr_vertex = glGetAttribLocation(shader_data.psId, "a_position"); 
         nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glGetAttribLocation(shader_data.psId, \"a_position\");"));
     
       glVertexAttribPointer(*attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0, 0);
         nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glVertexAttribPointer(attr_vertex, 2 , GL_FLOAT, GL_FALSE ,0, 0);"));
     
         glEnableVertexAttribArray(*attr_vertex);
        nResult = GL_ERROR_CHECK((GL_NO_ERROR,"glEnableVertexAttribArray(attr_vertex);"));
     
        glUniform1f(glGetUniformLocation(shader_data.psId,"offset_x"),x);                       
       glUniform1f(glGetUniformLocation(shader_data.psId,"offset_y"),y);                    
          glDrawElements(GL_TRIANGLE_FAN, 14,GL_UNSIGNED_SHORT,indices);

    Here i am expecting it would render 1 quad as i am passing vertex data of first quad in "bufferid1" but it renders all the 3 quads in vertices4. Please point me where i am going wrong here.

  2. #2
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,097
    Code :
    glDrawElements(GL_TRIANGLE_FAN, 14,GL_UNSIGNED_SHORT,indices);
    I am unclear what you would expect to get when you draw past the end of you buffer.

    Try
    Code :
    glDrawElements(GL_TRIANGLE_FAN, 4,GL_UNSIGNED_SHORT,indices);

Posting Permissions

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