Note that there are some explanatory texts on larger screens.

plurals
  1. POGLKit: [drawing pixels] initializing GLfloat array
    primarykey
    data
    text
    <p>I am drawing a pixel using GLKit. I can successfully draw the pixel at (10, 10) coordinates if I have:</p> <pre><code>glClearColor(0.65f, 0.65f, 0.65f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Prepare the effect for rendering [self.effect prepareToDraw]; GLfloat points[] = { 10.0f, 10.0f, }; glClearColor(1.0f, 1.0f, 0.0f, 1.0f); GLuint bufferObjectNameArray; glGenBuffers(1, &amp;bufferObjectNameArray); glBindBuffer(GL_ARRAY_BUFFER, bufferObjectNameArray); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer( GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 2*4, NULL); glDrawArrays(GL_POINTS, 0, 1); </code></pre> <p>But I want to decide at runtime how many and exactly where I want to draw pixels, so I tried this but it is drawing pixel at (10, 0), something's wrong here:</p> <pre><code>glClearColor(0.65f, 0.65f, 0.65f, 1.0f); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Prepare the effect for rendering [self.effect prepareToDraw]; GLfloat *points = (GLfloat*)malloc(sizeof(GLfloat) * 2); for (int i=0; i&lt;2; i++) { points[i] = 10.0f; } glClearColor(1.0f, 1.0f, 0.0f, 1.0f); GLuint bufferObjectNameArray; glGenBuffers(1, &amp;bufferObjectNameArray); glBindBuffer(GL_ARRAY_BUFFER, bufferObjectNameArray); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW); glEnableVertexAttribArray(GLKVertexAttribPosition); glVertexAttribPointer( GLKVertexAttribPosition, 2, GL_FLOAT, GL_FALSE, 2*4, NULL); glDrawArrays(GL_POINTS, 0, 1); </code></pre> <p>Kindly help me out.</p> <p>Edit: <strong>Problem</strong> Actually the problem is: I can't figure out what is the difference between:</p> <pre><code>GLfloat points[] = { 10.0f, 10.0f, }; </code></pre> <p>AND</p> <pre><code>GLfloat *points = (GLfloat*)malloc(sizeof(GLfloat) * 2); for (int i=0; i&lt;2; i++) { points[i] = 10.0f; } </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.
    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