Allegro getting choppy

closed account (GbX36Up4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#include <allegro.h>

int makerect(int selectedcolor, int a, int b, int c, int d);

int main()
{
  allegro_init();
  install_mouse();
  install_keyboard();
  set_color_depth(32);
  
  set_gfx_mode(GFX_AUTODETECT_WINDOWED, 900, 600, 0, 0);  
  clear_to_color( screen, makecol( 255, 255, 255));
  
  show_mouse(screen);
  
  int i;
  int s;
  int f = 16;
  int l;
  int cursor_x;
  int cursor_y;
  int selectedcolor;
  int a, b, c, d;
  
  while(! key [KEY_ESC]){
  rest(5);
          
          
          
  
  show_mouse(screen);
  acquire_screen();   
  line( screen, 640, 600, 640, 0, makecol( 55, 55, 150));
  release_screen();

                   
                  while(f<=(16*40)){
                     for(s=16*3;s<=(16*37);s=s+16){
                                            for(l=16*4;l<=(16*37);l=l+16){
                                                   acquire_screen();                  
                                                   rect(screen, 0, s, f, l, makecol( 0, 0, 255));
                                                   release_screen();                     
                                                                          }
                                                     
                     }
                     f=f+16;
                     }
                     
                     

          acquire_screen();
          rect( screen, 660, 64, (660+(64*3)), (64*4), makecol( 0, 0, 255));
          
          rectfill(screen, (660), (64*5), (660+64), (64*6), makecol( 255, 0, 0)); // color 1
          rectfill(screen, (660+64), (64*5), (660+64*2), (64*6), makecol( 0, 255, 0)); // color 2
          rectfill(screen, (660+64*2), (64*5), (660+64*3), (64*6), makecol( 0, 0, 255)); // color 3
          
          rectfill(screen, 660, (64*6), (660+64), (64*7), makecol( 255, 0, 255)); // color 4
          rectfill(screen, (660+64), (64*6), (660+64*2), (64*7), makecol( 0, 255, 255)); // color 5
          rectfill(screen, (660+64*2), (64*6), (660+64*3), (64*7), makecol( 255, 255, 0)); // color 6
          
          rectfill(screen, 660, (64*7), (660+64), (64*8), makecol( 50, 255, 150)); // color 7
          rectfill(screen, (660+64), (64*7), (660+64*2), (64*8), makecol( 0, 0, 0)); // color 8
          rectfill(screen, (660+64*2), (64*7), (660+64*3), (64*8), makecol( 100, 50, 200)); // color 9
          release_screen();
          if(mouse_b & 1){
                     cursor_x = mouse_x;
                     cursor_y = mouse_y;  
                     if(cursor_x >= 660 && cursor_x <= (660+64)){
                                 if(cursor_y >= (64*5) && cursor_y <= (64*6)){
                                  selectedcolor = 1;
                                  acquire_screen();
                                  rectfill(screen, 660, 64, (660+(64*3)), (64*4), makecol( 255, 0, 0));
                                  release_screen();
                                 }
                     }
                     
                     if(cursor_x >= (660+64) && cursor_x <= (660+64*2)){
                                 if(cursor_y >= (64*5) && cursor_y <= (64*6)){
                                  selectedcolor = 2;
                                 }
                     }
                     
                     if(cursor_x >= (660+64*2) && cursor_x <= (660+64*3)){
                                 if(cursor_y >= (64*5) && cursor_y <= (64*6)){
                                  selectedcolor = 3;
                                 }
                     }
                     
                     if(cursor_x >= 660 && cursor_x <= (660+64)){
                                 if(cursor_y >= (64*6) && cursor_y <= (64*7)){
                                  selectedcolor = 4;
                                 }
                     }
                     
                     if(cursor_x >= (660+64) && cursor_x <= (660+64*2)){
                                 if(cursor_y >= (64*6) && cursor_y <= (64*7)){
                                  selectedcolor = 5;
                                 }
                     }
                     
                     if(cursor_x >= (660+64*2) && cursor_x <= (660+64*3)){
                                 if(cursor_y >= (64*6) && cursor_y <= (64*7)){
                                  selectedcolor = 6;
                                 }
                     }
                     
                     if(cursor_x >= 660 && cursor_x <= (660+64)){
                                 if(cursor_y >= (64*7) && cursor_y <= (64*8)){
                                  selectedcolor = 7;
                                 }
                     }
                     
                     if(cursor_x >= (660+64) && cursor_x <= (660+64*2)){
                                 if(cursor_y >= (64*7) && cursor_y <= (64*8)){
                                  selectedcolor = 8;
                                 }
                     }
                     
                     if(cursor_x >= (660+64*2) && cursor_x <= (660+64*3)){
                                 if(cursor_y >= (64*7) && cursor_y <= (64*8)){
                                  selectedcolor = 9;
                                 }
                     }
                     
                     
                     if(cursor_x >= 0 && cursor_x <= 64 && selectedcolor != 0){
                                 if(cursor_y >= 64 && cursor_y <= (64*2)){
                                             a=0;
                                             b=64;
                                             c=64;
                                             d=(64*2);
                                            makerect(selectedcolor, a, b, c, d);         
                                 }            
                     }
          
          }
          
          
      }
}



END_OF_MAIN ()


int makerect(int selectedcolor, int a, int b, int c, int d){
    if(selectedcolor == 1){
                     acquire_screen();
                     rectfill(screen, a, b, c, d, makecol(255, 0, 0));   
                     release_screen();              
    }   
}


When it is run it works fine but it looks weird, almost like each time it refreshes you can see where it is changing. You may need to run it to see
what i'm talking about.

1
2
3
4
5
6
7
8
9
10
11
while(f<=(16*40)){
                     for(s=16*3;s<=(16*37);s=s+16){
                                            for(l=16*4;l<=(16*37);l=l+16){
                                                   acquire_screen();                  
                                                   rect(screen, 0, s, f, l, makecol( 0, 0, 255));
                                                   release_screen();                     
                                                                          }
                                                     
                     }
                     f=f+16;
                     }


It appears to be in the above area because when I use a goto loop instead of a while loop it doesn't look weird but the grid goes father than it is supposed to. I also tried a for loop and a do while loop instead of the while loop. While
using the for loop it stops when it is supposed to and doesn't look weird but it won't take in any input. Any help?
2 things:

this is a c++ board, not an allegro programming board. You can ask questions about your allegro program if you think your problems pertain to general c++ programming instead of an allegro specific issue.

I've been programming with allegro for a little while, and I've never used acquire_screen or release_screen. A game programming book that uses allegro that I use states that those 2 functions are for specific bitmap related functionality. I don't know what show_mouse does.
Last edited on
closed account (GbX36Up4)
acquire_screen(); must be called before drawing to the screen and release_screen(); after
show_mouse(); just helps with using mouse input and such things. I got my problem fixed.
I simply got rid of the for loop using s and used (l-16) in its place.
Topic archived. No new replies allowed.