Dark Bit Factory & Gravity

PROGRAMMING => Freebasic => Topic started by: donvito on February 29, 2008

Title: EXTREMELY n00b question...
Post by: donvito on February 29, 2008
Hey guys!

First off, GREAT SITE, I've been looking into learning to code old-school style demos for a long long time, and this site is a great resource.

Basically, I'm sure that my question is going to be ridiculously noobish, but I have to ask.

Essentially, I am trying to modify the "line-drawing" code from the second FB tutorial to make a crosshair in the center of the window. 

So far, I've got it centered, and the "left" and "right" of the crosshair, but I cannot get the vertical lines for some reason, I figured it would involve just using Y in place of X and some tweaking, but I can't figure it out.

I know that it writes from left to right, and I think this is my problem.  I feel like such a n00b, but I've never really done any graphics programming before.

heres the code... 

Quote
WHILE(1)
X = 320
Y = 240

FOR A = 0 TO 49
    BUFFER (X + A +(Y*XRES)) = &HFFFFFF
NEXT

FOR A = 0 TO 49
    BUFFER (X - A +(Y*XRES)) = &HFFFFFF
NEXT

FOR A = 0 TO 49
    BUFFER (Y + A +(X*YRES)) = &HFFFFFF
NEXT


I know that the framework can do this for me, but I like to learn the dirty, long way to do things purely because then I fully understand it.

Thanks for your help guys, I'm happy to be a new member to this community. :D

Title: Re: EXTREMELY n00b question...
Post by: zawran on February 29, 2008
Code: [Select]
FOR A = 0 TO 49
    BUFFER (X+(Y+A)*YRES) = &HFFFFFF
NEXT
Title: Re: EXTREMELY n00b question...
Post by: ninogenio on February 29, 2008
first of welcome to our comunity donvito, stick around you will learn loads of stuff as i have.

secondly thats not a stupid question at all. it's a bit tricky to learn to work with 1d buffers at first i remember doing my head in trying to learn them at first. the way they work is like so.

imagine your screen not as in x,y but just as in x. say you have a 640*480 size screen that would give you a 1d buffer of 307200 pixels. now comes the problem of getting to exact x ,y places in the buffer. well here is a little algo that you have probably seen quite a lot.

Buffer( x + ( Y*ScreenX ) )

now if you want to get too the first pixel in the second row its.

1 + 1*640 = 641

or the first pixel of the second row.

1 + 2*640 = 1281

the thing to remember with 1d buffers is when you come to the end of your screen ie 640 it will wrap around and go down a line so 641 is the first pixel on the second row.

hope that makes sense as im not very good at explaining things
Title: Re: EXTREMELY n00b question...
Post by: donvito on February 29, 2008
Hey guys,

Thanks a lot for both replies, that makes things a lot easier to understand!

Thanks again,
donvito
Title: Re: EXTREMELY n00b question...
Post by: donvito on February 29, 2008
Code: [Select]
FOR A = 0 TO 49
    BUFFER (X+(Y+A)*YRES) = &HFFFFFF
NEXT

sorry for double post but just wanted to say this works, but the yres needs to be xres :D

thanks,
donvito
Title: Re: EXTREMELY n00b question...
Post by: zawran on February 29, 2008
I might have switched things around, it was typed on my way to work, so I might have been tired :)
Title: Re: EXTREMELY n00b question...
Post by: Shockwave on February 29, 2008
Welcome Donvito :)

What you are doing is a great way to get used to the screen buffer. It will just click into place with you the way that a continuous sequence of numbers gets plotted into lines that forms the screen.

The maths for this is pretty simple and what you are making is fine for drawing simple straight lines, there are many many things that can be done to boost the speed for you when you have learned how the screen buffer works.

And please don't apologise for posting any programming question here, they are all welcome.
Title: Re: EXTREMELY n00b question...
Post by: donvito on March 01, 2008
Welcome Donvito :)

What you are doing is a great way to get used to the screen buffer. It will just click into place with you the way that a continuous sequence of numbers gets plotted into lines that forms the screen.

The maths for this is pretty simple and what you are making is fine for drawing simple straight lines, there are many many things that can be done to boost the speed for you when you have learned how the screen buffer works.

And please don't apologise for posting any programming question here, they are all welcome.

thanks for the welcome.

Yea, it was kinda like DUH when I saw it in action, and now I have a perfectly centered crosshair haha, cool, maybe...  useless? definitely. :D

I plan on dissecting the scroller tutorial soon.

i love this stuff, very fun.

donvito