Graphics

Here you can talk about anything related to BBC BASIC, not covered in another category
Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Graphics

Post by Ivan »

I was worried about BBC BASIC graphics was fast enough. I have just made a program with lots of simple objects which can scrolled sideways and the speed was ok.

In the meantime I had a study in C++ and had a go at opengl and that is hard to grasp combined with OOP.

Borland did a graphics library BGI that can be used much like BBC BASIC in C++, but it is not faster, so I think Richard did very good job about implementing graphics. I know BGI is old but I find many request on how to use it. They just want the basic of graphics and they also have to struggle with compiler settings.

I think many people should have a go at BBC BASIC, but experienced programmers will probably not advice them to.
Last edited by Ivan on Fri 22 Jan 2021, 09:29, edited 1 time in total.
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.

KenDown
Posts: 261
Joined: Wed 04 Apr 2018, 06:36

Re: Graphics

Post by KenDown »

Professional programmers can be terribly snobbish about BASIC, mainly - I suspect - because they are using inferiour products such as Visual Basic. I agree that everyone should program in BBC BASIC, preferably BB4W!

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: Graphics

Post by DDRM »

I suspect Richard would encourage them to use BBC-SDL, because of its cross-platform flexibility, unless they need the special features that BB4W offers, such as access to Windows-specific APIs....

:-)

D

Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: Graphics

Post by Ivan »

KenDown wrote:
Fri 22 Jan 2021, 08:22
Professional programmers can be terribly snobbish about BASIC, mainly - I suspect - because they are using inferiour products such as Visual Basic. I agree that everyone should program in BBC BASIC, preferably BB4W!
I had asked in a C++ forum. They had no understanding of why I did not want to use newest graphics libraries. I tried to explain I did not want to program state of the art graphics, but just plain 2D. They wanted me to compile different libraries and linking this and that. Not all are great to teach others or even explain howto.

If you mention eg. BGI many of them will automatically say ancient and ect. But I managed to setup CodeBlocks with BGI and it worked fine. It's relatively easy to convert BBC BASIC routines to C++.

In the fall 2019 I looked at my robot lawnmower and thought that I could easily emulate it. I soon learned that I could not. After a while I realized that I had to study trigonometry and I soon learned to draw circles and angles. Many experiments later I figured out that I could add a third value to y and therefore emulate z. A "million" experiments later I did a 3d function name(x, y, z, move or draw, colour). One of my neighbors who have mathematical knowledge said, then you are using vectors! I replied probably, I don't what a vector are.

Then I did a simple 3D drawing program with drawing, edit and delete lines. Rotate and resize, save and load.
You do not have the required permissions to view the files attached to this post.
Last edited by Ivan on Sun 24 Jan 2021, 10:11, edited 1 time in total.
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.

Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: Graphics

Post by Ivan »

DDRM wrote:
Fri 22 Jan 2021, 09:04
I suspect Richard would encourage them to use BBC-SDL, because of its cross-platform flexibility, unless they need the special features that BB4W offers, such as access to Windows-specific APIs....

:-)

D
I'm sure you are right about that point. :-)

I prefer "console" and not to be wrapped in a specific system. But if I need to, Richard had made a lot of system calls.
Last edited by Ivan on Sun 24 Jan 2021, 10:12, edited 1 time in total.
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: Graphics

Post by DDRM »

It definitely helps in terms of understanding to "do it yourself", and the built-in BBC BASIC graphics are a good way to do this - quite simple to understand and use. To get high performance with anything other than very simple models, though, you are probably going to want to use graphis libraries: both BB4W and BBC-SDL support this: in fact, from what Richard has said, the SDL OpenGL ones may be better in some ways than the D3D-based Windows ones.

Something else that you may want to look at in terms of graphical rendering is to consider using arrays to store the coordinates: that way you can use array arithmetic to process all the points at once, where that is appropriate - it is MUCH faster than iterating over each point. You just need to set up a transformation array (can handle translations, rotations, etc all in one), and then multiply the whole array to change a point of view, for example. Or put all the points in a single object in an array, so you can move/rotate it relative to the others.

Hope that's helpful!

D

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: Graphics

Post by DDRM »

You might want to look at a post Richard has made at groups.io:

https://groups.io/g/bb4w/topic/array_ar ... 0,80061306

where he has made a wireframe globe, and use matrix multiplication to rotate it in real time. There are some useful comments about arranging it to make hidden line removal possible, too.

Best wishes,

D

Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: Graphics

Post by Ivan »

Nice.

rem Rotation angles:
a = 0
c = 0
b = 0

Can apperently have any value and makes no difference as far as I can see.

But the increment values of a and b can be altered with effect.

Understanding matrice calculation, dot product or scalar will help a lot.


Regarding array arithmetic:

dim a(2,2)
a() = 1,2,3,4,5,6,7,8,9

Is much faster than iteration as you mentioned. My little experiment indicates 2 or 3 times faster.

I tried this one without succes.

dim struct{(2) x}
struct{()}.x = 600, 200, 500
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.

Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: Graphics

Post by Ivan »

Ivan wrote:
Tue 26 Jan 2021, 11:31
Nice.

rem Rotation angles:
a = 0
c = 0
b = 0

Can apperently have any value and makes no difference as far as I can see.

But the increment values of a and b can be altered with effect.

Understanding matrice calculation, dot product or scalar will help a lot.


Regarding array arithmetic:

dim a(2,2)
a() = 1,2,3,4,5,6,7,8,9

It is much faster than iteration as you mentioned. My little experiment indicates 2 or 3 times faster.

I tried this one without succes.

dim struct{(2) x}
struct{()}.x = 600, 200, 500
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: Graphics

Post by DDRM »

Hi Ivan,

I wasn't really talking about bulk-filling the array in the first place, but about using array arithmetic to process a lot of points at once, for example to do rotations. Hence the link to Richard's rotating world, which I suspect was posted in (indirect) response to your question and my answer, as a "worked example". What I'm suggesting is that you could store all the points in an object (2d or 3d) in a single matrix (or consider using separate matrices for each dimension x,y,z), and then you can multiply by a rotation matrix,and process all the points at once: this is likely to be several orders of magnitude faster, since it is done "behind the scenes", in assembled code.

On your second point, I don't think you can treat arrays of structures the same way when assigning data to them, because of the way they are laid out in memory. An array of integers has all the elements consecutive in memory, so it's easy to allocate lots of consecutive values. Addressing structure elements is quite complex (see the section on variable storage in memory, in the manual), but the x coordinates of successive structures aren't going to be next to each other. You'll need to use a loop to allocate them.

Best wishes,

D