Mike
--
Mike Levin
mlev...@comcast.net
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>
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.
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
> 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!
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.
Yep. I'm using the XCode thing at the mo' and lovin' it.
James
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
/* 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);
}
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
I will also include the following CD:
The Macintosh Programmer's C and Object Pascal Workshop, Version 3.2
Bruce Sauls
Raleigh, NC