Drawing things in C

203 views
Skip to first unread message

Mason

unread,
Mar 17, 2015, 10:45:36 AM3/17/15
to bareme...@googlegroups.com
Hi everybody,
This isn't an issue or something like that, but I was playing around with BareMetal OS and realized that there isn't really a library to use to draw things with.
So, I made one :)
I'm still working on some things like drawing polygons, but I've made it into a sort of usable library.
If you're interested, feel free to check it out :)

42Bastian

unread,
Mar 17, 2015, 12:08:11 PM3/17/15
to bareme...@googlegroups.com
Hi Mason
Shouldn't be thickness of a line be 90 degrees to the line instead of
simple more X?


--
42Bastian

Ian Seyler

unread,
Mar 17, 2015, 1:20:56 PM3/17/15
to bareme...@googlegroups.com, maso...@gmail.com
I tried it and it worked as intended! Good work! It would be good to implement double buffering though:

Draw scene to buffer
Copy buffer to video memory
Repeat

I might give that a try with the 3D stars demo I made.

-Ian

Ian Seyler

unread,
Mar 17, 2015, 1:27:10 PM3/17/15
to bareme...@googlegroups.com, maso...@gmail.com
There is a small error in the put_pixel function (which was originally an error in the 3dstars app).



On Tuesday, March 17, 2015 at 10:45:36 AM UTC-4, Mason wrote:

Pablo Hugo Reda

unread,
Mar 17, 2015, 2:14:39 PM3/17/15
to bareme...@googlegroups.com, maso...@gmail.com
Hi Mason

this is antialised line and polygon draw rutine

42Bastian

unread,
Mar 17, 2015, 2:23:22 PM3/17/15
to bareme...@googlegroups.com
Mason

> If you're interested, feel free to check it out :)
> https://github.com/ohnx/libDraw

I wonder, why do you use floating point math. For the primitives exist
Bresenham algos which are surely faster.

(Again it is bad that the GFX chips vendors do not provide open documents.)

--
42Bastian

Mason

unread,
Mar 17, 2015, 8:47:11 PM3/17/15
to bareme...@googlegroups.com
Err, I'm not very good with some aspects of math, so I pretty much just googled for and algorithm to compute a circle, line and filled circle, and just adapted them for BareMetal OS.
If you have any links to better algorithms, please send them to me and I'll have a look at them.

Mason

unread,
Mar 17, 2015, 8:47:11 PM3/17/15
to bareme...@googlegroups.com, maso...@gmail.com
What is the size of the VideoMemory?
Is there a way to find this?

Mason

unread,
Mar 17, 2015, 8:47:11 PM3/17/15
to bareme...@googlegroups.com, maso...@gmail.com

Pablo, thanks for the code, I'll look into it (It looks very scary, I don't know C++ :p)
Ian, I'll correct the put_pixel function in libDraw as well. As for the buffering, I'll start working on it.
42Bastian, you are absolutely correct... I was very lazy when writing the code, so I just made it increase the X. I'll probably work on it some other day when I feel like tackling that issue again :)

On Tuesday, March 17, 2015 at 10:45:36 AM UTC-4, Mason wrote:

Simon Heath

unread,
Mar 17, 2015, 8:51:51 PM3/17/15
to bareme...@googlegroups.com
I have to ask, as someone who's done a lot of custom drawing code
recently and knows how hard it is to make it well... how hard would it
be to just port Cairo?

Simon

On 03/17/2015 02:40 PM, Mason wrote:
> Err, I'm not very good with some aspects of math, so I pretty much
> just googled for and algorithm to compute a circle, line and filled
> circle, and just adapted them for BareMetal OS.
> If you have any links to better algorithms, please send them to me and
> I'll have a look at them.
>
> On Tuesday, March 17, 2015 at 2:23:22 PM UTC-4, 42Bastian wrote:
>
> Mason
>
> > If you're interested, feel free to check it out :)
> > https://github.com/ohnx/libDraw <https://github.com/ohnx/libDraw>
>
> I wonder, why do you use floating point math. For the primitives
> exist
> Bresenham algos which are surely faster.
>
> (Again it is bad that the GFX chips vendors do not provide open
> documents.)
>
> --
> 42Bastian
>
> --
> You received this message because you are subscribed to the Google
> Groups "BareMetal OS" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to baremetal-os...@googlegroups.com
> <mailto:baremetal-os...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

Ian Seyler

unread,
Mar 17, 2015, 8:54:26 PM3/17/15
to bareme...@googlegroups.com, maso...@gmail.com
The size of VideoMemory can be calculated like this:

VideoX * VideoY * (VideoBPP / 4)

The clear_screen() function in 3dstars does a similar calculation.

-Ian

Pablo Hugo Reda

unread,
Mar 17, 2015, 9:26:54 PM3/17/15
to bareme...@googlegroups.com, maso...@gmail.com
Mason

is not C++ is C!!
I spend many years optimice this algos, all integer operation.

Mason

unread,
Mar 18, 2015, 10:35:32 AM3/18/15
to bareme...@googlegroups.com, maso...@gmail.com
Okay, great!
Another question:
How do I allocate memory?
b_mem_allocate appears to take a pointer to a long and a long number, then return another long.
What are these values?

Mason

unread,
Mar 19, 2015, 11:28:13 AM3/19/15
to bareme...@googlegroups.com, maso...@gmail.com
Ha! I finally figured out why malloc and things like that weren't working, I was missing a library...
Added it and now I just use malloc, ignore this question...

Mason X

unread,
Jun 15, 2015, 3:46:22 PM6/15/15
to bareme...@googlegroups.com
I'm not sure...
Actually, it might not be difficult. The requirements would be that BareMetal OS gets all of its "glue" for C functions done, which might not be that easy...
Reply all
Reply to author
Forward
0 new messages