BGI -13h

This is a discussion on BGI -13h within the Game Programming forums, part of the General Programming Boards category; As i wanted to make a ball move on the screen (wich is my first attempt on doing that) i ...

  1. #1
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109

    BGI -13h

    As i wanted to make a ball move on the screen (wich is my first attempt on doing that) i though ill use 13 h mode .... my ball movement went slow and i could see the ball getting refreshed evry time. So i was thinking mayb the 13h mode is just slow (wich i already speeded up as much as i could) so i would port it to BGI (borland graphixs interface).
    Although ive got a higher resolution now im still having the same problem i can see the ball getting refreshed...
    heres my code
    of main...
    Code:
    #include <graphics.h>
    #include <conio.h>
    #include <stdlib.h>
    #include <dos.h>
    #include <math.h>
    
    int main( )
    {
     int gdriver, gmode, errorcode;
     char driver_path;
     detectgraph(&gdriver, &gmode);  /*VGA HI 640*480*/
     initgraph(&gdriver, &gmode, &driver_path);
    
     int angle;
    	float COS_TABLE[360], SIN_TABLE[360];
    	float pi=3.14159;
    	for(angle=0;angle<360;angle++){
    	 COS_TABLE[angle]=cos((float)angle/180 * pi);
    	 SIN_TABLE[angle]=sin((float)angle/180 * pi);
    	}
    
    	int moves=0;
    	int direction;
    	int r;
    	srand(NULL);
    	for(moves=0;moves<10;moves++){
    
    	direction=rand() %361;
    
    	  for(r=0;r<40;r++){
    			draw_ball(100+(COS_TABLE[direction]*r),100+(SIN_TABLE[direction]*r),5,COS_TABLE,SIN_TABLE);
    			delay(100);
    			draw_ball(100+(COS_TABLE[direction]*r),100+(SIN_TABLE[direction]*r),0,COS_TABLE,SIN_TABLE);
    			}
    	  }
     sleep(2);
     return 0;
     }
    And heres my draw_ball function
    Code:
    int draw_ball(int x,int y,int color, float COS_TABLE[] , float SIN_TABLE[]){
    	for(int a=0;a<360;a++){
    		for(int radius=0;radius<5;radius++){
    			putpixel(x+COS_TABLE[a]*radius,y+SIN_TABLE[a]*radius,color);
    		}
    	}
    	return 0;
    	}
    I think i know where the problem is. Its that the app always has to recalculate every ball and then put it onto the screen....
    Is there some way i can save this "ball" at runtime.
    So that the app has to calculate the ball one time and then just moves the ball by choosing direction, speed, x start and y start.

    Thx in advance.

    ::edit::
    sry bout the indentations when im writing code i always use tabs to indent.

  2. #2
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    I think i found it (just went for a walk outside). Would it help if i calculated every pixel of the ball then store it in a 2 dimensional array and when i want to draw it i just make a call to that 2-d array and plot it onto screen....

    Is this the way ??

  3. #3
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Do the math - what's the area of a circle?
    By my calculations, you loop 1800 times to draw a circle containing 50 pixels.
    I also know the formula for the area of a circle.But how can i implement that formula the only way i was able to draw a full-coloured circle was thias way: draw a circle ( from 0 degrees till 360 degrees) with radius 0 then radius 1 ....So i figured if i want to draw a full circle i need to do these *radius thing.....

    Anyway i'll forget about the whole calculating thing since this is stressing me out (because i really tought i was on the right track with that).Instead im just gonna draw my 2-d array on my own using an X for each pixel and a space for transparancy..
    I think that will be the best to do

  4. #4
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    As i wanted to make a ball move on the screen (wich is my first attempt on doing that) i though ill use 13 h mode .... my ball movement went slow and i could see the ball getting refreshed evry time. So i was thinking mayb the 13h mode is just slow (wich i already speeded up as much as i could) so i would port it to BGI (borland graphixs interface).
    Although ive got a higher resolution now im still having the same problem i can see the ball getting refreshed...
    heres my code
    of main...
    you think BGI is faster than 13h? hahahahhahaha! (sorry, i dont mean to be rude, i really dont). 13h is very low down and fast. its one of the fastest modes you can get, actually, because it is only 320x200, therefore does not require a lot of memory.

    If you are having speed problems in 13h, either your entire computer is on the slow side, or your algorithms are not near optimized. Optimize you algorithms!

    BGI is 100 times slower than 13th. If you experience flickering in 13h you will experience it 10 fold in BGI.

    I suggest two things:

    1. Page flipping / back buffering....completely annihilates any and all flickering. If you dont know what it is, learn it. www.brackeen.com Go to the VGA tutorial at that page.
    2. Optimize algorithms.

    If you have ANY doubts about the speed of 13h, consider this: The following games were ALL originally made in 13h mode:

    Wolfenstein 3D
    Doom
    Doom II
    Quake
    Mario Bro
    Legend of Zelda
    and many other popular games...u name it.....there are THOUSANDS of games out there made in 13h...

    so trust me...it is not 13h that is slow and causing flickering....and BGI would just make it worse. Use back buffering and optimized algorithms. Thats all I can tell you.
    My Website

    "Circular logic is good because it is."

  5. #5
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    Use back buffering and optimized algorithms. Thats all I can tell you.
    Yup im working on this right now... and i did knew that bgi was slower (ive just been messing around with that). But i already made the flickering go away for about 50%.

    Anyway thx all of you.
    BTw: that brackeen site was down the last few days... thats why i was kinda stuck... IMO its the only really good site that explains 13h.

  6. #6
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,109
    I've just got another question.
    When you use a function to wait for the vertical refresh thingie in VGA then your basically kind of syncronize your refresh rate of shapes with the refresh rate of the video card in VGA mode?

    + is there any reference you can download with most of the VGA interrupts in... Because you cant all know em by heart, or do you ?

    Again thx in advance..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. BGI Error:
    By it4_saravana in forum C Programming
    Replies: 4
    Last Post: 04-12-2008, 03:48 AM
  2. BGI and text cursor
    By Somnambulist in forum C++ Programming
    Replies: 4
    Last Post: 01-21-2004, 07:54 PM
  3. Replies: 2
    Last Post: 03-10-2003, 03:07 PM
  4. anyone know about interrupt 13h extensions?
    By merlyn2000 in forum A Brief History of Cprogramming.com
    Replies: 17
    Last Post: 06-17-2002, 12:00 PM
  5. Borland C++ BGI
    By Xterria in forum Game Programming
    Replies: 10
    Last Post: 03-05-2002, 08:39 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21