| |

VerySource

 Forgot password?
 Register
Search
View: 1470|Reply: 3

How to use OpenGL to draw continuous lines one by one? (Similar to drawing lines as the mouse moves)

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-19 01:00:01
| Show all posts |Read mode
void __fastcall TFormMain :: RenderGLScene ()
{
    glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    DrawObjects ();
    glFlush ();
}
void __fastcall TFormMain :: DrawObjects ()
{
   glBegin (GL_LINE_STRIP);
   glColor3f (1.0f, 0.0f, 0.0f); // Set the current color to red
   glVertex3f (0.0f, 0.0f, 0.0f);
   glVertex3f (0.0f, X, 0.0f); // X is a changed value, which is read in from outside through RS232
   glEnd ();
}
With the above method, there is always a straight line from 0, 0, 0 to the latest X value, how to achieve a little bit of connection, rather than the connection from the first point to the last point.
The effect I need is similar to that in the drawing software, as the mouse moves, it follows the line.
In addition, if you do not use glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); how to eliminate flicker?
Reply

Use magic Report

0

Threads

13

Posts

12.00

Credits

Newbie

Rank: 1

Credits
12.00

 China

Post time: 2020-7-12 13:45:01
| Show all posts
I don’t use it much, and I haven’t touched functions like LineTo. However, you can have multiple points between glBegin() and glEnd().

If you use a vector<float> pts to store multiple points, once RS232 has data to read, it is in push_back(X). Then call DrawObjects()

   glBegin(GL_LINE_STRIP);
   for(int i=0;i<pts.size();i++)
   {
       glVertex3f(0.0f,pts[i],0.0f);
   }
   glEnd();
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-9-6 19:30:01
| Show all posts
I wrote according to the code on the 1st floor, and the drawing is a fan shape, but the line is quite continuous
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-9-6 19:45:01
| Show all posts
My code is as follows:
glBegin(GL_LINE_STRIP);
for(int i=m_uVertexNum;i <m_vVerter.size()-2;++i)
{
glVertex2f(m_vVerter[i].x,m_vVerter[i].y);
To
        }
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list