Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6769681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:13:20+00:00 2026-05-26T15:13:20+00:00

I am trying to animate random point that i have created so they move

  • 0

I am trying to animate random point that i have created so they move across the screen and re-appear this is what i have done so far but does not work.the code is not the completed version of what i have i have only posted what i thought would be enough for this question could anyone help me animated the points

void TimerFunc(int value)
{
  xpos[0]=xpos[0]+0.25;
  glutPostRedisplay(); 
  glutTimerFunc(25, TimerFunc, 1);
}
struct Point
{
  float rship;
};
std::vector< Point > points;
void display(void)
{

glClear (GL_COLOR_BUFFER_BIT);   /* clear window */
glColor3f(1.0, 1.0, 1.0);        /* white drawing objects */
/* define object to be drawn as a square polygon */   

//Draw points
glEnableClientState( GL_VERTEX_ARRAY );  
glVertexPointer( 2, GL_FLOAT, sizeof(Point), &points[0].x );   
glPointSize( 1 ); //1 pixel dot
glDrawArrays( GL_POINTS, 0, points.size() );
glDisableClientState( GL_VERTEX_ARRAY );
//glEnable( GL_POINT_SMOOTH );/*round smooth points*/
glFlush();     /* execute drawing commands in buffer */


}
int main(int argc, char** argv)
for( int i = 0; i <250; ++i )
{
    Point pt;
    pt.x = -100 + (rand() % 200);
    pt.y = -100 + (rand() % 200);
    points.push_back(pt);
    xpos[i] = pt.x;
    ypos[i] = pt.y;

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:13:21+00:00Added an answer on May 26, 2026 at 3:13 pm

    Quick ‘n dirty:

    #include <GL/glut.h>
    #include <vector>
    #include <cstdlib>
    
    struct Point
    {
        float x, y;
        unsigned char r, g, b, a;
    };
    std::vector< Point > points;
    
    void timer( int value )
    {
        // move all points left each frame
        for( size_t i = 0; i < points.size(); ++i )
        {
            points[i].x -= 1;
    
            // wrap point around if it's moved off
            // the edge of our 100x100 area
            if( points[i].x < -50 )
            {
                points[i].x = 100 + points[i].x;
            }
        }
    
        glutPostRedisplay();
        glutTimerFunc(30, timer, 1);
    }
    
    void display(void)
    {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(-50, 50, -50, 50, -1, 1);
    
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    
        // draw
        glColor3ub( 255, 255, 255 );
        glEnableClientState( GL_VERTEX_ARRAY );
        glEnableClientState( GL_COLOR_ARRAY );
        glVertexPointer( 2, GL_FLOAT, sizeof(Point), &points[0].x );
        glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(Point), &points[0].r );
        glPointSize( 3.0 );
        glDrawArrays( GL_POINTS, 0, points.size() );
        glDisableClientState( GL_VERTEX_ARRAY );
        glDisableClientState( GL_COLOR_ARRAY );
    
        glFlush();
        glutSwapBuffers();
    }
    
    void reshape(int w, int h)
    {
        glViewport(0, 0, w, h);
    }
    
    int main(int argc, char **argv)
    {
        glutInit(&argc, argv);
        glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);
    
        glutInitWindowSize(640,480);
        glutCreateWindow("Scrolling Points");
    
        glutDisplayFunc(display);
        glutReshapeFunc(reshape);
        glutTimerFunc(30, timer, 1);
    
         // populate points
        for( size_t i = 0; i < 1000; ++i )
        {
            Point pt;
            pt.x = -50 + (rand() % 100);
            pt.y = -50 + (rand() % 100);
            pt.r = rand() % 255;
            pt.g = rand() % 255;
            pt.b = rand() % 255;
            pt.a = 255;
            points.push_back(pt);
        }    
    
        glutMainLoop();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to animate a UIButton to move up the screen. At any point
I am trying to animate a couple of images across a screen. Ideally I
I'm trying to animate a sequence of images and this could easily be done
I am trying to animate a label across the screen however I cannot seem
I'm trying to animate a UIButton to move randomly around the screen in different
i'm trying to animate an object in several steps across the screen until it
I'm trying to animate a dot from one point to another on a map.
I'm trying to animate a chess piece in a board. First I created a
I'm trying to animate a background image to move down a set amount of
I'm trying to animate something using jQuery. UPDATE I have it working the way

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.