C Graphics - Page Flipping

This is a discussion on C Graphics - Page Flipping within the C Programming forums, part of the General Programming Boards category; This is a simple code for page flipping in C. The problem is, it works on a friend's computer, but ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    5

    Unhappy C Graphics - Page Flipping

    This is a simple code for page flipping in C. The problem is, it works on a friend's computer, but not on mine. We both use the Turbo C++ compiler v3.0. The problem is that if 'i' is set to 0 inside the 'while (!kbhit())' loop, the Page 0 comes up and doesn't go. If 'i' is set to 1, 2, or 3, that page comes for a very short time (less than 1 second), and then Page 0 comes back and stays on the screen. How can I fix this problem?
    Code:
    #include <conio.h>
    #include <dos.h>
    #include <graphics.h>
    
    int main(void)
     {
         int     i;
    
          /* request auto detection */
         int gdriver = EGA, gmode = EGALO, errorcode;
    
         /* initialize graphics and local
         variables */
         initgraph(&gdriver, &gmode, "..\\bgi");
    
         /* read result of initialization */
         errorcode = graphresult();
         /* an error occurred */
         if (errorcode != grOk)
          {
              printf("Graphics error: %s\n", grapherrormsg(errorcode));
              printf("Press any key to halt:");
              getch();
              exit(1);    /* terminate with an error code */
          }
    
         /* setting the four pages available in EGALO mode */
         setactivepage(0);
         cleardevice();
         circle(1, 1, 100);
         outtextxy(200, 1, "Page 0");
    
         setactivepage(1);
         cleardevice();
         circle(getmaxx(), 1, 100);
         outtextxy(200, 1, "Page 1");
    
         setactivepage(2);
         cleardevice();
         circle(getmaxx(), getmaxy(), 100);
         outtextxy(200, 1, "Page 2");
    
         setactivepage(3);
         cleardevice();
         circle(1, getmaxy(), 100);
         outtextxy(200, 1, "Page 3");
    
         /* looping through the pages */
         while (!kbhit())
          {
              i = 0;
              setvisualpage(i);
              ++i;
              if (i == 4)
                   i = 0;
              delay(1000);
          }
    
         closegraph();
    
         return 0;
     }

    &#91;code]&#91;/code]tagged by Salem

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    14

    Re: C Graphics - Page Flipping


    /* looping through the pages */
    while (!kbhit())
    {
    i = 0;
    setvisualpage(i);
    ++i;
    if (i == 4)
    i = 0;
    delay(1000);
    }

    }
    solution :

    put the statement i=0 outside the loop.( before while)

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. why page based I/O can improve performance?
    By George2 in forum C Programming
    Replies: 1
    Last Post: 06-12-2006, 07:42 AM
  2. virtual memory
    By sweets in forum C Programming
    Replies: 6
    Last Post: 11-06-2004, 05:55 AM
  3. allegro help - page flipping?
    By MadHatter in forum Game Programming
    Replies: 2
    Last Post: 11-30-2002, 02:32 AM
  4. Page flipping
    By JoshG in forum Game Programming
    Replies: 8
    Last Post: 06-04-2002, 07:05 AM
  5. double buffering and page flipping question
    By stupid_mutt in forum C Programming
    Replies: 2
    Last Post: 01-30-2002, 12:50 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21