Drawing points before drawing a curve line

Hey guys,

So I’m trying to accomplish the following: draw a point on a mouse click. However, that doesn’t seem so complicated, but I need to “keep” those points on the screen and then draw a spline from those points. So for instance I have the following

void mouseButtonCallback(GLFWwindow* _window, int button, int action, int mods)
	switch (button)
		if (action == GLFW_RELEASE)
			if (transitionalFlag == false) {
				glfwGetCursorPos(window, &x, &y);
				setPositionVector(x, y);
			else {
				glfwGetCursorPos(window, &x, &y);
				setPositionVector(x, y);

Note: the If statement is because one of the line taken in is on the X-Y plane and the other on the X-Z plane ( doing a translational sweep with 2 spline selected by the user)

So, From those points , I have to save it into a vector and eventually put it in a VBO to be drawn, right? My question is this: How would I bind a VAO/VBO to allow points to be drawn and spline afterwards. Would it be with an if statement and what not? I’m rather new at this and drawing two “different” ( different because one is a point and the other is a line) objects is throwing me off.

What I was thinking was that I could create a variable GLfloat point_pos[3]; and always just give it to one vao and then draw it. However, how would I then bind my spline?

I don’t really know if I’m making sense, correct me wherever I’m wrong!

Thank you

you use the same VAO / VBO for both, spline drawing and points drawing
what you need to do is to call “glDrawArrays(…)” twice, one time for points …

glDrawArrays(GL_POINTS, offsetpoints, countpoints);

… and another time for the approximated spline …

glDrawArrays(GL_LINE_STRIP, offsetspline, countspline);

Wouldn’t that create an issue because my vector is empty from the get-go? and data keeps being fed into it every time a user clicks onto the screen? If I had a predefined vector it would be easier for me ( I mean, I’ve done a few exercise like that). However, it seems as if I Bind my buffer and send it to the gpu I get weird errors all along the way.

I mean something like this ( don’t mind the code, it’s just practice :slight_smile: ) :


        vector<GLfloat> vectorOfVertices = vectorsToFloat(pointsClickedByUser);
	//Initialize vertex buffer object
	glGenBuffers(1, &VBO);
	glGenVertexArrays(1, &VAO);

	//Bind the vertex array object, then the VBO

	glBindBuffer(GL_ARRAY_BUFFER, VBO);
	glBufferData(GL_ARRAY_BUFFER, sizeof(GLfloat) * vectorOfVertices.size(), &(vectorOfVertices[0]), GL_STATIC_DRAW);

	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), (GLvoid*)0);

	//Release the VAO and VBO
	glBindBuffer(GL_ARRAY_BUFFER, 0);

	while (!glfwWindowShouldClose(window)) {


		glClearColor(1.0f, 1.0f, 1.0f, 1.0f);

		glUniformMatrix4fv(modelMatrixLocation, 1, GL_FALSE, glm::value_ptr(modelMatrix));
		glUniformMatrix4fv(viewMatrixLocation, 1, GL_FALSE, glm::value_ptr(viewMatrix));
		glUniformMatrix4fv(projectionMatrixLocation, 1, GL_FALSE, glm::value_ptr(projectionMatrix));


		if (flag == true) {
			glDrawArrays(GL_POINTS, 0, vectorOfVertices.size() / 3);
		//swap the screen buffers