Drawing a vertical line at cursor position

Hello!

I’m learning OpenGL so decided to make an application which draw plots. I decided to make a selection so found that drawing vertical line is slow.

I would like to draw a vertical line at a cursor’s position. The line moves as the cursor moves. The algorithm is:

1. Put data for 2 vertices (-1, 1, 0) and (-1, -1, 0) into array buffer for dynamic drawing.
2. Load shader which in fact just a white pixel.

loop:
	3. Catch mouse position.
	4. Update the coordinates of the vertieces.
	5. Bind the vertex array of the vertieces.
	6. Draw arrays in GL_LINES mode.
	7. Unbind.

The problem is that the line doesn’t stick to the cursor. It is drawn with some delay. For example if I select files in my file explorer I don’t see such delay of a selection rectangle so it sticks right to the cursor. I don’t see that in a real-time strategy game selecting unites. So here I don’t understand what slows down my application.

I removed everything leaving only drawing the line. Still there 214 lines. You can see the C code here.

If you decide to build it and launch, please notice that path to the shaders supposes the application to be launched from the root of the project.

I’ve found a possible solution of the issue. By default motion of a cursor is affected by scaling and acceleration. It is designated in the documentation of GLFW about GLFW_RAW_MOUSE_MOTION (unfortunately I can’t write a link due to forum’s rules). By now I got that it’s impossible to have a line sticked to a cursor. At least to a system cursor. Perhaps diving into the source code of glfw can give another conclusion.

Bottom line:
In order to draw a line which moves with a mouse you need to add the following code

    if (glfwRawMouseMotionSupported()) {
        glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
        glfwSetInputMode(window, GLFW_RAW_MOUSE_MOTION, GLFW_TRUE);
    } else {
        printf("glfwRawMouseMotionSupported is not\n");
    }

It disables drawing of a system cursor and disables acceleration and scaling of position of a cursor.

Glad you got it figured out. Here’s that link:

Re “can’t write a link”, just keep using the forums and those restrictions will evaporate on your account pretty quickly.