1
\$\begingroup\$

So, in order to draw a line, I track the coordinates of the mouse, then I add them to the array and capture it as GL_LINE_STRIP_ADJACENCY. However, for example, I completed drawing a line1 at P1 and decided to start drawing a different line at P2 as shown in the figure, but my two points P1 and P2 joined together, how to fix it? Need to clear the array after drawing at the point P1, actually it doesn't help if I use glClearColor and glClear(GL_COLOR_BUFFER_BIT).. Is there any other way?

enter image description here

\$\endgroup\$
0
\$\begingroup\$

It seems like you're drawing both lines with only one primitive by accumulating vertices frame-by-frame tracked from the mouse position. To fix it, when you're done drawing one line(you release mouse button and press again), you should create another primitive and start accumulating vertices inside it. enter image description here

\$\endgroup\$
  • \$\begingroup\$ Ok, so, to create new primitive I need create new VBO and VAO, yep? And render in scope 1 frame my old buffer with vertices that present first primitive and new buffer with new vertices, yes? And what if i need draw 100 primitives, I need every time do it?? \$\endgroup\$ – adziri Oct 19 '18 at 7:54
  • \$\begingroup\$ @Azazel-San, that's right. But if you want more efficient way of handling this, you should only re-draw window when needed, or completely switch to the way of handling things just like every image-editing software does: that is, do it in raster. Have a big framebuffer where you draw your lines once and then display the framebuffer itself. \$\endgroup\$ – Ocelot Oct 19 '18 at 8:05
  • \$\begingroup\$ about framebuffers, its glGenFramebuffers/glGenTextures/glGenRenderbuffers ? \$\endgroup\$ – adziri Oct 19 '18 at 8:15
  • \$\begingroup\$ @Azazel-San, that a whole new question. You can find alot of information about framebuffers on the web. An OpenGL wiki page would explain framebuffers better than me: khronos.org/opengl/wiki/Framebuffer \$\endgroup\$ – Ocelot Oct 19 '18 at 8:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.