1

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.

J.Doe
  • 17
  • 6
  • That is an interesting tangent. I’ll try it and see if it changes the way the triangles are drawn. Would I expect it change the display of points? Not really. A few years ago I wrote a OSX application using OpenGL to do a pricipal components analysis, and was able to easily display the original points, mean-centered points, standardized points, and the scores from the analysis. I put together some WebGL stuff, as well. Simply displaying four points should be simple. – J.Doe Feb 27 '18 at 13:48
  • Rabbid76, I changed my code to rotate my data around the y-axis so I could see both sides of the polygons. However, when I added the glPolygonMode command, I received the error “Implicit declaration of function ‘glPolygonMode’ is invalid in C99’ - did you suspect this? As well, earlier when I tried to glEnable(Gl_POINT_SIZE), I get “Use of undeclared identifier...” I import GLKit.h, ES2/gl.h, ES2/glext.h – J.Doe Feb 27 '18 at 14:52
  • Changed my EAGLContext to OpenGLES3, but no improvement. – J.Doe Feb 27 '18 at 22:02
  • Went back to some WebGL lessons I worked through some years ago, and drawArrays with gl_points works as expected. The only solution I can find for this question seems to be to draw a quad and discard fragments beyond .5* length of side of quad. Sure would be interested in knowing that this was not necessary if it is not necessary. Thanks Rabbid, for chiming in, because without you this would have been a very lonely experience. – J.Doe Mar 01 '18 at 02:41
  • Oh, one last thought, I have not implemented this yet, but it strikes me as a two-dimensional solution to a three-dimensional problem. Going to be interesting to see this round point spin on its axis. A cube with six faces like this will probably not look like a sphere, but more like a transparent box with spots on its sides. Strangely, for the app I want to do, looking at linear algebra, I don’t need points, so this exploration is purely academic. – J.Doe Mar 01 '18 at 16:22

0 Answers0