Could glVertexAttribPointer() last at attribute value in OpenGL be a array ?
up vote
1
down vote
favorite
Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone.
I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。
lazy var postions : [GLfloat] = [
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0,
]
lazy var colors : [GLfloat] = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
]
and this is the code about glVertexAttribPointer
let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
glEnableVertexAttribArray(posistionAtt)
let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
glEnableVertexAttribArray(colorAtt)
the result for the gradient triangel in the iPhone
swift opengl-es opengl-es-2.0
add a comment |
up vote
1
down vote
favorite
Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone.
I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。
lazy var postions : [GLfloat] = [
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0,
]
lazy var colors : [GLfloat] = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
]
and this is the code about glVertexAttribPointer
let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
glEnableVertexAttribArray(posistionAtt)
let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
glEnableVertexAttribArray(colorAtt)
the result for the gradient triangel in the iPhone
swift opengl-es opengl-es-2.0
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone.
I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。
lazy var postions : [GLfloat] = [
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0,
]
lazy var colors : [GLfloat] = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
]
and this is the code about glVertexAttribPointer
let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
glEnableVertexAttribArray(posistionAtt)
let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
glEnableVertexAttribArray(colorAtt)
the result for the gradient triangel in the iPhone
swift opengl-es opengl-es-2.0
Now I have two custom shader, the position vertex shader and the color fragment shader. And I define two array data, position Array and color Array. This can make the gradient triangel in the iPhone.
I didn't call the glBindBuffer() and glBufferData() for the VAO. but in the glVertexAttribPointer(),I send the position array to its last attribute and the color array too. Now, I feel confused,I found most documents explain the last attribute in this function, it is offset in vertex data array. now I send it to the array data and did not call the glBindBuffer() and glBufferData(), but it take effect。
lazy var postions : [GLfloat] = [
-0.5, -0.5, 0.0,
0.5, -0.5, 0.0,
0.0, 0.5, 0.0,
]
lazy var colors : [GLfloat] = [
1, 0, 0,
0, 1, 0,
0, 0, 1,
]
and this is the code about glVertexAttribPointer
let posistionAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "position"))
glVertexAttribPointer(posistionAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), postions)
glEnableVertexAttribArray(posistionAtt)
let ptr = UnsafePointer<Int>.init(bitPattern: 3 * MemoryLayout<GLfloat>.size)
let colorAtt : GLuint = GLuint(glGetAttribLocation(shaderProgram, "color"))
glVertexAttribPointer(colorAtt, 3, GLenum(GL_FLOAT), GLboolean(GL_FALSE), GLsizei(3 * MemoryLayout<GLfloat>.size), colors)
glEnableVertexAttribArray(colorAtt)
the result for the gradient triangel in the iPhone
swift opengl-es opengl-es-2.0
swift opengl-es opengl-es-2.0
edited Nov 10 at 18:04
Rabbid76
30k112842
30k112842
asked Nov 10 at 17:57
ADDICE
133
133
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.
See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:
void VertexAttribPointer( uint index, int size, enum type,
boolean normalized, sizei stride,
const void *pointer );
...
For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.
See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:
... When an array is sourced from
a buffer object, the pointer value of that array is used to compute an offset, in basic
machine units, into the data store of the buffer object. ...
This means, in case of
glBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(...., pointer)
pointer
has to be a pointer to the vertex array data - the array of vertex array data.
But in case of
glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
glVertexAttribPointer(...., offset)
offset
has to be an offset, to the data store of vbo
.
could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
– ADDICE
Nov 12 at 8:47
@ADDICE Yes. ForglBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(..., array)
,array
is the data array.
– Rabbid76
Nov 12 at 9:06
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.
See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:
void VertexAttribPointer( uint index, int size, enum type,
boolean normalized, sizei stride,
const void *pointer );
...
For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.
See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:
... When an array is sourced from
a buffer object, the pointer value of that array is used to compute an offset, in basic
machine units, into the data store of the buffer object. ...
This means, in case of
glBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(...., pointer)
pointer
has to be a pointer to the vertex array data - the array of vertex array data.
But in case of
glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
glVertexAttribPointer(...., offset)
offset
has to be an offset, to the data store of vbo
.
could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
– ADDICE
Nov 12 at 8:47
@ADDICE Yes. ForglBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(..., array)
,array
is the data array.
– Rabbid76
Nov 12 at 9:06
add a comment |
up vote
0
down vote
accepted
If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.
See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:
void VertexAttribPointer( uint index, int size, enum type,
boolean normalized, sizei stride,
const void *pointer );
...
For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.
See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:
... When an array is sourced from
a buffer object, the pointer value of that array is used to compute an offset, in basic
machine units, into the data store of the buffer object. ...
This means, in case of
glBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(...., pointer)
pointer
has to be a pointer to the vertex array data - the array of vertex array data.
But in case of
glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
glVertexAttribPointer(...., offset)
offset
has to be an offset, to the data store of vbo
.
could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
– ADDICE
Nov 12 at 8:47
@ADDICE Yes. ForglBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(..., array)
,array
is the data array.
– Rabbid76
Nov 12 at 9:06
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.
See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:
void VertexAttribPointer( uint index, int size, enum type,
boolean normalized, sizei stride,
const void *pointer );
...
For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.
See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:
... When an array is sourced from
a buffer object, the pointer value of that array is used to compute an offset, in basic
machine units, into the data store of the buffer object. ...
This means, in case of
glBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(...., pointer)
pointer
has to be a pointer to the vertex array data - the array of vertex array data.
But in case of
glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
glVertexAttribPointer(...., offset)
offset
has to be an offset, to the data store of vbo
.
If no vertex buffer object is bound, then the last parameter is treated as a pointer to the data.
See OpenGL ES 2.0 specification; 2.8. VERTEX ARRAYS; 21:
void VertexAttribPointer( uint index, int size, enum type,
boolean normalized, sizei stride,
const void *pointer );
...
For each command, pointer specifies the location in memory of the first value of the first element of the array being specified.
See OpenGL ES 2.0 specification; 2.9. BUFFER OBJECTS; 25:
... When an array is sourced from
a buffer object, the pointer value of that array is used to compute an offset, in basic
machine units, into the data store of the buffer object. ...
This means, in case of
glBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(...., pointer)
pointer
has to be a pointer to the vertex array data - the array of vertex array data.
But in case of
glBindBuffer(GL_ARRAY_BUFFER, vbo) // vbo != 0
glVertexAttribPointer(...., offset)
offset
has to be an offset, to the data store of vbo
.
edited Nov 12 at 9:05
answered Nov 10 at 18:16
Rabbid76
30k112842
30k112842
could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
– ADDICE
Nov 12 at 8:47
@ADDICE Yes. ForglBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(..., array)
,array
is the data array.
– Rabbid76
Nov 12 at 9:06
add a comment |
could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
– ADDICE
Nov 12 at 8:47
@ADDICE Yes. ForglBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(..., array)
,array
is the data array.
– Rabbid76
Nov 12 at 9:06
could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
– ADDICE
Nov 12 at 8:47
could i understand it like this. the positions and colors In this example, their element without offset, so i can send the array as glVertexAttribPointer(..., array)
– ADDICE
Nov 12 at 8:47
@ADDICE Yes. For
glBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(..., array)
, array
is the data array.– Rabbid76
Nov 12 at 9:06
@ADDICE Yes. For
glBindBuffer(GL_ARRAY_BUFFER, 0)
glVertexAttribPointer(..., array)
, array
is the data array.– Rabbid76
Nov 12 at 9:06
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53241857%2fcould-glvertexattribpointer-last-at-attribute-value-in-opengl-be-a-array%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown