C programming question
February 15, 2009 8:19 AM   Subscribe

Seeking some direction in learning C for a project.

I have an project I want to work up to, and I am planning on writing it in C.
I have written simple command line programs in C. I have experience in simple shell and perl scripts.
I'll be writing and running this program on an old box running Kubuntu 7.10.
The ultimate project would be similar to an 8bit sprite/tile editor for bin dumps from toys.
I did write a perl script which read in my dump and generated html files as 480 byte snapshots to look for the fullscreen graphics of the toy. This functionally worked, but took time to generate, used alot of space, and was slow to go through results.
I downloaded several actual tile editors and tried my bin dump just to try. I found it of course much better than my method - loaded imediately with a scroll window to scan through quickly. What did not work was they were 8x8, 16x16, not a custom size.
My end goal is to have an ajustable size scroll window which will allow me to identify offset by mouseover/click.
My intial goal is just to write a gui app that renders the bits as pixels in a window.
I am looking for recommendations of online tutorials or books with projects that will build in the gui direction. What I have found seems to just be command line with output going to terminal or file.
posted by sailormouth to Computers & Internet (13 answers total) 2 users marked this as a favorite
 
First, do not stop, do not pass Go, without reading "The C Programming Language" by Kernighan and Ritchie.

Second, here's an online tutorial by Ritchie, the developer of C.
posted by IAmBroom at 9:08 AM on February 15, 2009 [3 favorites]


Processing is a simple language with a C like syntax but not frills about header files etc, and it has a lot of functions for image processing, also mouse interaction.


posted by spacefire at 9:20 AM on February 15, 2009


oops

link
posted by spacefire at 9:22 AM on February 15, 2009


There are a classic series of books called 'Graphics Gems' that cover an amazing range of optimizations for graphic problems. C may or may not be the optimization you need. Some problems just need a better algorithm.
posted by sammyo at 9:23 AM on February 15, 2009


Best answer: I assume you don't need C help (if so, see IAmBroom's post), but rather want to use a GUI toolkit. If you're using C, that's probably Gtk+.

Btw, can't you just render your bin dumps into some image format (very easily doable from eg ImageMagick, which has a Perl interface as well) and use a normal image viewer/editor as your GUI?
posted by themel at 9:27 AM on February 15, 2009


If you don't mind being open-source, I'd go with C++ and Qt. I think you'll get something more rewarding in less time. As a bonus it will be inherently cross-platform, and once learned will likely make it a lot easier for any future ideas you may have.
posted by hungrysquirrels at 10:15 AM on February 15, 2009


Best answer: GTK and Qt, as people have said, are the obvious choices. There are an uncountable number of other things you could look into, like FLTK, wxWidgets, Tk … I lean slightly towards GTK, but Kubuntu is (IRC) based on KDE which is based on Qt, so using Qt might integrate more smoothly with the rest of your desktop.

Whatever toolkit you use probably has an example in the source distro of displaying an image in a scrollable region. Just take that example and display an image created by your code instead. You'll need to read up a bit on how the toolkit represents images, or how it likes to create images from bitmap data, or whatever.
posted by hattifattener at 11:15 AM on February 15, 2009 [1 favorite]


(Also— if you take the route themel suggests, which is what I often do in this situation— the PBM/PGM/PPM family of formats is dead-simple to generate and is supported by most of the multi-image-format-viewer applications on free systems. It's my format of choice if I just want to make a debugging dump of some 2-dimensional data somewhere.)
posted by hattifattener at 11:20 AM on February 15, 2009


I second Kernighan and Ritchie. It's an excellent book both to learn from and to use as a reference later.
posted by Flunkie at 11:30 AM on February 15, 2009


I learned C from K&R and wouldn't recommend it. Yes, it's the ultimate reference, short of the Standard itself; but it's not good at teaching its concepts.

You need K&R if you're serious about C, but for your own sanity: learn from something else.

As others have noted though, this isn't really a "how do I learn C" question; it's "how do I choose and learn a GUI toolkit".
posted by We had a deal, Kyle at 1:49 PM on February 15, 2009


Perl should be able to handle what you want to do (even with a GUI) reasonably timely. I won't argue C isnt much faster than Perl, but it sounds like you need to optimize your code vs changing languages.
posted by SirStan at 2:31 PM on February 15, 2009


Response by poster: Thank you all for the feedback.

Yes, toolkit is ultimately what I am after.
I will look more into gtk and qt. I checked my work computer which has gtk and qt4. gtk works fine, but qt qmake is not working. My work machine would be better and faster, but I have no root access on it. That is why I mentioned the Kubuntu machine I have at home if I needed to install anything.

I will also look into imagemagick.
The perl script I wrote read in the dump from a 256kb chip and generated 547 html files. Not the most efficient for use of space or ease of scanning through the files. But it did show me I could find the graphic data in a binary file. That was for a full screen graphic 480 bytes (64 px/bits x 60 px/bits), but there are graphics that are not full screen. In those 480 byte snapshots the graphics of course did not line up, but I was able to get the offset. I had another script that used the offset to generate a single clean image. There was no issue with that second script.
posted by sailormouth at 3:58 PM on February 15, 2009


FWIW, if you're more comfortable with perl and don't need C for some other reason, GTK can be used from perl (it looks like Qt has a perl binding too but it's not maintained?).
posted by hattifattener at 10:41 PM on February 15, 2009


« Older Never sick a day in your life?   |   What is the name of this 1980's television series? Newer »
This thread is closed to new comments.