What's a simple C programming environment on Mac OS X?

250 views
Skip to first unread message

Michael Levin

unread,
Nov 21, 2003, 6:45:46 PM11/21/03
to
I need the ability to write some simple C code which would create a window
and fill it with dots of different colors (basically, I need to be able to
call plot_dot(x,y,c) where x,y are the coordinates of pixel (x,y) in the
window, and c is the color. I'm happy programming from the shell, using
emacs; I don't need a fancy IDE. I want a nice simple cc compiler, and a
library which can just draw some graphics (I do simple scientific
programming from time to time). I've checked out the Apple developers kit on
their website, and it looks like total overkill for me - I don't need (or
have time to delve into) all the fancy stuff for making cool-looking user
interfaces etc. On the other hand, maybe the basics are easier than I think.
Could someone give me some advice: what's the simplest way to write a simple
C program to draw some color dots on a 2D square of the screen? Do I use the
Apple kit (if so, is there a primer somewhere) or can I just get a C
compiler which would run from the shell (I need executables, maybe for gcc
or something like this)? Any suggestions for a simple graphical library
which can be used? Please cc: any replies to mlev...@comcast.net. Thank you
in advance!!

Mike


--

Mike Levin
mlev...@comcast.net

Miro Jurisic

unread,
Nov 21, 2003, 6:54:35 PM11/21/03
to
In article <BBE40DD8.C43%mlev...@comcast.net>,
Michael Levin <mlev...@comcast.net> wrote:

I would recommend using OpenGL and its GLUT toolkit, which lets you create
simple applications with a window to draw in.

hth

meeroh

--
If this message helped you, consider buying an item
from my wish list: <http://web.meeroh.org/wishlist>

John Coyote

unread,
Nov 21, 2003, 7:30:36 PM11/21/03
to
In article <BBE40DD8.C43%mlev...@comcast.net>, Michael Levin
<mlev...@comcast.net> wrote:

the apple developer sw is free, last time i checked anyway.
when you install it, it also installs all the traditional
command line tools like cc (gcc), linker, standard libraries, etc.
you also want to make sure you install the BSD subsystem so
you get all the man entries.

Alan Gauld

unread,
Nov 22, 2003, 4:26:49 AM11/22/03
to
On Fri, 21 Nov 2003 23:45:46 GMT, Michael Levin
<mlev...@comcast.net> wrote:
> I need the ability to write some simple C code which would create a window
> and fill it with dots of different colors

Can I ask why it needs to be C code?
While it is possible to do what you want in C it sounds like a
higher level language like Tcl or Python (andm maybe even
Applescript) would be much easier and faster to use.
Unless you are doing a ton of number crunching as well C is an
awful lot of hard work to throw up a canvas and draw some
graphics!

> programming from time to time). I've checked out the Apple developers kit on
> their website, and it looks like total overkill for me


If your prograqms are similar creating one template and then copy
and modifying it shouldn't be too hard. But the Dev kit does make
life easy even for plain C programming.

> Could someone give me some advice: what's the simplest way to write a simple
> C program to draw some color dots on a 2D square of the screen?

The simplest way is to join the program and use the Apple tools.
But you can do it by hand if you really want.

> can I just get a C compiler which would run from the shell
> (I need executables, maybe for gcc or something like this)?

gcc and the other tools are all there, just open a terminal
session, start vi or emacs and hack away. You need to find the
right libraries and include them of course but they too are there
to use.

But for casual use I'd almost never use C, it's the kind of task
scripting languages were made for!

Alan G.
Author of the Learn to Program website
http://www.freenetpages.co.uk/hp/alan.gauld

Michael Levin

unread,
Nov 22, 2003, 6:46:29 AM11/22/03
to
On 11/22/03 4:26 AM, in article 3fbf2a6e....@news.blueyonder.co.uk,
"Alan Gauld" <alan....@btinternet.com> wrote:

> Can I ask why it needs to be C code?
> While it is possible to do what you want in C it sounds like a
> higher level language like Tcl or Python (andm maybe even
> Applescript) would be much easier and faster to use.
> Unless you are doing a ton of number crunching as well C is an
> awful lot of hard work to throw up a canvas and draw some
> graphics!

I already have a bunch of C code which does quite a bit of number
crunching (I'm moving from a different platform). I'd rather not change all
of it...

> The simplest way is to join the program and use the Apple tools.
> But you can do it by hand if you really want.

is this the Xcode package, or have I got the wrong thing?

Thanks for the help!

Mike Kluev

unread,
Nov 22, 2003, 7:00:10 AM11/22/03
to

The question about IDE aside (I would recommend using "free" Xcode),
here is the basic app that draws pixel.

#include <Carbon.h>
int main(void)
{
WindowRef window;
Rect r = { 10, 50, 300, 300 };
RGBColor color = { 0xFFFF, 0, 0 }

window = NewCWindow(NULL, &r, "\pTitle", true, 0, (WindowPtr)-1, 0, 0);
SetPort(GetWindowPort(window));
SetCPixel(100, 100, &color);
QDFlushPortBuffer(GetWindowPort(window), NULL);
while (!Button()) {}
return 0;
}

--
Mike Kluev

PS. Remove "-DELETE-." part of my e-mail address to reply.

James Hayward

unread,
Nov 23, 2003, 11:42:27 AM11/23/03
to
>>The simplest way is to join the program and use the Apple tools.
>>But you can do it by hand if you really want.
>
>
> is this the Xcode package, or have I got the wrong thing?
>

Yep. I'm using the XCode thing at the mo' and lovin' it.

James

rob shaw

unread,
Nov 24, 2003, 9:18:21 AM11/24/03
to
In article <BBE40DD8.C43%mlev...@comcast.net>, Michael Levin
<mlev...@comcast.net> wrote:

Here's how to compile and link programs with quickdraw calls without
using a fancy IDE. I don't know how you find this kind of stuff out
other than asking on news groups...

cc tst.c -o tst -framework Carbon

Here's the test program posted earlier, with a few typos fixed...

#include <Carbon/Carbon.h>
int main(void)
{
WindowRef window;
Rect r = { 40, 50, 300, 300 };


RGBColor color = { 0xFFFF, 0, 0 };

window = NewCWindow(NULL, &r, 0, true, 0, (WindowPtr)-1, 0, 0);


SetPort(GetWindowPort(window));
SetCPixel(100, 100, &color);
QDFlushPortBuffer(GetWindowPort(window), NULL);
while (!Button()) {}
return 0;
}

rob

rob shaw

unread,
Nov 24, 2003, 9:39:59 AM11/24/03
to
As long as I'm complaining about how hard it can be to find out
how to do simple stuff on a mac, here's how to write directly to the screen.
Some of us actually like to write our own (very fast) graphics
without dealing with the (#$%^&*!) GUI.

/* write directly to screen... */
/* scribble to first 100 rows... */

#include <Carbon/Carbon.h>

char *getfb(short *rowl,short *nrows,short *depth,short *rowbytes);

main()
{
short rowl,nrows,depth,rowbytes;
char *fb,val;
long i,j,jump;

fb = getfb(&rowl,&nrows,&depth,&rowbytes);
rowbytes &= 0x7fff;
jump = rowbytes - rowl*depth;

for(j=0;j<100;j++)
{
for(i=0;i<rowl*depth;i++)
*fb++ = val++;
fb += jump;
}
}

char *getfb(short *rowl,short *nrows,short *depth,short *rowbytes)
{
GDHandle theGDList;
Ptr theBase;

theGDList = GetDeviceList();
theBase = (*(*theGDList)->gdPMap)->baseAddr;
*rowl = (*(*theGDList)->gdPMap)->bounds.right;
*nrows = (*(*theGDList)->gdPMap)->bounds.bottom;
*depth = (*(*theGDList)->gdPMap)->pixelSize;
*rowbytes = (*(*theGDList)->gdPMap)->rowBytes;
return(theBase);
}

Toby Thain

unread,
Nov 28, 2003, 9:02:56 PM11/28/03
to
Michael Levin <mlev...@comcast.net> wrote in message news:<BBE4B6C5.1403%mlev...@comcast.net>...


If you're working in and targeting OS X, then Xcode (or gcc as other
posters suggest) would be ideal. Otherwise, MPW (free download from
http://developer.apple.com/tools/mpw-tools/ ) is an excellent command
line-oriented development environment. It can create any kind of
Classic executable, and Carbon executables for OS X.

The example posted by Mike Kluev would be easily built under MPW. Note
that using SetCPixel() in this way would be very slow if you were
plotting many pixels. In that instance, a much faster method (with
Carbon) would be an offscreen GWorld, set memory directly to plot
pixels, then CopyBits the offscreen PixMap into your window.

Toby

bsa...@bellsouth.net

unread,
Mar 6, 2004, 12:14:41 PM3/6/04
to
I have a box of MPW manuals that I would like for someone who might use them
to have.
The manuals are all white 3-ring binders with slip in spine and front cover
labels.
The box weighs 24 lbs. The price is $10 + shipping.
The 6 manuals are:
MPW: Macintosh Programmer's Workshop Development Environment, Volume 1,
Version 3.0
MPW: Macintosh Programmer's Workshop Development Environment, Volume 2,
Version 3.0
MPW Assembler: Macintosh Programmer's Workshop Assembler, Version 3.0
MPW C: Macintosh Programmer's Workshop C, Version 3.0
SADE: Symbolic Application Debugging Environment, Version 1.0
MacsBug, Version 6.0

I will also include the following CD:
The Macintosh Programmer's C and Object Pascal Workshop, Version 3.2

Bruce Sauls
Raleigh, NC

Reply all
Reply to author
Forward
0 new messages