Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: glVertexAttribP4uiv

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

    glVertexAttribP4uiv

    i have been trying to use glVertexAttribP with GL_UNSIGNED_INT_2_10_10_10_REV but stuck up at some point.

    here is my code

    Code :
    GLuint red=0,green=511,blue=511,alpha=3;
    	GLuint val = 0;
     
    	val = val | (alpha << 30);
    	val = val | (blue << 20);
    	val = val | (green << 10);
    	val = val | (red << 0);
    	GLfloat vertices[]={-0.9f, -0.9f, 0.0f,1.0f,
    						 -0.9f, 0.6f, 0.0f,1.0f,
    						 0.6f,0.6f,0.0f,1.0f,
    						 0.6f,-0.9f,0.0f,1.0f};
     
     
    	GLuint test_data[]={val,val,val,val};
    	glGenBuffers(1, &BufferId);
    	glBindBuffer(GL_ARRAY_BUFFER, BufferId);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
     
    	glEnableVertexAttribArray(glGetAttribLocation(shader_data.psId,"position"));
    	glVertexAttribPointer(glGetAttribLocation(shader_data.psId,"position"), 4,GL_FLOAT,GL_FALSE, 0,0);
     
     
    	glGenBuffers(1, &BufferId1);
    	glBindBuffer(GL_ARRAY_BUFFER, BufferId1);
    	glBufferData(GL_ARRAY_BUFFER, sizeof(test_data), test_data, GL_STATIC_DRAW);
     
    	glEnableVertexAttribArray(glGetAttribLocation(shader_data.psId,"color"));
    //	glVertexAttribPointer(glGetAttribLocation(shader_data.psId,"color"), 4,GL_INT_2_10_10_10_REV,GL_TRUE, 0,0);
          glVertexAttribP4uiv(glGetAttribLocation(shader_data.psId,"color"),GL_UNSIGNED_INT_2_10_10_10_REV ,GL_TRUE,0);
     
     
    	glDrawArrays(GL_TRIANGLE_FAN,0,4);

    it gives Access violation at glDraw call. code works fine with glVertexAttribPointer. what am i missing here?
    Last edited by debonair; 05-16-2013 at 03:37 AM.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    `glEnableVertexAttribArray` says that you're using an array for that attribute. But you're not using an array. So OpenGL tries to access an array that you haven't specified. Hence the boom.

    Disable the array instead of enabling it.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    thanks for the quick one..
    Now, i commented glEnableVertexAttribArray() call keeping rest same. now i get a black color..

  4. #4
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    Quote Originally Posted by Alfonse Reinheart View Post
    `glEnableVertexAttribArray` says that you're using an array for that attribute. But you're not using an array. So OpenGL tries to access an array that you haven't specified. Hence the boom.

    Disable the array instead of enabling it.
    when i comment glEnableVertexAttribArray() i get a black color. Seems that it fails to take color values.

  5. #5

  6. #6
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    Quote Originally Posted by Alfonse Reinheart View Post
    You get black because that's what you set the color to.
    Sorry, i didn't get you.
    I am setting it to non zero values though red, green, blue variables in my code and finally doing bit-wise operations. Please correct me if wrong.

  7. #7
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    Then show the statement where you're doing that. It isn't in the code you posted:

    Code :
    glVertexAttribP4uiv(glGetAttribLocation(shader_data.psId,"color"),GL_UNSIGNED_INT_2_10_10_10_REV ,GL_TRUE,0);

    That sets the value to 0. Which means that it's 0 for all four components.

  8. #8
    Advanced Member Frequent Contributor arekkusu's Avatar
    Join Date
    Nov 2003
    Posts
    781
    glVertexAttribP4uiv sets the constant current-vertex attribute. Since you passed "0" it should immediately dereference NULL and crash, not set all black.
    glVertexAttribP4ui (no 'v') on the other hand would have set the attribute to all black.

  9. #9
    Junior Member Regular Contributor
    Join Date
    Jun 2012
    Posts
    204
    Thanks a lot guys.
    I thought glVertexAttribP4ui works with buffer objects so i was passing it 0 as offset. I didn't understand 'y'. And when i passed array into it, it was giving black because AMD is buggy. Later tried on nvidia and it worked.
    Seems that i need to read some more stuff to get insight how it actually works.
    Last edited by debonair; 05-19-2013 at 11:06 PM.

  10. #10
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,948
    And when i passed array into it, it was giving black because AMD is buggy. Later tried on nvidia and it worked.
    It doesn't take an array. Well, it kind of does, but it's only an array with one unsigned integer element in length. Really, I have no idea why they even added the `v` versions of these functions.

    The functions that take real arrays of values are the glVertexAttribPointer functions.

Posting Permissions

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