![]() |
|
Blank Screen |
agonvs
Member #15,917
March 2015
|
Hi all, I'm getting nothing but a white screen here (although the music plays fine). It won't even clear to black. What am I doing wrong? 1#include<allegro5/allegro.h>
2#include<allegro5/allegro_primitives.h>
3#include<allegro5/allegro_image.h>
4#include<allegro5/allegro_audio.h>
5#include<allegro5/allegro_acodec.h>
6#include<iostream>
7#include"globals.h"
8#include"paddle.h"
9using namespace std;
10
11int main()
12{
13 float gameTime = 0;
14 int frames = 0;
15 int gameFPS = 0;
16 if(!(al_init()))
17 cout << "Couldn't initialize Allegro." << cout;
18 if(!(al_install_joystick()))
19 cout << "Couldn't install joystick." << endl;
20 al_init_image_addon();
21 al_init_primitives_addon();
22 ALLEGRO_DISPLAY *display = NULL;
23 display = al_create_display(1280,720);
24 al_install_audio();
25 al_init_acodec_addon();
26 al_reserve_samples(1);
27 ALLEGRO_SAMPLE* sample = NULL;
28 ALLEGRO_SAMPLE_INSTANCE* instance = NULL;
29 sample=al_load_sample("The Heat Is On.ogg");
30 instance = al_create_sample_instance(sample);
31 al_attach_sample_instance_to_mixer(instance, al_get_default_mixer());
32 ALLEGRO_EVENT_QUEUE *event_queue = NULL;
33 event_queue = al_create_event_queue();
34 if(!event_queue)
35 cout << "al_create_event_queue failed." << endl;
36 ALLEGRO_TIMER *timer;
37 timer = al_create_timer(1.0/60);
38 al_register_event_source(event_queue, al_get_timer_event_source(timer));
39
40 gameTime = al_current_time();
41 al_register_event_source(event_queue, al_get_joystick_event_source());
42 ALLEGRO_JOYSTICK* joy = al_get_joystick(0);
43 ALLEGRO_JOYSTICK_STATE jst;
44 buttons button;
45 direction dir = NONE;
46 bool render = false;
47 ALLEGRO_BITMAP *image = NULL;
48 image = al_load_bitmap("batonspritesheet.png");
49 const int arraySize = 3;
50 bool alive = true;
51 Paddle paddle;
52 paddle.initialize(576, 687, 0, 0, 128, 32, image);
53 al_start_timer(timer);
54 al_play_sample_instance(instance);
55 while(alive)
56 {
57 ALLEGRO_EVENT ev;
58 al_wait_for_event(event_queue, &ev);
59 al_get_joystick_state(joy, &jst);
60 if (ev.type == ALLEGRO_EVENT_JOYSTICK_AXIS)
61 {
62 if ((jst.stick[2].axis[0] == 0) && (jst.stick[2].axis[1] == 0))
63 dir = NONE;
64 if ((jst.stick[2].axis[0] == 1) && (jst.stick[2].axis[1] == 0))
65 dir = RIGHT;
66 if ((jst.stick[2].axis[0] == -1) && (jst.stick[2].axis[1] == 0))
67 dir = LEFT;
68 }
69 if (ev.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN)
70 if (jst.button[9])
71 button = NINE;
72//update
73 else if (ev.type == ALLEGRO_EVENT_TIMER)
74 {
75 render = true;
76 paddle.update(dir);
77 frames++;
78 if (al_current_time() - gameTime >= 1)
79 {
80 gameTime = al_current_time();
81 gameFPS = frames;
82 frames = 0;
83 }
84 }
85//render
86 if (render && al_is_event_queue_empty(event_queue))
87 {
88 //al_set_target_bitmap(al_get_backbuffer(display));
89 al_clear_to_color(al_map_rgb(0,0,0));
90 paddle.Render();
91 al_flip_display();
92 }
93 if (jst.button[9])
94 alive = false;
95 }
96 al_destroy_bitmap(image);
97 al_destroy_timer(timer);
98 al_destroy_event_queue(event_queue);
99 return 0;
100}
Please help! |
SiegeLord
Member #7,827
October 2006
![]() |
Does this reduced code work for you (it does for me, should clear everything to red): 1#include<allegro5/allegro.h>
2#include<allegro5/allegro_primitives.h>
3#include<allegro5/allegro_image.h>
4#include<allegro5/allegro_audio.h>
5#include<allegro5/allegro_acodec.h>
6#include<iostream>
7//~ #include"globals.h"
8//~ #include"paddle.h"
9using namespace std;
10
11int main()
12{
13 float gameTime = 0;
14 int frames = 0;
15 int gameFPS = 0;
16 if(!(al_init()))
17 cout << "Couldn't initialize Allegro." << cout;
18 if(!(al_install_joystick()))
19 cout << "Couldn't install joystick." << endl;
20 al_init_image_addon();
21 al_init_primitives_addon();
22 ALLEGRO_DISPLAY *display = NULL;
23 display = al_create_display(1280,720);
24 al_install_audio();
25 al_init_acodec_addon();
26 al_reserve_samples(1);
27 ALLEGRO_SAMPLE* sample = NULL;
28 ALLEGRO_SAMPLE_INSTANCE* instance = NULL;
29 sample=al_load_sample("The Heat Is On.ogg");
30 instance = al_create_sample_instance(sample);
31 al_attach_sample_instance_to_mixer(instance, al_get_default_mixer());
32 ALLEGRO_EVENT_QUEUE *event_queue = NULL;
33 event_queue = al_create_event_queue();
34 if(!event_queue)
35 cout << "al_create_event_queue failed." << endl;
36 ALLEGRO_TIMER *timer;
37 timer = al_create_timer(1.0/60);
38 al_register_event_source(event_queue, al_get_timer_event_source(timer));
39
40 gameTime = al_current_time();
41 al_register_event_source(event_queue, al_get_joystick_event_source());
42 ALLEGRO_JOYSTICK* joy = al_get_joystick(0);
43 ALLEGRO_JOYSTICK_STATE jst;
44 //~ buttons button;
45 //~ direction dir = NONE;
46 bool render = false;
47 //~ ALLEGRO_BITMAP *image = NULL;
48 //~ image = al_load_bitmap("batonspritesheet.png");
49 const int arraySize = 3;
50 bool alive = true;
51 //~ Paddle paddle;
52 //~ paddle.initialize(576, 687, 0, 0, 128, 32, image);
53 al_start_timer(timer);
54 //~ al_play_sample_instance(instance);
55 while(alive)
56 {
57 ALLEGRO_EVENT ev;
58 al_wait_for_event(event_queue, &ev);
59 al_get_joystick_state(joy, &jst);
60 if (ev.type == ALLEGRO_EVENT_JOYSTICK_AXIS)
61 {
62 //~ if ((jst.stick[2].axis[0] == 0) && (jst.stick[2].axis[1] == 0))
63 //~ dir = NONE;
64 //~ if ((jst.stick[2].axis[0] == 1) && (jst.stick[2].axis[1] == 0))
65 //~ dir = RIGHT;
66 //~ if ((jst.stick[2].axis[0] == -1) && (jst.stick[2].axis[1] == 0))
67 //~ dir = LEFT;
68 }
69 //~ if (ev.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN)
70 //~ if (jst.button[9])
71 //~ button = NINE;
72//update
73 else if (ev.type == ALLEGRO_EVENT_TIMER)
74 {
75 render = true;
76 //~ paddle.update(dir);
77 frames++;
78 if (al_current_time() - gameTime >= 1)
79 {
80 gameTime = al_current_time();
81 gameFPS = frames;
82 frames = 0;
83 }
84 }
85//render
86 if (render && al_is_event_queue_empty(event_queue))
87 {
88 //~ al_set_target_bitmap(al_get_backbuffer(display));
89 al_clear_to_color(al_map_rgb_f(1,0,0));
90 //~ paddle.Render();
91 al_flip_display();
92 }
93 if (jst.button[9])
94 alive = false;
95 }
96 //~ al_destroy_bitmap(image);
97 al_destroy_timer(timer);
98 al_destroy_event_queue(event_queue);
99 return 0;
100}
If it does, then something is wrong with your paddle functions. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
agonvs
Member #15,917
March 2015
|
Yes that worked. I don't know what's wrong with the paddle code but here it is: 1#include"allegro5/allegro.h"
2
3void Paddle::initialize(int x, int y, int velX, int velY, int width, int height)
4{
5 mX = x;
6 mY = y;
7 mVelX = velX;
8 mVelY = velY;
9 mWidth = width;
10 mHeight = height;
11 mImage = al_load_bitmap("batonspritesheet.png");
12 mDir = NONE;
13 mFrame = 0;
14 mCount = 0;
15
16}
17
18void Paddle::update(direction dir)
19{
20 if (dir == LEFT)
21 {
22 tempX = mX - 8;
23 if (tempX < 0)
24 mX = 0;
25 else
26 mX = tempX;
27 }
28 else if (dir == NONE){}
29 else
30 {
31 tempX = mX + 8;
32 if ((mX + mWidth) >= 1279)
33 mX = (1279 - mWidth);
34 else
35 mX = tempX;
36 }
37}
38
39void Paddle::render()
40{
41 if (mCount == 5)
42 {
43 mFrame++;
44 mCount = 0;
45 }
46 if (mFrame == 3)
47 mFrame = 0;
48 al_draw_bitmap_region(mImage, (mFrame * 128), 0, 128, 32, mX, mY, 0);
49 mCount++;
50}
That was paddle.cpp. Here's the updated main.cpp code: 1#include<allegro5/allegro.h>
2#include<allegro5/allegro_primitives.h>
3#include<allegro5/allegro_image.h>
4#include<allegro5/allegro_audio.h>
5#include<allegro5/allegro_acodec.h>
6#include<iostream>
7#include"globals.h"
8#include"paddle.h"
9using namespace std;
10
11int main()
12{
13 float gameTime = 0;
14 int frames = 0;
15 int gameFPS = 0;
16 if(!(al_init()))
17 cout << "Couldn't initialize Allegro." << cout;
18 if(!(al_install_joystick()))
19 cout << "Couldn't install joystick." << endl;
20 al_init_image_addon();
21 al_init_primitives_addon();
22 ALLEGRO_DISPLAY *display = NULL;
23 display = al_create_display(1280,720);
24 //al_install_audio();
25 //al_init_acodec_addon();
26 //al_reserve_samples(1);
27 //ALLEGRO_SAMPLE* sample = NULL;
28 //ALLEGRO_SAMPLE_INSTANCE* instance = NULL;
29 //sample=al_load_sample("The Heat Is On.ogg");
30 //instance = al_create_sample_instance(sample);
31 //al_attach_sample_instance_to_mixer(instance, al_get_default_mixer());
32 ALLEGRO_EVENT_QUEUE *event_queue = NULL;
33 event_queue = al_create_event_queue();
34 if(!event_queue)
35 cout << "al_create_event_queue failed." << endl;
36 ALLEGRO_TIMER *timer;
37 timer = al_create_timer(1.0/60);
38 al_register_event_source(event_queue, al_get_timer_event_source(timer));
39 gameTime = al_current_time();
40 al_register_event_source(event_queue, al_get_joystick_event_source());
41 ALLEGRO_JOYSTICK* joy = al_get_joystick(0);
42 ALLEGRO_JOYSTICK_STATE jst;
43 buttons button;
44 direction dir = NONE;
45 bool render = false;
46 ALLEGRO_BITMAP *image = NULL;
47
48 const int arraySize = 3;
49 bool alive = true;
50 //Paddle paddle;
51 //paddle.initialize(576, 687, 0, 0, 128, 32);
52 al_start_timer(timer);
53 //al_play_sample_instance(instance);
54 while(alive)
55 {
56 ALLEGRO_EVENT ev;
57 al_wait_for_event(event_queue, &ev);
58 al_get_joystick_state(joy, &jst);
59 if (ev.type == ALLEGRO_EVENT_JOYSTICK_AXIS)
60 {
61 if ((jst.stick[2].axis[0] == 0) && (jst.stick[2].axis[1] == 0))
62 dir = NONE;
63 if ((jst.stick[2].axis[0] == 1) && (jst.stick[2].axis[1] == 0))
64 dir = RIGHT;
65 if ((jst.stick[2].axis[0] == -1) && (jst.stick[2].axis[1] == 0))
66 dir = LEFT;
67 }
68 if (ev.type == ALLEGRO_EVENT_JOYSTICK_BUTTON_DOWN)
69 if (jst.button[9])
70 button = NINE;
71//update
72 else if (ev.type == ALLEGRO_EVENT_TIMER)
73 {
74 render = true;
75 //paddle.update(dir);
76 frames++;
77 if (al_current_time() - gameTime >= 1)
78 {
79 gameTime = al_current_time();
80 gameFPS = frames;
81 frames = 0;
82 }
83 }
84//render
85 if (render && al_is_event_queue_empty(event_queue))
86 {
87 //al_set_target_bitmap(al_get_backbuffer(display));
88 al_clear_to_color(al_map_rgb(0,0,0));
89 //paddle.Render();
90 al_flip_display();
91 }
92 if (jst.button[9])
93 alive = false;
94 }
95 al_destroy_bitmap(image);
96 al_destroy_timer(timer);
97 al_destroy_event_queue(event_queue);
98 return 0;
99}
Thoughts?::) |
SiegeLord
Member #7,827
October 2006
![]() |
Hmm... I don't see anything wrong either :/. Have you also tried commenting out just the audio routines? "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
agonvs
Member #15,917
March 2015
|
I figured it out. It was an incredibly stupid error. I capitalized Render when it should have been lower case. In the base class I inherited from, Render was uppercase. I changed it. It works now. |
SiegeLord
Member #7,827
October 2006
![]() |
Phew, you had me worried there. To prevent this from happening in the future, get into the habit of adding override when you override a method. It's a very useful C++11 feature. "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
agonvs
Member #15,917
March 2015
|
Thanks for the tip! |
|