Drawing a line with Rust and OpenGL

Hello everyone,

Intro

I'm learning OpenGL with Rust so I've got a question rather about OpenGL than Rust. I'm not sure if the forum is the right place to ask for some help about graphics programming but I have no idea where I can ask for it as my code is a piece of Rust code. If you know where I can ask such question please tell me.

Subject

I'm trying to implement an application which accepts a bunch of points and draws a plot. I want to add an ability to select some range of a plot and zoom it. 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 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. So here I don't understand what slows down my application.

Sample

Code is here. I removed everything leaving only loading shaders, drawing the line and catching input events. I did my best to make the example as small as possible, but a "hello world" with OpenGL requires quite a big piece of code (200 lines in the case). I separated loading of shaders trying to prevent some distraction. I took crates gl and glfw.

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. 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 glfw.supports_raw_motion() {
        window.set_cursor_mode(glfw::CursorMode::Disabled);
        window.set_raw_mouse_motion(true);
    } else {
        println!("mouse raw motion is not supported");
    }

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

Thank you. Your problem was bizarre and kept me up one night.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.