"neoakata" <tranderson@...> wrote Thu, 11 Apr 2002 20:24:14 -0000 :
> Taking your advice, I'd like to write this to be as OS independent as
> possible.
> 1) I've written graphics applications for DOS4GW & Windows (and some
> other out of date operating systems) but never linux. I know that
> even doing something as simple as setting up the resolution and
> plotting a single pixel on the screen can be a difficult thing to
> figure out when you are just getting familiar with doing graphics in
> a new environment. Would anyone happen to have a silly little plot a
> pixel program that runs in linux? (or know where I can find some
> code that would help?)
Ok, using the SDL will make this soooooo intricate.
This program will compile & run under unix, windows, macos, beos and even
playstation 2, and will take advantage of most available hardware
accelerations when copying the buffer into video memory.
1st.c:
********************* CUT HERE **********************************
#include <SDL/SDL.h>
unsigned long *buffer = NULL;
unsigned int L,H;
void putpixel(unsigned int x,unsigned int y, unsigned long clr) {
buffer[x+y*L] = clr;
}
int main() {
SDL_Surface *ecran;
char quit = 0;
int i;
L = 640;
H = 480;
SDL_Init( SDL_INIT_VIDEO );
ecran = SDL_SetVideoMode( L,H,32, 0 /*SDL_FULLSCREEN*/ );
buffer = (unsigned long*)ecran->pixels;
memset(ecran->pixels,0xff,640*480*4);
for (i=0; i<200; i++)
putpixel(i,i,0xff00ff);
SDL_Flip( ecran );
while (!quit) {
SDL_Event event;
if ( SDL_PollEvent(&event) )
switch (event.type) {
case SDL_QUIT:
quit = 1;
break;
case SDL_KEYDOWN:
switch (event.key.keysym.sym) {
case SDLK_q:
case SDLK_ESCAPE:
quit = 1;
break;
}
break;
}
}
SDL_Quit();
return 0;
}
********************* CUT HERE **********************************
And you have a window, with graphism, keyboard and window-closing button being
handled.
To compile:
gcc -c -o 1st.o 1st.c
gcc -lSDL 1st.o -o 1st
> 5) In general, for cross platform graphics development, what IS the
> best OS to develop in?
The one you prefer. But for cross-platform, never use VC+: lots of standard
stuff
not supported, and lots of non standard stuff integrated.
For example in my case I stick to Linux, but only because it is my favorite
development
environment.