• Welcome to Dark Bit Factory & Gravity.
 

Allegro help !

Started by waste, February 17, 2014

Previous topic - Next topic

0 Members and 0 Guests are viewing this topic.

waste

hi all ,

I'm begginer in demoscene effects ( though i used to do that on z80 assembly ...)  , 

i'm trying to merge two source code i 've found ,  one starfield and  one scroller text (no sine first) , using allegro for both

the two codes compile and execute well, but when i want to insert my scroller text with the starfield , the program stops ,

i can provide source code by mail or mp,  here are sections  i suppose that cause the crash,  (when i put the line "problem 1,2,3" in comments , text scroller runs without starfield )   

sorry for my english ... i hope it's quite correct

Main function


int main(int argc, char *argv[]) {

    int framecount;
    framecount=0;

    allegro_init();       
install_keyboard();   

    LOCK_VARIABLE(speed_counter);
    LOCK_FUNCTION(increment_speed_counter);
    install_int_ex(increment_speed_counter, BPS_TO_TIMER(60));

set_color_depth(8) ;   // 8 bit colour
if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, screen_x, screen_y, 0, 0)<0)
{
    //set_gfx_mode(GFX_TEXT, 0, 0, 0, 0); 
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, screen_w, screen_h, 0, 0);

     allegro_message("Failure to init video mode!\n%s\n", allegro_error);
    exit(1); // force abort
}

off_screen = create_bitmap(screen_x, screen_y); 


Init_Music();
    Init_Font();
    install_timer();
    Play_Music();
    srand(time(NULL));
Star star[maxstars];     // problem one !

while ((!key[KEY_ESC])&&(!key[KEY_SPACE]))
    {

        clear_bitmap(off_screen);





        DrawString((framecount % 2550)-820,508,"TEST SCROLL LEFT TO RIGHT...NO SINUS EFFECT FIRST....");  // draw scroller
        framecount+=6;
        vsync();
       blit(off_screen, screen, 0, 0, 0, 0, screen_x, screen_y); 
        rest(1);
    };
    while(speed_counter > 0)
        {
         for(int i = 0; i < maxstars; ++i)
                            {
                                    star[i].movestars();                // problem two !
                            }
                            speed_counter --;
         }

        draw_sprite(screen, buffer, 0, 0);       // third problem , linked to the Star Class, supposed to draw starfield


    destroy_bitmap(off_screen);     
    Kill_Music();
    Kill_Font();
    remove_timer();     
return 0;     
}     
END_OF_MAIN();



here is the Star Class that causes problems




Star::Star()
{
            posx = (rand() % screen_w);
            posy = (rand() % screen_h);
            speed = (rand() % 5) + 1;
            putpixel(buffer, posx, posy, makecol(255, 255, 255));

void Star::movestars()
{
          putpixel(buffer, posx, posy, makecol(0, 0, 0));
          posx -= speed;
          if (posx <= 0)
          {
             posx = screen_w;
          }
          putpixel(buffer, posx, posy, makecol(255, 255, 255 ));
}


thanks in advance for your advices



waste

ooops , buffer init missing

buffer = create_bitmap(screen_w, screen_h);

it's better now though i don't have the two effects at same time ..... problem with While ....

waste

that's ok now, 


thanks even if i feel abit alone  !!


Gore Motel

Yo! I glanced over the code snippets, but I can't really help much since I never used Allegro and haven't written any C++ code since my college years. Maybe you could post the full source if you're still having trouble.

And your English is fine, I understood what you wrote.

Yaloopy

Glad you figured out the solution. If you want to post long source code you could attach it as a .txt file with your post.
Fuck L. Ron Hubbard and fuck all his clones.
Challenge Trophies Won:

Hotshot

I used do allergo years ago but now they change bit which is Allergo 5 that I am not try it yet.

Just wondering what IDE do you used?

Cant see anythings wrong with your code but dont understand why your program crash!

waste

hi,

here is the full source if you want to take a look to,  i used DEVC++  , why ? because it the only one i managed to configure with allegro !!!

it's for learning purpose, i will try to do my own now,  next step , implement à sine routine to move the scroller ,  i have already my sine table ,

i have to understand how to do that .....



Hotshot

#7
Hello waste,

You have done very well to do it on your own :)

:clap:

It is good to learn from it as being it is Allergo 5 and the code of itself is really good!

I used CodeBlocks IDE at the moment :)

Number 1 Challange - Try Change Starfield going up
Number 2 Challange - Try make Font scrolling in Sine wave :)
Number 3 Challange - Try make 2 rainbow bar from top and one middle with starfield in the middle :)


waste

 :carrot:

thanks !! , i also begin PureBasic  at same time !!  so as soon as possible , i will upgrade my c++ allegro projects with all of that  !! it 's more  difficult in c++ for me !!

i waste a lot of time to set my IDE configured !! with libs, headers etc ...

Hotshot

#9
Quote
thanks !! , i also begin PureBasic  at same time !!  so as soon as possible , i will upgrade my c++ allegro projects with all of that  !! it 's more  difficult in c++ for me !!


Purebasic is where is like straight to the point and get job done quicker but learning C++ is good things as it is hard to master them which take time!

Quote
i waste a lot of time to set my IDE configured !! with libs, headers etc ...

I hate that as I wish there was IDE Allergo(someone who make em) where it setup everythings for ya on every time you make project which would be good otherwise it would be too much hassle like you say

I found Allergo 5 Tutorials and I will post it on either Useful links, or general chat soon or C / C++ /C# :)