Coding Graphics in C: SetPixel, LineDraw, Moire and More!

preview_player
Показать описание
Dave takes you on a tour of the C code used to write graphics primitives for the ancient Commodore KIM-1 computer. See how setpixel, linedraw, and more are implemented from first principles.
Рекомендации по теме
Комментарии
Автор

You should definitely do more things like this with how programming works

licksorestockpile
Автор

This brings back a lot of memories. It was like 2000 or 2001 and I was learning C using books and a compiler written in the 80s! (Borland Turbo C/C++ 1.1) I still have a great sense of nostalgia for that blue background with chunky yellow text and seeing functions written in that glorious font with pointers that poke and peek directly into memory and occasionally prodding hardware registers brings back some fond memories. Thanks, Dave!

jamesclark
Автор

Your fluency with bit-shifting and boolean is mesmerizing; a master-class video from you would be solid gold.

drewlarson
Автор

Greetings from San Francisco. I thought there were no time machines, but you just brought me back to 1979. I loved it the first time around, and I'm (almost) ready to break out my Poly88 with a Cromemco Dazzler and write code along with you. Almost... but sanity prevailed. Dave, you are a BAD influence. I can't wait for your next stroll through my faded youth.

greg
Автор

I remember implementing the Bresenham circle algorithm in assembly and also figuring out the math behind it when I was in 8th or 9th grade where I had just learnt the the Pythagorean theorem. It was so awesome :)

mfkman
Автор

Loved this! Man, this takes me back. I still prefer to program in C (not C++) to this day, usually using a GNU compiler which supports the newer versions of C. I remember programming graphics in DOS on my old computer in the 1990s. I wrote my own graphics library much like you have here by accessing A000 etc... as I learned I added more functions to it for lines, some optimized functions for straight lines (I think that used memset commands to set larger amounts at once). I loved those days and the fact that it wasn't done for you. I created a free game called Deluxe Pacman 1 & 2 for DOS, older Windows and modern Windows (last tested on Windows 10) and it is coded entirely using C (no plusses), only it uses the Allegro library (I honestly wish I had done it entirely on my own and never used a library). Good times anyhow.

Oh, and I used to use DJGPP for DOS back then, it handled the memory limitations for you, so no worries about things like long jumps and the like. I believe Quake was written with it. Very nice.

NeilRoy
Автор

You can speed up that Bresenham's implementation considerably by avoiding calls to SETPIXEL. Instead, translate the x, y starting point to a byte address and a mask (as done within SETPIXEL), and within the loop, treat x moves as shifts of that mask (adding/subtracting one to the byte offset if the mask becomes 0), and treat y moves as adjustments (add/subtract BYTESPERROW) of the byte address.

Back in the day (circa 1985 with an EGA/VGA adapter on a PC running MS-DOS) I had an assembly language Bresenham's that was nearly as fast as a NEC 7220 based board.

Also, for a lot of applications (I was doing CAD work at the time), it is well worth the minimal effort to optimize horizontal and vertical lines.

rdwells
Автор

This reminds me so much of when I was a kid programming different early machines that did not have any built in graphics like the early Atari and TRS80. I love it, please make more videos like this one. Thank you very much.

jamesross
Автор

That was awesome! I remember doing this in the early 80's. I have a lot of nostalgia for this and sometimes actually miss it, if you can believe that! More please!

jeffsimkowski
Автор

A few years ago I wrote a graphics primitive library for Arduino driving a 20*10RGB led array. This was used in a series of digital art workshops as part of our National Arts Festival. The best of the art was later displayed on our huge Rgb periodic table display. Each element was about 6x6” . Since the pixels were wired in an odd order I created a translation table to translate x/y to pixel number. Fun times.

DavidtheSwarfer
Автор

Dave, enjoy your podcast. Would like to see you interview the folks who made up the team that created the 6502.

jeffgrill
Автор

Great video!!

I never have to touch low-level programming in my line of work but as time goes on in deepening my appreciation for this technology and the people who both understand it and are willing to share it. Everything is built on top of this! Incredible!

ILostMyOreos
Автор

This is amazing! It also shows up how in previous a programmer have to think twice before using a single byte otherwise they may run out of volatile memory. The code was clean and explanation wad on point. Really great work!

sofiaknyazeva
Автор

Thanks Dave, it really is quite nice to receive a master lesson on such simple graphics outputs. Reminds me of learning Fortran over a night shift so that I could modify a shift trivia quiz to include a graphical image, using ascii characters. Amazing what you learn when you need it! Writing Trev wins with an image of a winners cup, no matter who wins, was the result I famously added to the code! Take that A-shift! Hahaha 🤣

makethingsbetter
Автор

Happy memories of designing a tiny antialiased font to draw text in 256 color SuperVGA. It was for a simple GUI to acquire and show CCD camera data for use in an electrophysiology lab (looking at calcium transients in cells using calcium-sensitive fluorescent dye). Somehow there was enough room on the screen to display the image frame, a histogram and a control panel at the same time. The advantage of whatever mode I used was it had square pixels (so the image frame wasn't distorted) and there were enough colors to represent the range of intensity values coming in from the camera. If I remember right, it was a variable width font with maximum width 6 pixels and a height of 9 pixels. The manual 'antialiasing' was two-tone.

fburton
Автор

Hi Dave, thanks for the great video!
This takes me back to my C64 days. You're absolutely right about the bit pattern for the characters being right to left on a left to right ordered screen memory. Though I never even gave it a second thought at the time, it just made sense since it was writing a byte to memory and that's the order of the bits for a 6502/6510

chrisdixon
Автор

Ah brings back memories getting into assembly on my 6502 atari 800 xl back in 1981 or something... Still up till this day, 40 years later one of the most satisfying periods in my life :P

JPEaglesandKatz
Автор

Really love this Dave! It's so great to draw some wisdom from the older generation of programmers. I'm continually amazed at the kind of fundamentals you develop if you don't spend all your day debugging yaml templating

buttforce
Автор

You're my hero 💙 and all I have been looking for.
Finally now I have a tutorial guide for the idea behind how graphics were designed and implemented.

TheFuture
Автор

This is great. I recently wrote my own graphics API using similar algorithms. I will have to add Moire! Thank you for your channel.

IdleGSE