![]() |
|
starfield - direct acces to video memory |
mscava
Member #6,815
January 2006
![]() |
i'm sorry but another problem occured... int stars_[800][540]; for(short x=0;x<800;x++) for(short y=0;y<540;y++) stars_[x][y] = makecol16(255,255,random(175,255)); acquire_bitmap(bitmap); bmp_select(bitmap); for(short y = 0; y<540; y++) { unsigned long address = bmp_read_line(bitmap,y); for (short x=0; x<800; x += sizeof(uint16_t)) bmp_write16(address+x,(uint16_t)stars_[y]+x); } release_bitmap(bitmap); and bitmap is video_bitmap. whole program just crashes. |
Richard Phipps
Member #1,632
November 2001
![]() |
Why don't you just use an Allegro bitmap and blit? |
A J
Member #3,025
December 2002
![]() |
your method will be slow, and prone to crash just use a regular memory bitmap, then blit. ___________________________ |
Andrei Ellman
Member #3,434
April 2003
|
If you are accessing your array with stars_[y]+x, you have got the X and Y coordiantes the wrong way round for this to work. Try int stars_[540][800]; and stars_[y][x] = makecol16(255,255,random(175,255)); AE. -- |
Elverion
Member #6,239
September 2005
![]() |
Yeah...you're method seems as though it would be rather slow. What's with the whole reading and writting lines of the bitmap? The way I would do it is as follows: create an array/vector/etc. of star objects/structs You might want to also consider scaling the "stars" based on distance from center of the screen. Or, you can also make them fade in from gray to white as they reach the edges of the screen, too. -- |
Kitty Cat
Member #2,815
October 2002
![]() |
Quote: draw each star to the double buffer using putpixil
What he's doing is faster than putpixel (check the exflame example -- |
mscava
Member #6,815
January 2006
![]() |
thanks kitty...what i am trying to do is to write those stars onto video_buffer. with putpixel it is slooow. exflame example is showing how to make it faster. so i tried to do something like that. but my code just seems to crash the program... so any ideas how to rewrite it so it will be fast and working? and i've tried to exchange x and y but it still crashes... |
A J
Member #3,025
December 2002
![]() |
do you know how to use a debugger ? ___________________________ |
Kitty Cat
Member #2,815
October 2002
![]() |
You need to keep consistant with your x/y usage with the array. In bmp_write16, you were adding x instead of sub-scripting it for the array. And, you were calling bmp_read_line (which is for reading) instead of bmp_write_line (which is for writing). int stars_[540][800]; for(short y=0;y<540;y++) for(short x=0;x<800;x++) stars_[y][x] = makecol16(255,255,random(175,255)); acquire_bitmap(bitmap); bmp_select(bitmap); for(short y = 0; y<540; y++) { unsigned long address = bmp_write_line(bitmap, y); for (short x=0; x<800; x++) bmp_write16(address + x*sizeof(uint16_t), (uint16_t)stars_[y][x]); } bmp_unwrite_line(bitmap); release_bitmap(bitmap);
-- |
mscava
Member #6,815
January 2006
![]() |
thank you very much kitty cat... now it works... and i am less confused with all those bmp_read/write methods... thanks again... |
|