Results 1 to 3 of 3

Thread: Drawing points before drawing a curve line

  1. #1
    Newbie Newbie
    Join Date
    Feb 2017
    Posts
    4

    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

    Code :
    void mouseButtonCallback(GLFWwindow* _window, int button, int action, int mods)
    {
    	switch (button)
    	{
    	case GLFW_MOUSE_BUTTON_LEFT:
    		if (action == GLFW_RELEASE)
    		{
    			if (transitionalFlag == false) {
     
     
    				glfwGetCursorPos(window, &x, &y);
    				setPositionVector(x, y);
    				pointsClickedByUser.push_back(positionsClickedByUser);
    			}
    			else {
     
    				glfwGetCursorPos(window, &x, &y);
    				setPositionVector(x, y);
    				pointsClickedByUserTranslational.push_back(positionsClickedByUser);
    			}
     
    		}
     
    	}

    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

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2016
    Posts
    477
    Quote Originally Posted by PepeBeef View Post
    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.
    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);

  3. #3
    Newbie Newbie
    Join Date
    Feb 2017
    Posts
    4
    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 ) :

    Code :
    [....]
     
            vector<GLfloat> vectorOfVertices = vectorsToFloat(pointsClickedByUser);
    	//Initialize vertex buffer object
    	glGenBuffers(1, &VBO);
    	glGenVertexArrays(1, &VAO);
     
    	//Bind the vertex array object, then the VBO
    	glBindVertexArray(VAO);
     
    	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);
    	glEnableVertexAttribArray(0);
     
    	//Release the VAO and VBO
    	glBindBuffer(GL_ARRAY_BUFFER, 0);
    	glBindVertexArray(0);
     
     
    	while (!glfwWindowShouldClose(window)) {
     
    		glfwPollEvents();
     
     
     
    		glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
    		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
     
     
    		glUseProgram(shader_program);
     
    		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));
     
    		glBindVertexArray(VAO);
     
    		if (flag == true) {
    			glDrawArrays(GL_POINTS, 0, vectorOfVertices.size() / 3);
     
    		}
    		//swap the screen buffers
    		glfwSwapBuffers(window);
    	}

Similar Threads

  1. Drawing a curve over a curved surface
    By arennuit in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 02-06-2018, 03:16 AM
  2. Drawing 3D curve with varying width
    By esapir in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 04-24-2014, 06:24 PM
  3. Drawing Koch's curve
    By Infty in forum OpenGL: General
    Replies: 5
    Last Post: 05-24-2011, 01:21 AM
  4. One more on nurbs... drawing curve interactively.
    By BigShooter in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 11-04-2003, 09:58 AM
  5. How to get 3d coords from mouse clicks - drawing a curve...
    By BigShooter in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 10-31-2003, 01:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean