Results 1 to 8 of 8

Thread: Pause after GL_LINE_STRIP

  1. #1
    Guest

    Pause after GL_LINE_STRIP

    Hi,
    I am new to OpenGL. I am working on a project where I need to read data from a input file, store coordinates in an array and then draw the image by using GL_LINE_STRIP and coordinates in the array. I also need to pause after each line is drawn so you can see the image being rendered line by line with about 0.3 second pause after each line.

    I have everything finished, the problem I have is with the whole animation of lines. It hangs for a while and then draws the whole image at once, without any delay after each line.

    Code :
    void main(int argc, char** argv)
    {
       	PromptFileName();
    	CreateArray();
    	ReadData();
     
        init_window(argc,argv);
        other_init(); 
     
        glutMainLoop();             
    }
    Code :
    void init_window(int argc, char** argv)
    {
        glutInit(&argc,argv);
    	glutInitDisplayMode (GLUT_RGB); 
    	glutInitWindowSize(500,400); 
    	glutInitWindowPosition(0,0); 
    	glutCreateWindow("2A"); 
    }
    Code :
    void other_init()
    {
    	glClearColor(1.0, 1.0, 1.0, 1.0);    
        glColor3d(0.0,0.0,0.0);			    
    	glMatrixMode(GL_PROJECTION);
    	glLoadIdentity();
    	glOrtho(-2026.0, 2026.0, -2026.0, 2026.0, -1.0, 1.0);
    	glMatrixMode(GL_MODELVIEW);
     
        glutDisplayFunc(display); 
        glutKeyboardFunc(keyboard);
    }
    Code :
    void display(void)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glClearColor(1.0, 0.0, 1.0, 1.0);
    	glClear(GL_COLOR_BUFFER_BIT);	
     
        for (int i=0; i<arraySize; i++){
            sleep( (clock_t) (0.3 * CLOCKS_PER_SEC ));
     
            glColor3f(i/10.0, 1.0, 0.0);      
    //arrayPtr has the coordinates
            if (arrayPtr[i][3] == 1)    // if this row is marked as jump
            {
                if (i != 0)
                    glEnd();
                glBegin(GL_LINE_STRIP);
            }
            // draw a line strip
            glVertex3f(arrayPtr[i][0], arrayPtr[i][1], 0.0);
     
            glFlush();                      // clear buffers
            sleep( (clock_t) (0.3 * CLOCKS_PER_SEC ));
     
        }
     
        glEnd();
        glFlush();
    }
    Thank you.
    -Tom

  2. #2
    Member Newbie
    Join Date
    Jan 2002
    Location
    Steamboat Springs, CO, USA
    Posts
    43

    Re: Pause after GL_LINE_STRIP

    It's illegal to call glFlush between glBegin/glEnd.

    You'll need to draw the line segments one at a time with glBegin(GL_LINE_STRIP);glVertex3f();glVertex3f();g lEnd() then sleep().

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Pause after GL_LINE_STRIP

    don't sleep when rendering. sleep before or after. Otherwise it's just like kicking in the air...

  4. #4
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,107

    Re: Pause after GL_LINE_STRIP

    If you do not use double buffering, then you will have to use just GL_LINES and draw one line at a time, so glBegin/glVertex/glVertex/glEnd/sleep.

    If you use double buffering, then you should draw entire line loop from beginning to current segment and call swapBuffers each time.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: Pause after GL_LINE_STRIP

    i guess the sleep function you are using is the one from unistd.h? in that case, the function takes only integers as arguments, and it is not possible to sleep for a fraction of a second.

    you better try usleep. usleep takes an unsigned long argument, which is the number of microseconds. if you want a delay of 0.3 seconds, you need usleep(300000).

  6. #6
    Senior Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: Pause after GL_LINE_STRIP

    Maybe he's using this sleep example from the MSDN
    http://msdn.microsoft.com/library/de..._crt_clock.asp

  7. #7
    Senior Member Frequent Contributor plasmonster's Avatar
    Join Date
    Mar 2004
    Posts
    739

    Re: Pause after GL_LINE_STRIP

    There's a gem of a function in OpenGL called glGetError. If you place one of these calls after all significant blocks of GL code, you'll have a real time saver in tracking down problems like this one. The errors themselves are pigeonholed into a handful of enums, but they'll sure help you to confine your search. Look at gluErrorString (in glu.h) for a displayable string version of the enum returned by glGetError.

    http://www.mevis.de/opengl/glGetError.html
    http://www.mevis.de/opengl/gluErrorString.html

  8. #8
    Guest

    Re: Pause after GL_LINE_STRIP

    Thank you all for your help.
    Actually you are correct, I was using that sleep method. But now I am using the "Sleep(DWORD ms)" method from <windows.h>.

    And my problem was trying to use glFlush() inside glBegin(...) and glEnd(). After I moved glFlush() after glEnd(), everything is working fine.

    Thanks again.
    -Tom

Similar Threads

  1. From GL_LINE_STRIP to VBO/VAOs ?
    By techwinder in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-14-2016, 10:48 AM
  2. Pause the glutMainLoop
    By Diego Felix in forum OpenGL: General
    Replies: 6
    Last Post: 07-24-2011, 03:32 AM
  3. Pause commando
    By globalace in forum OpenGL: Windows
    Replies: 1
    Last Post: 03-14-2010, 03:10 PM
  4. GL_POINT, GL_LINE_STRIP
    By devdept in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 01-02-2008, 03:22 AM
  5. best place to pause cpu
    By zed in forum OpenGL: Advanced Coding
    Replies: 9
    Last Post: 02-13-2005, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean