3 ms·
When I first learned C, I did so under DOS, an environment in which you could declare a pointer to video memory, make a magic call, and start drawing graphics.
by JoshTriplett 15y ago
When I first learned C, I did so under DOS, an environment in which you could declare a pointer to video memory, make a magic call, and start drawing graphics. I found that a memorable way to learn pointers. Sadly, doing that in the modern world requires quite a bit more setup.
- zedshaw 15y agoHmmmm, I wonder if you could do that in a similar way...
- cubicle67 15y agoThat's how I was taught assembler. One of our first assignments was to draw a circle on the screen. Second was an etch-a-sketch like drawing programme where you controlled the pixel via kbd. We used int 10h[0] a lot [0] http://en.wikipedia.org/wiki/INT_10H http://en.wikipedia.org/wiki/INT_10H
- angrycoder 15y agoYou can do something similar now using SDL. In fact, unless you are blitting bitmaps or using additional libraries, it is the only way to get stuff on screen. SDL gives you a pointer that corresponds to the video memory and you stick colors into it. Here is a tutorial for using SDL for 'old school' graphics programming: http://sol.gfxile.net/gp/ http://sol.gfxile.net/gp/ Of course this would require the student to install SDL and write a makefile to link it all together. I feel that is something worth covering though, since most books just do a bunch of hand waving when it comes to linking external libraries.
- JoshTriplett 15y agoWhen I said "quite a bit more setup", I had SDL in mind. :) Yes, you can get a raw pointer to a graphics buffer via SDL, but in addition to the extra setup to get a window, you have to make extra calls (such as SDL_Flip or SDL_UpdateRect) to make your changes visible.
- antirez 15y agoThis is how I learned C as well (demo coding), and a book like that makes a lot of sense IMHO: learning C with computer graphics. Now this would probably be SDL based, but as long as the user receives the initial help to get started with a simple Makefile and the calls to get a window, it will be a lot similar to the old times of int 10h. Cheers, Salvatore