Results 1 to 2 of 2

Thread: animation

  1. #1


    I've been working with OpenGL off and on and I needed a program to read my data files and display them on the screen. I do have one that was fixed by someone in this help forum and I've been using that so far.
    I now need the code to work on any number of files by reading the images one at a time instead of loading them into an array and then reading them out. I was told by someone that all I needed was space for one image and I could use that to cycle through my data files and display them on the screen. The program does display something but there's a lot of flickering and you can't see anything at all.
    If someone could point out what is wrong, I would be very grateful. Here's the code for the animation display.

    /* Movie player: plays movies with an indeterminate number of files */

    #include <stdio.h>
    #include <stdlib.h>

    #include <GL/glut.h>

    GLint counter = 0;
    GLuint *image;
    GLfloat s;

    GLint n = 296;
    GLint m = 128;
    GLint k = 255;

    void myidle()

    fprintf(stderr, "counter is %d\n", counter );


    void display()
    glRasterPos2i(0, 0);
    glDrawPixels(n, m, GL_RGB, GL_UNSIGNED_INT, image);

    void bitmap()
    FILE *fd;
    int k, nm;
    int one;
    char filename1[20];
    int i;
    int red, green, blue;

    fprintf(stderr,"counter is %d\n", counter );
    nm = n*m;
    sprintf(filename1,"nldat/%05d.dat", counter );
    while ( ( fd = fopen( filename1, "r") ) != NULL ) {

    image = malloc(3*sizeof(GLuint)*nm);

    s = 255./k;

    for(i = 0; i < nm; i++)
    fscanf(fd, "%d\n", &one );
    red = one;
    blue = one;
    green = one;
    image[3*i + 3] = red;
    image[3*i + 2] = green;
    image[3*i + 1] = blue;

    void myreshape(int h, int w)
    gluOrtho2D(0.0, (GLfloat) n, 0.0, (GLfloat) m);
    glViewport(0, 0, h, w);

    int main(int argc, char **argv)

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(n, m);
    glutInitWindowPosition(0, 0);
    glPixelTransferf(GL_RED_SCALE, s);
    glPixelTransferf(GL_GREEN_SCALE, s);
    glPixelTransferf(GL_BLUE_SCALE, s);
    glClearColor(1.0, 1.0, 1.0, 1.0);
    return 0;

    Thanks a lot in advance.

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Gastonia, NC, USA

    Re: animation

    To help the flickering, do not keep updating the screen in your idle function until you are ready to load a new file.


    int new_image;

    new_image = FALSE;

    // If you want the images to load automatically, then maybe a time function.
    if( (current_time - past_time) > delay_time); // Where delay_time is the amount of time to pass before loading image.
    new_image = TRUE;
    past_time = current_time; // reset timmer

    if(newimage = true) glutPostRedisplay(); We only draw to the screen if the image has changed.

    [This message has been edited by nexusone (edited 08-26-2002).]

    [This message has been edited by nexusone (edited 08-26-2002).]

Similar Threads

  1. Help with an animation
    By Eztlicoatl in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 10-03-2015, 06:03 PM
  2. Animation name
    By Vespa in forum COLLADA
    Replies: 1
    Last Post: 10-14-2009, 04:51 AM
  3. Sprite Animation / Texture Animation
    By Rodrix in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 03-11-2007, 10:36 PM
  4. How to do Animation
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 07-13-2003, 04:41 AM
  5. 3D animation
    By Alhek in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-20-2003, 11:09 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