Note that there are some explanatory texts on larger screens.

plurals
  1. POAssist me to understand OpenGL glGenBuffers
    primarykey
    data
    text
    <p>Here is the deal. If I leave the code with glGenBuffers(1, vertexBuffers), the code compiles are works. But, I thought that it should be 2 since vertexBuffers is of size two. </p> <p>Am I missing something? </p> <p>Code below:</p> <pre><code>-(void)drawRect:(NSRect)dirtyRect { // get program ID for shader program GLuint programID = [self loadShaders]; // get new dimensions NSSize dim = [self frame].size; // clear the background with color glClearColor(0.0, 0.0, 0.0, 0.4); glDepthRange(0.1, 100.0); glViewport(0, 0, dim.width, dim.height); glClear(GL_COLOR_BUFFER_BIT); // vertex data GLfloat vertexPositionData[] = {-dim.width/2, -dim.height/2, 0.0, 5.0, dim.width/2, -dim.height/2, 0.0, 5.0, 0.0, dim.height/2, 0.0, 5.0}; GLfloat vertexColorData[] = {1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.5, 0.0, 0.0, 1.0, 0.5}; GLfloat scaleMatrixData[] = {1/(dim.width/2), 0.0, 0.0, 0.0, 0.0, 1/(dim.height/2), 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0}; GLint scaleMatrixUniform = glGetUniformLocation(programID, "scaleMatrix"); // generate a buffer for our triangle glGenBuffers(1, vertexBuffers); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(vertexPositionData), vertexPositionData, GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[1]); glBufferData(GL_ARRAY_BUFFER, sizeof(vertexColorData), vertexColorData, GL_STATIC_DRAW); //glBindBuffer(GL_ARRAY_BUFFER, 0); glUseProgram(programID); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[0]); glEnableVertexAttribArray(VERTEX_POS_INDEX); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffers[1]); glEnableVertexAttribArray(VERTEX_COLOR_INDEX); glVertexAttribPointer(VERTEX_POS_INDEX, VERTEX_POS_SIZE, GL_FLOAT, GL_FALSE, 0, vertexPositionData); glVertexAttribPointer(VERTEX_COLOR_INDEX, VERTEX_COLOR_SIZE, GL_FLOAT, GL_FALSE, 0, vertexColorData); glUniformMatrix4fv(scaleMatrixUniform, 1, GL_FALSE, scaleMatrixData); glDrawArrays(GL_TRIANGLES, 0, 3); glDisableVertexAttribArray(0); glDisableVertexAttribArray(1); glUseProgram(0); // flush buffer glFlush(); [[self openGLContext] flushBuffer]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload