Esempio n. 1
0
int main( int argc, char* args[] ) 
{
	SDL_Surface *screen; 

	Uint32 width = 640;
	Uint32 height = 480;
	Uint32 bpp = 32;
	Uint32 flags = SDL_HWSURFACE;

	int i; for (i = 1; i < argc; i++) if (!strcasecmp("--fullscreen", args[i])) flags |= SDL_FULLSCREEN;

	if (SDL_Init(SDL_INIT_VIDEO) < 0) {
		fprintf(stderr, "Video initialization failed: %s\n", SDL_GetError());
		exit(-1);
	}

	if ((screen = SDL_SetVideoMode(width, height, bpp, flags)) == 0) {
		fprintf(stderr, "Video mode set failed: %s\n", SDL_GetError());
       	exit(-1);
	}

	SDL_FillRect(screen, NULL, 0x333333);

	prepare_inline_font();
	
/*	infont(SDL_LoadBMP("fonts/oddball6x8.bmp")); */

	incolor(0xFF0000, 0x333333);

	inprint(screen, "Hello World!", 10, 10);

	incolor(0x000000, 0xFFFFFF);

	inprint(screen, "A QUICK BROWN FOX JUMPS OVER A LAZY DOG!", 10, 30);
	inprint(screen, "a quick brown fox jumps over a lazy dog?", 10, 60);
	inprint(screen, "`'.,:;0123456789{}()[]|\\/-+*=!@#$%^&", 10, 90);

	/* Wait for a while */
	for (i = 1000; i > 20; i--) { SDL_Flip(screen); SDL_Delay(10); }

	kill_inline_font();

	SDL_Quit(); 
	return 0; 
}
void drawmandelbrot(SDL_Surface *surface) {
  if (SDL_MUSTLOCK(surface)) {
    SDL_LockSurface(surface);
  }
  Uint32 *pixels = (Uint32 *) surface->pixels;

  for (int i = 0; i < surface->w * surface->h; i++) {
    int y = i / surface->w;
    int x = i % surface->w;

    float complex c = ((3.0f * x / surface->w) - 2.0f)
        + I * ((2.0f * y / surface->h) - 1.0f);

    bool diverges = false;
    float complex z = 0;
    int it;
    for (it = 1; it <= max_it; it++) {
      /* z = z² + c */
      z = cpowf(z, 2) + c;

      /* If |z| ever gets greater than 2, it diverges. */
      if (cabsf(z) > 2) {
        diverges = true;
        break;
      }
    }

    Uint32 color;
    if (diverges) {
      color = outcolor(it);
    } else {
      color = incolor();
    }

    pixels[i] = color;

    /* Update the screen every 10 lines. */
    if (y % 10 == 0 && x == 0) {
      SDL_Flip(surface);
    }
  }

  /* Update the screen a final time. */
  SDL_Flip(surface);
  if (SDL_MUSTLOCK(surface)) {
    SDL_UnlockSurface(surface);
  }
}