Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Advice/Help needed...
#1
Hello!
I'm both new to the forums and also programming in general. Most of my programming experience has been from playing on my calculator and taking a programming class at school. Since both use a basic, I decided to start playing around with qbasic, and quickly found out about freeBASIC.

Freebasic was just what i was looking for to spark my interest in programming... thanks so much you guys!!!

Anyways..... i have a couple of questions so please bear with me, b/c i am a "n00bz0r".

1. I know freeBasic doesnt support the graphic functions (draw, pset, line, etc...) and i've been reading up on this forum about different graphic libraries being used. Could you explain the differences between the libraries (api, sdl, openGL) and recommend how I should go about learning them, like maybe some good sites or resources? I've been searching on google, but mostly have found incomplete or outdated info.

2. I've made a program of a ball bouncing in a box. However, it seems to flash alot. I then replaced the cls with writing a black square over the ball. This seemed to help, but the box still flashes a little. Could you guys give me some advice on the code?:


Code:
cls
print "***Program by: RJ***"
print "Watch the ball go!!!"
input "Hit anykey to continue.";p
cls

let x=10
let y=10
let xadj=1
let yadj=1
'game
do
      'top outline
      let r= 1
      let c= 1
      for c = 1 to 80
        locate r,c
        print Chr$(177)
      next c

      'bottom outline
      let r= 22
      let c=1
      for c = 1 to 80
        locate r,c
        print Chr$(177)
      next c

      'left outline
      let c=1
      let r=1
      for r=1 to 22
        locate r,c
        print Chr$(177)
      next r

      'right outline
      let c=80
      let r=1
      for r = 1 to 22
        locate r,c
        print Chr$(177)
      next r
      
      'black to erase ball because cls sux
      let Row=x
      let Col=y
      locate Row,Col
      print Chr$(255)

      'bouncy ball
      IF y <= 2 THEN yadj = 1
      IF y >= 79 THEN yadj = -1
      IF x >= 22 THEN xadj = -1
      IF x <= 2 THEN xadj = 1
      x = x + xadj
      y = y + yadj
     locate x,y
     print Chr$(2)
loop

Again, awesome site and compiler and sorry about the stupid questions.
Reply
#2
For learning SDL, Download the HTML doc at libsdl.org. It's in C but easily translatable to FB. For OpenGL, google the "OpenGL Red Book" it's all you need to do GL stuff. Combining both makes it even easier.

I may be able to write a tute or two regarding those things in FB. But don't count on it until I get my comp repaired.


AS for the Flickering:

http://faq.qbasicnews.com/?blast=BallToBallCollision

It uses SetVideoSeg by Plasma. In other words, use a double buffer.

Welcome to the forums!!!
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#3
eehm, just wait for the next release of FB. it has qb -like gfw library with it. I did a small test (the source code from old qbasic) and all I had to change was adding a "flip" command. it dwars out to the screen the stuff you did.
url]http://fbide.sourceforge.net/[/url]
Reply
#4
Quote:eehm, just wait for the next release of FB.
Woah really, qbgfx4fb is in the next release of FB? I thought v1c would at least want PRINT working first...
Reply
#5
i have cvs version and it has qbgfx
url]http://fbide.sourceforge.net/[/url]
Reply
#6
The reason you get 'flashes,' more commonly known as flickering, is because drawing everything directly to the screen separately is slow.

To fix this, you use a technique called Double Buffering. In this technique, you write to a buffer that isn't drawn immediately. Once you have filled the buffer to what you want, then you draw it to the screen. This is much faster, as instead of doing lots of small drawings to the screen, you are drawing one big screen each step.

If you are confused as to what a buffer is, then just think of it like this: You want to scan a picture. The scanned image is your screen, and the drawing on paper is the buffer. Let's pretend you are drawing a man.

The simple way of drawing to the screen, what most people do before they learn about double buffering, is the equivalent of drawing the man's head, scanning it, drawing the man body, scanning it, and drawing and scanning each individual part of the body and scanning it separately. It is much slower. Double buffering would be the equivalent of drawing the man in one go, then scanning him and having a picture in one go.

I haven't read the doc that Rel pointed you to, but there are many many good tutorials all over the Internet. With the new library for the old graphic commands of QB now in FB, you should be able to use the QB tutorials directly.

The best resource is http://www.petesqbsite.com. Now this site was just attacked by hackers, but keep checking back, because Pete is sure to put the site back up.
·~¹'°¨°'¹i|¡~æthérFòx~¡|i¹'°¨°'¹~·-
avinash.vora - http://www.avinashv.net
Reply
#7
If you are still inclined to do this in text, you should be able to shave off some processor time by drawing your outline outside of your do loop, then adjust your math to where the ball doesn't overlap it on collision but rather richets when flush with it. Also you could erase the two let statements in the black ball cluster and simply use locate x,y as it will do the same thing with less code. By speeding up your loop it will help on the refresh since it isn't actively drawing as much. I hope this helps too. Smile
Reply
#8
Thanks so much for all your responses!

I now understand the flickering problem and double buffering, and I'll check out the links as soon as possible. 8)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)