I have tried many different things, but I have the impression that this is all that I need to do to generate points instead of lines or triangles. The uncommented glDrawElements works, the commented commands to set line width and draw just lines works, but trying to draw the points does not. Is there something I am missing? Is drawing a point really this simple or does a texture have to be bound to the point?
I can provide setup of GL, and the shaders if desired, but my first question is simply ... if the lines and triangles work, should the points?
/////////////////////////////////////////////////////////////
- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect {
glClearColor(0.0, 0.0, 0.0, _alpha);
glClear(GL_COLOR_BUFFER_BIT);
[self.effect prepareToDraw];
glBindBuffer(GL_ARRAY_BUFFER, _vertexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _indexBuffer);
glEnableVertexAttribArray(GLKVertexAttribPosition);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Position));
glEnableVertexAttribArray(GLKVertexAttribColor);
glVertexAttribPointer(GLKVertexAttribColor, 4, GL_FLOAT, GL_FALSE,
sizeof(Vertex), (const GLvoid *) offsetof(Vertex, Color));
glDrawElements(GL_TRIANGLES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);
//glLineWidth(10.0);
//glDrawElements(GL_LINES, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);
//glDrawElements(GL_POINTS, sizeof(Indices)/sizeof(Indices[0]), GL_UNSIGNED_BYTE, 0);
}
//////////////////////////////////////////////////////////////////
// fragment shader
varying lowp vec4 DestinationColor; // 1
void main(void) { // 2
gl_FragColor = DestinationColor; // 3
}
////////////////////////////////////////////////////////
// vertex shader
attribute vec4 Position; // 1
attribute vec4 SourceColor; // 2
varying vec4 DestinationColor; // 3
void main(void) { // 4
DestinationColor = SourceColor; // 5
gl_Position = Position; // 6
gl_PointSize = 10.0;
}
//////////////////////////////////////////////////////////
Edit: I changed my vertex array to include a ‘w’ value of ‘1’ (x,y,z,w) because points need the ‘w’ but it changed nothing. I had assumed glDrawElements and the shader program would use ‘1’ if the value was not included, and I guess I still assume that. Edit2: I realized that my vertices are from an example from Ray Wenderlich, and are for making a triangle, and the vertices are 1,1,0; -1,-1,0; and the like. Going to try to spread out my points and see if that does anything. Can you have a point size of 10.0 when the vertices range from -1 to 1? Edit3: I knew that wouldn’t do anything. If a line width of 10 is legitimate, of course a point size of 10 is, as well. But still, I did change the vertices to 100, -100, etc., and translated myself way out the z-axis to be able to see it all, to no avail.