/* Set up and enable texturing on our object */ static void setup_xpm_texture (ModeInfo *mi, const unsigned char *data, unsigned long size) { XImage *image = image_data_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi), data, size); char buf[1024]; clear_gl_error(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* iOS invalid enum: glPixelStorei(GL_UNPACK_ROW_LENGTH, image->width); */ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image->data); sprintf (buf, "builtin texture (%dx%d)", image->width, image->height); check_gl_error(buf); XDestroyImage (image); }
/* Set up and enable texturing on our object */ static void setup_xpm_texture (ModeInfo *mi, char **xpm_data) { XImage *image = xpm_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi), MI_COLORMAP (mi), xpm_data); char buf[1024]; clear_gl_error(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* iOS invalid enum: glPixelStorei(GL_UNPACK_ROW_LENGTH, image->width); */ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, image->data); sprintf (buf, "builtin texture (%dx%d)", image->width, image->height); check_gl_error(buf); }
/*=================== Load Texture =========================================*/ static void LoadTexture(ModeInfo * mi, char **fn, int t_num) { #if defined( I_HAVE_XPM ) atunnelstruct *sa = &Atunnel[MI_SCREEN(mi)]; XImage *teximage; /* Texture data */ if ((teximage = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), fn)) == None) { (void) fprintf(stderr, "Error reading the texture.\n"); glDeleteTextures(1, &sa->texture[t_num]); do_texture = False; #ifdef STANDALONE exit(0); #else return; #endif } #ifdef HAVE_GLBINDTEXTURE glBindTexture(GL_TEXTURE_2D, sa->texture[t_num]); #endif /* HAVE_GLBINDTEXTURE */ glPixelStorei(GL_UNPACK_ALIGNMENT, 4); clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, teximage->width, teximage->height, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, teximage->data); check_gl_error("texture"); /* Texture parameters, LINEAR scaling for better texture quality */ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); XDestroyImage(teximage); #else /* !I_HAVE_XPM */ do_texture = False; #endif /* !I_HAVE_XPM */ }
static Bool LoadGLTextures(ModeInfo *mi) { blocktube_configuration *lp = &lps[MI_SCREEN(mi)]; Bool status; status = True; glGenTextures(1, &lp->envTexture); glBindTexture(GL_TEXTURE_2D, lp->envTexture); lp->texti = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), blocktube_xpm); if (!lp->texti) { status = False; } else { glPixelStorei(GL_UNPACK_ALIGNMENT,1); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, lp->texti->width, lp->texti->height, 0, GL_RGBA, GL_UNSIGNED_INT_8_8_8_8_REV, lp->texti->data); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); } return status; }
/* Set up and enable texturing on our object */ static void setup_xpm_texture (ModeInfo *mi, char **xpm_data) { XImage *image = xpm_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi), MI_COLORMAP (mi), xpm_data); char buf[1024]; clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, image->data); sprintf (buf, "builtin texture (%dx%d)", image->width, image->height); check_gl_error(buf); /* setup parameters for texturing */ glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); }
void init_toneclock(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i, size_hour, istart; toneclockstruct *tclock; /* initialize */ if (toneclocks == NULL) { if ((toneclocks = (toneclockstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (toneclockstruct))) == NULL) return; } tclock = &toneclocks[MI_SCREEN(mi)]; tclock->mi = mi; if (tclock->gc == None) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE tclock->fg = MI_FG_PIXEL(mi); tclock->bg = MI_BG_PIXEL(mi); #endif tclock->blackpixel = MI_BLACK_PIXEL(mi); tclock->whitepixel = MI_WHITE_PIXEL(mi); if ((tclock->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_toneclock(display, tclock); return; } XSetWindowColormap(display, window, tclock->cmap); (void) XParseColor(display, tclock->cmap, "black", &color); (void) XAllocColor(display, tclock->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, tclock->cmap, "white", &color); (void) XAllocColor(display, tclock->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, tclock->cmap, background, &color); (void) XAllocColor(display, tclock->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, tclock->cmap, foreground, &color); (void) XAllocColor(display, tclock->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif tclock->colors = (XColor *) NULL; tclock->ncolors = 0; } if ((tclock->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_toneclock(display, tclock); return; } } /* Clear Display */ MI_CLEARWINDOW(mi); tclock->painted = False; XSetFunction(display, tclock->gc, GXxor); /*Set up toneclock data */ if (MI_IS_FULLRANDOM(mi)) { if (NRAND(10)) tclock->original = False; else tclock->original = True; } else { tclock->original = original; } tclock->direction = (LRAND() & 1) ? 1 : -1; tclock->win_width = MI_WIDTH(mi); tclock->win_height = MI_HEIGHT(mi); if (tclock->hour != NULL) free_hour(tclock); if ( tclock->original ) { tclock->num_hour = 12; } else { tclock->num_hour = MI_COUNT(mi); } tclock->x0 = tclock->win_width / 2; tclock->y0 = tclock->win_height / 2; if (tclock->num_hour == 0) { tclock->num_hour = DEF_NUM_hour; } else if (tclock->num_hour < 0) { tclock->num_hour = NRAND(-tclock->num_hour) + 1; } if ( tclock->num_hour < 12 ) istart = NRAND( 12 - tclock->num_hour ); else istart = 0; if ((tclock->hour = (toneclockhour *) calloc(tclock->num_hour, sizeof (toneclockhour))) == NULL) { free_toneclock(display, tclock); return; } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { /* Set up colour map */ if (tclock->colors != NULL) { if (tclock->ncolors && !tclock->no_colors) free_colors(display, tclock->cmap, tclock->colors, tclock->ncolors); free(tclock->colors); tclock->colors = (XColor *) NULL; } tclock->ncolors = MI_NCOLORS(mi); if (tclock->ncolors < 2) tclock->ncolors = 2; if (tclock->ncolors <= 2) tclock->mono_p = True; else tclock->mono_p = False; if (tclock->mono_p) tclock->colors = (XColor *) NULL; else if ((tclock->colors = (XColor *) malloc(sizeof (*tclock->colors) * (tclock->ncolors + 1))) == NULL) { free_toneclock(display, tclock); return; } tclock->cycle_p = has_writable_cells(mi); if (tclock->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) tclock->cycle_p = False; else tclock->cycle_p = True; } else { tclock->cycle_p = cycle_p; } } if (!tclock->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, True, &tclock->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, &tclock->cycle_p); else make_smooth_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tclock->cmap, tclock->colors, &tclock->ncolors, True, &tclock->cycle_p); } XInstallColormap(display, tclock->cmap); if (tclock->ncolors < 2) { tclock->ncolors = 2; tclock->no_colors = True; } else tclock->no_colors = False; if (tclock->ncolors <= 2) tclock->mono_p = True; if (tclock->mono_p) tclock->cycle_p = False; } #ifndef NO_DBUF if (tclock->dbuf != None) XFreePixmap(display, tclock->dbuf); tclock->dbuf = XCreatePixmap(display, window, tclock->win_width, tclock->win_height, MI_DEPTH(mi)); /* Allocation checked */ if (tclock->dbuf != None) { XGCValues gcv; gcv.foreground = 0; gcv.background = 0; gcv.graphics_exposures = False; gcv.function = GXcopy; if (tclock->dbuf_gc != None) XFreeGC(display, tclock->dbuf_gc); if ((tclock->dbuf_gc = XCreateGC(display, (Drawable) tclock->dbuf, GCForeground | GCBackground | GCGraphicsExposures | GCFunction, &gcv)) == None) { XFreePixmap(display, tclock->dbuf); tclock->dbuf = None; } else { XFillRectangle(display, (Drawable) tclock->dbuf, tclock->dbuf_gc, 0, 0, tclock->win_width, tclock->win_height); /*XSetBackground(display, MI_GC(mi), MI_BLACK_PIXEL(mi)); XSetFunction(display, MI_GC(mi), GXcopy);*/ } } #endif tclock->angle = NRAND(360) * PI_RAD; tclock->velocity = (NRAND(7) - 3) * PI_RAD; size_hour = MIN( tclock->win_width , tclock->win_height) / 3; tclock->pulsating = False; tclock->moving = False; tclock->anglex = 0.0; tclock->angley = 0.0; tclock->fill = 0; tclock->radius = size_hour; tclock->max_radius =0.0; if ( ( !tclock->original && NRAND( 15 ) == 3 ) || tclock->num_hour > 12 ) tclock->randomhour = True; else tclock->randomhour = False; if ( !tclock->original && tclock->win_width > 20 ) { if ( abs( MI_SIZE(mi) ) > size_hour ) { if ( MI_SIZE( mi ) < 0 ) { size_hour = -size_hour; } } else { size_hour = MI_SIZE(mi); } if ( size_hour < 0 ) { tclock->radius = MIN(NRAND( size_hour - 10) + 10, tclock->radius ); } else { tclock->radius = MIN( size_hour , tclock->radius ); } if ( MI_IS_FULLRANDOM( mi ) ) { if ( NRAND(2) ) tclock->pulsating = True; else tclock->pulsating = False; tclock->fill = NRAND( 101 ); } else { tclock->pulsating = pulsating; tclock->fill = fill; } } tclock->phase = 0.0; if ( tclock->pulsating ) tclock->ph_vel = (NRAND(7) - 3) * PI_RAD; for (i = 0; i < tclock->num_hour; i++) { toneclockhour *hour0; hour0 = &tclock->hour[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (tclock->ncolors > 2) hour0->colour = NRAND(tclock->ncolors - 2) + 2; else hour0->colour = 1; /* Just in case */ XSetForeground(display, tclock->gc, tclock->colors[hour0->colour].pixel); } else { if (MI_NPIXELS(mi) > 2) hour0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else hour0->colour = 1; /*Xor'red so WHITE may not be appropriate */ XSetForeground(display, tclock->gc, hour0->colour); } hour0->angle = NRAND(360) * PI_RAD; hour0->velocity = (NRAND(7) - 3) * PI_RAD; hour0->radius = tclock->radius / 5.0; tclock->max_radius = MAX( tclock->max_radius , hour0->radius ); hour0->num_point = 12; hour0->num_point1 = 16; if ( tclock->randomhour ) { int j; hour0->point_numbers = tclock->hexadecimal_clock + i * hour0->num_point1; if ( NRAND( 14 ) == 4 ) { for (j = 0; j < ( hour0->num_point1 / 4 ) - 1 ; j++) { hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 1 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 ) + 1; } hour0->point_numbers[ hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 1 + hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 2 + hour0->num_point1 / 4 ] = 1; hour0->point_numbers[ 3 + hour0->num_point1 / 4 ] = 1; } else { for (j = 0; j < hour0->num_point1 / 4 ; j++) { hour0->point_numbers[ j * 4 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 1 ] = hour0->point_numbers[ j * 4 ]; hour0->point_numbers[ j * 4 + 2 ] = NRAND( 12 ) + 1; hour0->point_numbers[ j * 4 + 3 ] = NRAND( 12 ) + 1; } } } else hour0->point_numbers = original_clock[i+istart]; if ( NRAND( 100 ) >= tclock->fill ) hour0->draw = True; else hour0->draw = False; #ifdef NO_DBUF { int x0 , y0; x0 = (int) (tclock->radius * sin( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->x0 + tclock->a_x * sin( tclock->anglex ) ); y0 = (int) (tclock->radius * cos( -tclock->angle - PI_RAD * i * 360.0 / tclock->num_hour ) * 0.5 * ( 1 + cos( tclock->phase ) ) + tclock->y0 + tclock->a_y * sin( tclock->angley ) ); toneclock_drawhour(mi , hour0 , x0 , y0 ); } #endif } tclock->a_x = 0; tclock->a_y = 0; if ( !tclock->original && tclock->win_width > 20 ) { if ( tclock->radius < MIN( tclock->win_width , tclock->win_height) / 4 ) { if ( MI_IS_FULLRANDOM( mi ) ) { if ( NRAND(2) ) tclock->moving = True; } else { tclock->moving = move_clock; } if ( tclock->moving ) { tclock->a_x = (int) floor( ( tclock->win_width / 2 ) - 1.05 * ( tclock->radius + tclock->max_radius ) ); tclock->a_y = (int) floor( ( tclock->win_height / 2 ) - 1.05 * ( tclock->radius + tclock->max_radius ) ); tclock->vx = (NRAND(15) - 7) * PI_RAD; tclock->vy = (NRAND(15) - 7) * PI_RAD; } } } XFlush(display); XSetFunction(display, tclock->gc, GXcopy); }
/* Create a texture in OpenGL. First an image is loaded and stored in a raster buffer, then it's */ static void Create_Texture(ModeInfo *mi, const char *filename) { int height, width; GLubyte *image; int format; if ( !strncmp(filename, "BUILTIN", 7)) { BUILTIN: image = Generate_Image(&width, &height, &format); } else { XImage *ximage = file_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi), filename); if (! ximage) goto BUILTIN; image = (GLubyte *) ximage->data; width = ximage->width; height = ximage->height; format = GL_RGBA; } /* GL_MODULATE or GL_DECAL depending on what you want */ glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* perhaps we can edge a bit more speed at the expense of quality */ glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); if (do_texture_quality) { /* with texture_quality, the min and mag filters look *much* nice but are *much* slower */ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); } else { /* default is to do it quick and dirty */ /* if you have mipmaps turned on, but not texture quality, nothing will happen! */ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); } /* mipmaps make the image look much nicer */ if (do_mipmap) { int status; clear_gl_error(); status = gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, format, GL_UNSIGNED_BYTE, image); if (status) { const char *s = (char *) gluErrorString (status); fprintf (stderr, "%s: error mipmapping %dx%d texture: %s\n", progname, width, height, (s ? s : "(unknown)")); exit (1); } check_gl_error("mipmapping"); } else { clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, format, width, height, 0, format, GL_UNSIGNED_BYTE, image); check_gl_error("texture"); } }
/* initialise textures */ static void inittextures(ModeInfo * mi) { sballsstruct *sb = &sballs[MI_SCREEN(mi)]; #if defined( I_HAVE_XPM ) if (do_texture) { glGenTextures(1, &sb->backid); #ifdef HAVE_GLBINDTEXTURE glBindTexture(GL_TEXTURE_2D, sb->backid); #endif /* HAVE_GLBINDTEXTURE */ sb->btexture = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), sball_bg); if (!(sb->btexture)) { (void) fprintf(stderr, "Error reading the background texture.\n"); glDeleteTextures(1, &sb->backid); do_texture = False; sb->faceid = 0; /* default textures */ sb->backid = 0; return; } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sb->btexture->width, sb->btexture->height, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, sb->btexture->data); check_gl_error("texture"); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glGenTextures(1, &sb->faceid); #ifdef HAVE_GLBINDTEXTURE glBindTexture(GL_TEXTURE_2D, sb->faceid); #endif /* HAVE_GLBINDTEXTURE */ sb->ftexture = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), sball); if (!(sb->ftexture)) { (void) fprintf(stderr, "Error reading the face texture.\n"); glDeleteTextures(1, &sb->faceid); sb->faceid = 0; return; } glPixelStorei(GL_UNPACK_ALIGNMENT, 1); clear_gl_error(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, sb->ftexture->width, sb->ftexture->height, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, sb->ftexture->data); check_gl_error("texture"); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); } else { sb->faceid = 0; /* default textures */ sb->backid = 0; } #else /* !I_HAVE_XPM */ do_texture = False; sb->faceid = 0; /* default textures */ sb->backid = 0; #endif /* !I_HAVE_XPM */ }
void init_mandelbrot(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); mandelstruct *mp; if (mandels == NULL) { if ((mandels = (mandelstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (mandelstruct))) == NULL) return; } mp = &mandels[MI_SCREEN(mi)]; mp->mi = mi; mp->screen_width = MI_WIDTH(mi); mp->screen_height = MI_HEIGHT(mi); mp->backwards = (Bool) (LRAND() & 1); if (mp->backwards) mp->column = mp->screen_width - 1; else mp->column = 0; mp->power = NRAND(3) + MINPOWER; mp->counter = 0; MI_CLEARWINDOW(mi); if (MI_IS_FULLRANDOM(mi)) { mp->binary = (Bool) (LRAND() & 1); mp->dem = (Bool) (LRAND() & 1); mp->interior = NRAND(interior_size); #if 0 /* too slow */ mp->pow = (NRAND(5) == 0); mp->sin = (NRAND(5) == 0); #endif } else { mp->binary = binary_p; mp->dem = dem_p; if (index_p) { mp->interior = INDEX; } else if(alpha_p) { mp->interior = ALPHA; } else if(lyap_p) { mp->interior = LYAPUNOV; } else { mp->interior = NONE; } mp->pow = pow_p; mp->sin = sin_p; } mp->reptop = 300; /* these could be tuned a little closer, but the selection ** process throws out the chaf anyway, it just takes slightly ** longer */ mp->extreme_ul.real = -3.0; mp->extreme_ul.imag = -3.0; mp->extreme_lr.real = 3.0; mp->extreme_lr.imag = 3.0; if (!mp->gc) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE mp->fg = MI_FG_PIXEL(mi); mp->bg = MI_BG_PIXEL(mi); #endif mp->blackpixel = MI_BLACK_PIXEL(mi); mp->whitepixel = MI_WHITE_PIXEL(mi); if ((mp->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_mandelbrot(display, mp); return; } XSetWindowColormap(display, window, mp->cmap); (void) XParseColor(display, mp->cmap, "black", &color); (void) XAllocColor(display, mp->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, mp->cmap, "white", &color); (void) XAllocColor(display, mp->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, mp->cmap, background, &color); (void) XAllocColor(display, mp->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, mp->cmap, foreground, &color); (void) XAllocColor(display, mp->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif mp->colors = (XColor *) NULL; mp->ncolors = 0; } if ((mp->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_mandelbrot(display, mp); return; } } MI_CLEARWINDOW(mi); /* Set up colour map */ mp->direction = (LRAND() & 1) ? 1 : -1; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (mp->colors != NULL) { if (mp->ncolors && !mp->no_colors) free_colors(display, mp->cmap, mp->colors, mp->ncolors); free(mp->colors); mp->colors = (XColor *) NULL; } mp->ncolors = MI_NCOLORS(mi); if (mp->ncolors < 2) mp->ncolors = 2; if (mp->ncolors <= 2) mp->mono_p = True; else mp->mono_p = False; if (mp->mono_p) mp->colors = (XColor *) NULL; else if ((mp->colors = (XColor *) malloc(sizeof (*mp->colors) * (mp->ncolors + 1))) == NULL) { free_mandelbrot(display, mp); return; } mp->cycle_p = has_writable_cells(mi); if (mp->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) mp->cycle_p = False; else mp->cycle_p = True; } else { mp->cycle_p = cycle_p; } } if (!mp->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif mp->cmap, mp->colors, &mp->ncolors, True, True, &mp->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif mp->cmap, mp->colors, &mp->ncolors, True, &mp->cycle_p); else make_smooth_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif mp->cmap, mp->colors, &mp->ncolors, True, &mp->cycle_p); } XInstallColormap(display, mp->cmap); if (mp->ncolors < 2) { mp->ncolors = 2; mp->no_colors = True; } else mp->no_colors = False; if (mp->ncolors <= 2) mp->mono_p = True; if (mp->mono_p) mp->cycle_p = False; } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (mp->mono_p) { mp->cur_color = MI_BLACK_PIXEL(mi); } } Select(&mp->extreme_ul,&mp->extreme_lr, mp->screen_width,mp->screen_height, (int) mp->power,mp->reptop, mp->pow, mp->sin, &mp->ul,&mp->lr); }
/* initialise textures */ static void inittextures(ModeInfo * mi) { firestruct *fs = &fire[MI_SCREEN(mi)]; #ifdef HAVE_XPM if (do_texture) { glGenTextures(1, &fs->groundid); #ifdef HAVE_GLBINDTEXTURE glBindTexture(GL_TEXTURE_2D, fs->groundid); #endif /* HAVE_GLBINDTEXTURE */ if ((fs->gtexture = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), ground)) == None) { (void) fprintf(stderr, "Error reading the ground texture.\n"); glDeleteTextures(1, &fs->groundid); do_texture = False; fs->groundid = 0; fs->treeid = 0; return; } glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fs->gtexture->width, fs->gtexture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, fs->gtexture->data); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); if (fs->num_trees) { glGenTextures(1, &fs->treeid); #ifdef HAVE_GLBINDTEXTURE glBindTexture(GL_TEXTURE_2D,fs->treeid); #endif /* HAVE_GLBINDTEXTURE */ if ((fs->ttexture = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), tree)) == None) { (void)fprintf(stderr,"Error reading tree texture.\n"); glDeleteTextures(1, &fs->treeid); fs->treeid = 0; fs->num_trees = 0; return; } glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, fs->ttexture->width, fs->ttexture->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, fs->ttexture->data); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE); } } else { fs->groundid = 0; /* default textures */ fs->treeid = 0; } #else /* !HAVE_XPM */ do_texture = False; fs->groundid = 0; /* default textures */ fs->treeid = 0; #endif /* !HAVE_XPM */ }
ENTRYPOINT void init_tentacles (ModeInfo *mi) { tentacles_configuration *tc; int wire = MI_IS_WIREFRAME(mi); int i; if (!tcs) { tcs = (tentacles_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (tentacles_configuration)); if (!tcs) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } } tc = &tcs[MI_SCREEN(mi)]; tc->glx_context = init_GL(mi); reshape_tentacles (mi, MI_WIDTH(mi), MI_HEIGHT(mi)); if (!wire) { GLfloat amb[4] = {0.0, 0.0, 0.0, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {0.0, 1.0, 1.0, 1.0}; glLightfv(GL_LIGHT0, GL_POSITION, light_pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); } if (!wire && !cel_p) { glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); } tc->trackball = gltrackball_init (False); tc->left_p = !(random() % 5); if (arg_segments < 2) arg_segments = 2; if (arg_slices < 3) arg_slices = 3; if (arg_thickness < 0.1) arg_thickness = 0.1; if (arg_wiggliness < 0) arg_wiggliness = 0; if (arg_wiggliness > 1) arg_wiggliness = 1; if (arg_flexibility < 0) arg_flexibility = 0; if (arg_flexibility > 1) arg_flexibility = 1; parse_color (mi, "tentacleColor", arg_color, tc->tentacle_color); parse_color (mi, "stripeColor", arg_stripe, tc->stripe_color); parse_color (mi, "suckerColor", arg_sucker, tc->sucker_color); /* Black outlines for light colors, white outlines for dark colors. */ if (tc->tentacle_color[0] + tc->tentacle_color[1] + tc->tentacle_color[2] < 0.4) tc->outline_color[0] = 1; tc->outline_color[1] = tc->outline_color[0]; tc->outline_color[2] = tc->outline_color[0]; tc->outline_color[3] = 1; for (i = 0; i < MI_COUNT(mi); i++) move_tentacle (make_tentacle (mi, i, MI_COUNT(mi))); if (wire) texture_p = cel_p = False; if (cel_p) texture_p = False; if (texture_p || cel_p) { glGenTextures(1, &tc->texid); # ifdef HAVE_GLBINDTEXTURE glBindTexture ((cel_p ? GL_TEXTURE_1D : GL_TEXTURE_2D), tc->texid); # endif tc->texture = xpm_to_ximage (MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), (cel_p ? grey_texture : scales)); if (!tc->texture) texture_p = cel_p = False; } if (texture_p) { glPixelStorei (GL_UNPACK_ALIGNMENT, 1); clear_gl_error(); glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, tc->texture->width, tc->texture->height, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, tc->texture->data); check_gl_error("texture"); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_2D); } else if (cel_p) { clear_gl_error(); glTexImage1D (GL_TEXTURE_1D, 0, GL_RGBA, tc->texture->width, 0, GL_RGBA, /* GL_UNSIGNED_BYTE, */ GL_UNSIGNED_INT_8_8_8_8_REV, tc->texture->data); check_gl_error("texture"); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_REPEAT); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnable(GL_TEXTURE_1D); glHint (GL_LINE_SMOOTH_HINT, GL_NICEST); glEnable (GL_LINE_SMOOTH); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable (GL_BLEND); /* Dark gray instead of black, so the outlines show up */ glClearColor (0.13, 0.13, 0.13, 1.0); } compute_unit_torus (mi, 0.5, MAX(5, arg_slices/6), MAX(9, arg_slices/3)); }
ENTRYPOINT void init_soma (ModeInfo *mi) { int loop; int colorincrement; GLfloat fogColor[4] = {0., 0., 0., 1.}; GLfloat pos[4] = {0.0, 1.0, 1.0, 0.0}; GLfloat amb[4] = {0.2, 0.2, 0.2, 1.0}; GLfloat dif[4] = {1.0, 1.0, 1.0, 1.0}; GLfloat spc[4] = {0.4, 0.4, 0.4, 1.0}; GLfloat shininess[] = {75.}; GLfloat specular[] = {1., 1., 1., 1.}; soma_configuration *lp; if (!lps) { lps = (soma_configuration *) calloc (MI_NUM_SCREENS(mi), sizeof (soma_configuration)); if (!lps) { fprintf(stderr, "%s: out of memory\n", progname); exit(1); } lp = &lps[MI_SCREEN(mi)]; } lp = &lps[MI_SCREEN(mi)]; lp->glx_context = init_GL(mi); lp->currentfigure = malloc (sizeof (figure)); lp->basefigure = malloc (sizeof (figure)); lp->fduration = ((duration > 0 && duration <= 5000) ? duration : 500); lp->cduration = ((colorchangerate > 0 && colorchangerate <= 1000) ? colorchangerate: 10); lp->tduration = ((changerate > 0 && changerate <= 500) ? changerate : 100); lp->viewangle = 0.; lp->vanglestep = ((spinrate >= -100 && spinrate <= 100) ? (spinrate / 500.0) : 0.02); if (do_clockwise) lp->vanglestep *= -1; lp->dstate = exploding; makedlists(lp->piecedlists); if(!MI_IS_MONO(mi)) { lp->numcolors = ((ncolors > 0 && ncolors < 2049) ? ncolors : 256); lp->colors = calloc ( lp->numcolors, sizeof (*lp->colors)); make_smooth_colormap (MI_DISPLAY(mi),MI_VISUAL(mi), MI_COLORMAP(mi), lp->colors, &lp->numcolors, False, 0, True); } if( (MI_IS_MONO(mi)) || (lp->numcolors < 1)) { /* GLfloat white[] = {1., 1., 1., 1.}; */ lp->numcolors = 1; lp->colors = calloc (1, sizeof (*lp->colors)); lp->colors[0].pixel = MI_WHITE_PIXEL(mi); XQueryColor( MI_DISPLAY(mi), MI_COLORMAP(mi), &lp->colors[0]); /* glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, white); */ } colorincrement = (int)lp->numcolors / 7; for (loop = 1; loop < 8; loop++) { if (do_multicolors && lp->numcolors > 6) { lp->colorindices[loop] = colorincrement * loop; } else { lp->colorindices[loop] = 0; } } lp->ftimer = lp->ctimer = 1; if (lp->numcolors < 2) reset_color(lp, lp->currentfigure); glEnable(GL_FOG); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_DENSITY, 0.50); glHint(GL_FOG_HINT, GL_NICEST); glFogf(GL_FOG_START, 15); glFogf(GL_FOG_END, 25); glFogfv(GL_FOG_COLOR, fogColor); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); glCullFace(GL_BACK); glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glClearDepth(1.0f); glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightfv(GL_LIGHT0, GL_AMBIENT, amb); glLightfv(GL_LIGHT0, GL_DIFFUSE, dif); glLightfv(GL_LIGHT0, GL_SPECULAR, spc); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT, GL_SPECULAR, specular); glMaterialfv(GL_FRONT, GL_SHININESS, shininess); handleGLerrors("init"); reshape_soma(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); glFlush(); }
void init_tik_tak(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); int i, max_objects, size_object; tik_takstruct *tiktak; /* initialize */ if (tik_taks == NULL) { if ((tik_taks = (tik_takstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (tik_takstruct))) == NULL) return; } tiktak = &tik_taks[MI_SCREEN(mi)]; tiktak->mi = mi; if (tiktak->gc == None) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE tiktak->fg = MI_FG_PIXEL(mi); tiktak->bg = MI_BG_PIXEL(mi); #endif tiktak->blackpixel = MI_BLACK_PIXEL(mi); tiktak->whitepixel = MI_WHITE_PIXEL(mi); if ((tiktak->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_tik_tak(display, tiktak); return; } XSetWindowColormap(display, window, tiktak->cmap); (void) XParseColor(display, tiktak->cmap, "black", &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, tiktak->cmap, "white", &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, tiktak->cmap, background, &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, tiktak->cmap, foreground, &color); (void) XAllocColor(display, tiktak->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif tiktak->colors = (XColor *) NULL; tiktak->ncolors = 0; } if ((tiktak->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_tik_tak(display, tiktak); return; } } /* Clear Display */ MI_CLEARWINDOW(mi); tiktak->painted = False; XSetFunction(display, tiktak->gc, GXxor); /*Set up tik_tak data */ tiktak->direction = (LRAND() & 1) ? 1 : -1; tiktak->win_width = MI_WIDTH(mi); tiktak->win_height = MI_HEIGHT(mi); tiktak->num_object = MI_COUNT(mi); tiktak->x0 = tiktak->win_width / 2; tiktak->y0 = tiktak->win_height / 2; max_objects = MI_COUNT(mi); if (tiktak->num_object == 0) { tiktak->num_object = DEF_NUM_OBJECT; max_objects = DEF_NUM_OBJECT; } else if (tiktak->num_object < 0) { max_objects = -tiktak->num_object; tiktak->num_object = NRAND(-tiktak->num_object) + 1; } if (tiktak->object == NULL) if ((tiktak->object = (tik_takobject *) calloc(max_objects, sizeof (tik_takobject))) == NULL) { free_tik_tak(display, tiktak); return; } size_object = MIN( tiktak->win_width , tiktak->win_height) / 3; if ( abs( MI_SIZE(mi) ) > size_object) { if ( MI_SIZE( mi ) < 0 ) { size_object = -size_object; } } else { size_object = MI_SIZE(mi); } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { /* Set up colour map */ if (tiktak->colors != NULL) { if (tiktak->ncolors && !tiktak->no_colors) free_colors(display, tiktak->cmap, tiktak->colors, tiktak->ncolors); free(tiktak->colors); tiktak->colors = (XColor *) NULL; } tiktak->ncolors = MI_NCOLORS(mi); if (tiktak->ncolors < 2) tiktak->ncolors = 2; if (tiktak->ncolors <= 2) tiktak->mono_p = True; else tiktak->mono_p = False; if (tiktak->mono_p) tiktak->colors = (XColor *) NULL; else if ((tiktak->colors = (XColor *) malloc(sizeof (*tiktak->colors) * (tiktak->ncolors + 1))) == NULL) { free_tik_tak(display, tiktak); return; } tiktak->cycle_p = has_writable_cells(mi); if (tiktak->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) tiktak->cycle_p = False; else tiktak->cycle_p = True; } else { tiktak->cycle_p = cycle_p; } } if (!tiktak->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, True, &tiktak->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, &tiktak->cycle_p); else make_smooth_colormap( #ifdef STANDALONE MI_DISPLAY(mi), MI_WINDOW(mi), #else mi, #endif tiktak->cmap, tiktak->colors, &tiktak->ncolors, True, &tiktak->cycle_p); } XInstallColormap(display, tiktak->cmap); if (tiktak->ncolors < 2) { tiktak->ncolors = 2; tiktak->no_colors = True; } else tiktak->no_colors = False; if (tiktak->ncolors <= 2) tiktak->mono_p = True; if (tiktak->mono_p) tiktak->cycle_p = False; } for (i = 0; i < tiktak->num_object; i++) { tik_takobject *object0; object0 = &tiktak->object[i]; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (tiktak->ncolors > 2) object0->colour = NRAND(tiktak->ncolors - 2) + 2; else object0->colour = 1; /* Just in case */ XSetForeground(display, tiktak->gc, tiktak->colors[object0->colour].pixel); } else { if (MI_NPIXELS(mi) > 2) object0->colour = MI_PIXEL(mi, NRAND(MI_NPIXELS(mi))); else object0->colour = 1; /*Xor'red so WHITE may not be appropriate */ XSetForeground(display, tiktak->gc, object0->colour); } object0->angle = NRAND(90) * PI_RAD; object0->angle1 = NRAND(90) * PI_RAD; object0->velocity_a = (NRAND(7) - 3) * PI_RAD; object0->velocity_a1 = (NRAND(7) - 3) * PI_RAD; if (size_object == 0) object0->size_ob = 9; else if (size_object > 0) object0->size_ob = size_object; else object0->size_ob = NRAND(-size_object) + 1; object0->size_ob++; object0->num_point = NRAND(6)+3; if (LRAND() & 1) object0->size_mult = 1.0; else { object0->num_point *= 2; object0->size_mult = 1.0 - ( 1.0 / (float) ((LRAND() & 1) + 2 ) ); } if (object0->xy != NULL) free(object0->xy); if ((object0->xy = (XPoint *) malloc(sizeof( XPoint ) * (2 * object0->num_point + 2))) == NULL) { free_tik_tak(display, tiktak); return; } if ((LRAND() & 1) || object0->size_ob < 10 ) { object0->inner = False; if ( object0->xy1 != NULL ) free( object0->xy1 ); object0->xy1 = (XPoint *) NULL; } else { object0->inner = True; object0->size_ob1 = object0->size_ob - NRAND( object0->size_ob / 5 ) - 1; object0->num_point1 = NRAND(6)+3; if (LRAND() & 1) object0->size_mult1 = 1.0; else { object0->num_point1 *= 2; object0->size_mult1 = 1.0 - ( 1.0 / (float) ((LRAND() & 1) + 2 ) ); } if (object0->xy1 != NULL) free(object0->xy1); if ((object0->xy1 = (XPoint *) malloc(sizeof( XPoint ) * (2 * object0->num_point1 + 2))) == NULL) { free_tik_tak(display, tiktak); return; } object0->size_mult1 = 1.0; } tik_tak_setupobject( mi , object0); tik_tak_reset_object( object0); tik_tak_drawobject(mi, object0 ); } XFlush(display); XSetFunction(display, tiktak->gc, GXcopy); }
static void LoadTexture(ModeInfo * mi, char **fn, const char *filename, GLuint texbind, int blur, float bw_color, Bool anegative, Bool onealpha) { /* looping and temporary array index variables */ int ix, iy, bx, by, indx, indy, boxsize, cchan, tmpidx, dtaidx; float boxdiv, tmpfa, blursum ; unsigned char *tmpbuf, tmpa; Bool rescale; XImage *teximage; /* Texture data */ rescale = False; boxsize = 2; boxdiv = 1.0 / ( boxsize * 2.0 + 1.0) / ( boxsize * 2.0 + 1.0); if (filename) teximage = xpm_file_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), filename); else teximage = xpm_to_ximage(MI_DISPLAY(mi), MI_VISUAL(mi), MI_COLORMAP(mi), fn); if (teximage == NULL) { fprintf(stderr, "%s: error reading the texture.\n", progname); glDeleteTextures(1, &texbind); do_texture = False; exit(0); } /* check if image is 2^kumquat, where kumquat is an integer between 1 and 10. Recale to nearest power of 2. */ tmpfa = mylog2((float) teximage->width); bx = 2 << (int) (tmpfa -1); if (bx != teximage->width) { rescale = True; if ((tmpfa - (int) tmpfa) > 0.5849) bx = bx * 2; } tmpfa = mylog2((float) teximage->height); by = 2 << (int) (tmpfa - 1); if (by != teximage->height) { rescale = True; if ((tmpfa - (int) tmpfa) > 0.5849) by = by * 2; } #ifndef HAVE_JWZGLES if (rescale) { tmpbuf = calloc(bx * by * 4, sizeof(unsigned char)); if (gluScaleImage(GL_RGBA, teximage->width, teximage->height, GL_UNSIGNED_BYTE, teximage->data, bx, by, GL_UNSIGNED_BYTE, tmpbuf)) check_gl_error("scale image"); free(teximage->data); teximage->data = (char *) tmpbuf; teximage->width = bx; teximage->height= by; } /* end rescale code */ #endif /* !HAVE_JWZGLES */ if (anegative ) { for (ix = 0 ; ix < teximage->height * teximage->width; ix++) { if (!teximage->data[ ix * 4 + 3]) { teximage->data[ ix * 4 + 3] = (unsigned char) 0xff; tmpa = (unsigned char) (bw_color * 0xff); } else { if (onealpha) teximage->data[ ix * 4 + 3] = (unsigned char) 0xff; else teximage->data[ ix * 4 + 3] = (unsigned char) 0xff - teximage->data[ ix * 4 + 3]; tmpa = (unsigned char) ((1.0 - bw_color) * 0xff); } /* make texture uniform b/w color */ teximage->data[ ix * 4 + 0] = (unsigned char) ( tmpa); teximage->data[ ix * 4 + 1] = (unsigned char) ( tmpa); teximage->data[ ix * 4 + 2] = (unsigned char) ( tmpa); /* negate alpha */ } } if (blur > 0) { if (! anegative ) /* anegative alread b/w's the whole image */ for (ix = 0 ; ix < teximage->height * teximage->width; ix++) if (!teximage->data[ ix * 4 + 3]) { teximage->data[ ix * 4 + 0] = (unsigned char) ( 255.0 * bw_color); teximage->data[ ix * 4 + 1] = (unsigned char) ( 255.0 * bw_color); teximage->data[ ix * 4 + 2] = (unsigned char) ( 255.0 * bw_color); } ; tmpbuf = calloc(teximage->height * teximage->width * 4, sizeof(unsigned char) ) ; while (blur--) { /* zero out tmp alpha buffer */ for (iy = 0 ; iy <teximage->height * teximage->width * 4 ; iy++) tmpbuf[iy] = 0; for (cchan = 0; cchan < 4 ; cchan++) { for (iy = 0 ; iy < teximage->height ; iy++) { for (ix = 0 ; ix < teximage->width ; ix++) { dtaidx = (teximage->width * iy + ix) * 4; tmpa = teximage->data[dtaidx + cchan]; tmpfa = (float) tmpa * boxdiv; /* box filter */ for (by = -boxsize ; by <= boxsize; by++) { for (bx = -boxsize ; bx <= boxsize; bx++) { indx = wrapVal(ix + bx, 0, teximage->width); indy = wrapVal(iy + by, 0, teximage->height); tmpidx = (teximage->width * indy + indx) * 4; blursum = tmpfa; tmpbuf[tmpidx + cchan] += (unsigned char) blursum; } /* for bx */ } /* for by */ } /* for ix */ } /* for iy */ } /* for cchan */ /* copy back buffer */ for (ix = 0 ; ix < teximage->height * teximage->width * 4; ix++) teximage->data[ix] = tmpbuf[ix]; } /*while blur */ free(tmpbuf); /*tidy*/ } /* if blur */ clear_gl_error(); #ifdef HAVE_GLBINDTEXTURE glBindTexture(GL_TEXTURE_2D, texbind); clear_gl_error(); /* WTF? sometimes "invalid op" from glBindTexture! */ #endif glPixelStorei(GL_UNPACK_ALIGNMENT, 4); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, teximage->width, teximage->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, teximage->data); check_gl_error("texture"); setTexParams(); XDestroyImage(teximage); }
void getImage(ModeInfo * mi, XImage ** logo, int default_width, int default_height, unsigned char *default_bits, #ifdef HAVE_XPM int default_xpm, char **name, #endif int *graphics_format, Colormap * ncm, unsigned long *black) { Display *display = MI_DISPLAY(mi); static char *bitmap_local = (char *) NULL; #ifndef STANDALONE #ifdef HAVE_XPM XpmAttributes attrib; #endif #if 0 /* This probably works best in most cases but for random mode used with random selection of a file it will fail often. */ *ncm = None; #else if (!fixedColors(mi)) *ncm = XCreateColormap(display, MI_WINDOW(mi), MI_VISUAL(mi), AllocNone); else *ncm = None; #endif #ifdef HAVE_XPM attrib.visual = MI_VISUAL(mi); if (*ncm == None) { attrib.colormap = MI_COLORMAP(mi); } else { attrib.colormap = *ncm; } attrib.depth = MI_DEPTH(mi); attrib.valuemask = XpmVisual | XpmColormap | XpmDepth; #endif #endif /* !STANDALONE */ *graphics_format = 0; if (bitmap_local != NULL) { free(bitmap_local); bitmap_local = (char *) NULL; } if (MI_BITMAP(mi) && strlen(MI_BITMAP(mi))) { #ifdef STANDALONE bitmap_local = MI_BITMAP(mi); #else if ((bitmap_local = (char *) malloc(256)) == NULL) { (void) fprintf(stderr , "no memory for \"%s\"\n" , MI_BITMAP(mi)); return; } (void) strncpy(bitmap_local, MI_BITMAP(mi), 256); #if HAVE_DIRENT_H getRandomFile(MI_BITMAP(mi), bitmap_local); #endif #endif /* STANDALONE */ } if (bitmap_local && strlen(bitmap_local)) { #if defined( USE_MAGICK ) && !defined( STANDALONE ) if ( readable( bitmap_local ) ) { if ( MI_NPIXELS( mi ) > 2 ) { Colormap magick_colormap; if (*ncm == None) { magick_colormap = MI_COLORMAP(mi); } else { magick_colormap = *ncm; } if ( MagickSuccess == MagickFileToImage( mi , bitmap_local , logo , magick_colormap ) ) { *graphics_format = IS_MAGICKFILE; *black = GetColor(mi, MI_BLACK_PIXEL(mi)); (void) GetColor(mi, MI_WHITE_PIXEL(mi)); (void) GetColor(mi, MI_BG_PIXEL(mi)); (void) GetColor(mi, MI_FG_PIXEL(mi)); } } } else { (void) fprintf(stderr , "could not read file \"%s\"\n" , bitmap_local); } #else # ifndef STANDALONE if (readable(bitmap_local)) { if (MI_NPIXELS(mi) > 2) { Colormap ras_colormap; if (*ncm == None) { ras_colormap = MI_COLORMAP(mi); } else { ras_colormap = *ncm; } if (RasterSuccess == RasterFileToImage(mi, bitmap_local, logo , ras_colormap )) { *graphics_format = IS_RASTERFILE; *black = GetColor(mi, MI_BLACK_PIXEL(mi)); (void) GetColor(mi, MI_WHITE_PIXEL(mi)); (void) GetColor(mi, MI_BG_PIXEL(mi)); (void) GetColor(mi, MI_FG_PIXEL(mi)); } } } else { (void) fprintf(stderr, "could not read file \"%s\"\n", bitmap_local); } #ifdef HAVE_XPM #ifndef USE_MONOXPM if (MI_NPIXELS(mi) > 2) #endif { if (*graphics_format <= 0) { if (*ncm != None) reserveColors(mi, *ncm, black); if (XpmSuccess == XpmReadFileToImage(display, bitmap_local, logo, (XImage **) NULL, &attrib)) *graphics_format = IS_XPMFILE; } } #endif #endif /* !STANDALONE */ if (*graphics_format <= 0) { if (!blogo.data) { if (BitmapSuccess == XbmReadFileToImage(bitmap_local, &blogo.width, &blogo.height, (unsigned char **) &blogo.data)) { blogo.bytes_per_line = (blogo.width + 7) / 8; *graphics_format = IS_XBMFILE; *logo = &blogo; } } else { *graphics_format = IS_XBMDONE; *logo = &blogo; } } #endif if (*graphics_format <= 0 && MI_IS_VERBOSE(mi)) (void) fprintf(stderr, "\"%s\" is in an unrecognized format or not compatible with screen\n", bitmap_local); } #ifndef STANDALONE #ifdef HAVE_XPM if (*graphics_format <= 0 && ((MI_IS_FULLRANDOM(mi)) ? LRAND() & 1: default_xpm)) #ifndef USE_MONOXPM if (MI_NPIXELS(mi) > 2) #endif if (XpmSuccess == XpmCreateImageFromData(display, name, logo, (XImage **) NULL, &attrib)) *graphics_format = IS_XPM; #endif #endif /* STANDALONE */ if (*graphics_format <= 0) { if (!blogo.data) { blogo.data = (char *) default_bits; blogo.width = default_width; blogo.height = default_height; blogo.bytes_per_line = (blogo.width + 7) / 8; *graphics_format = IS_XBM; } else *graphics_format = IS_XBMDONE; *logo = &blogo; } #ifndef STANDALONE /* Come back later */ if (*ncm != None && *graphics_format != IS_RASTERFILE && *graphics_format != IS_XPMFILE && *graphics_format != IS_XPM && *graphics_format != IS_MAGICKFILE) { XFreeColormap(display, *ncm); *ncm = None; } #endif /* STANDALONE */ /* Come back later */ }
/*- * init_swirl * * Initialise things for swirling * * - win is the window to draw in */ void init_swirl(ModeInfo * mi) { Display *display = MI_DISPLAY(mi); Window window = MI_WINDOW(mi); swirlstruct *sp; /* does the swirls array exist? */ if (swirls == NULL) { int i; /* allocate an array, one entry for each screen */ if ((swirls = (swirlstruct *) calloc(MI_NUM_SCREENS(mi), sizeof (swirlstruct))) == NULL) return; /* initialise them all */ for (i = 0; i < MI_NUM_SCREENS(mi); i++) initialise_swirl(&swirls[i]); } /* get a pointer to this swirl */ sp = &(swirls[MI_SCREEN(mi)]); sp->mi = mi; /* get window parameters */ sp->width = MI_WIDTH(mi); sp->height = MI_HEIGHT(mi); sp->depth = MI_DEPTH(mi); sp->rdepth = sp->depth; sp->visual = MI_VISUAL(mi); if (sp->depth > 16) sp->depth = 16; /* initialise image for speeding up drawing */ if (!initialise_image(display, sp)) { free_swirl(display, sp); return; } MI_CLEARWINDOW(mi); if (!sp->gc) { if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { XColor color; #ifndef STANDALONE sp->fg = MI_FG_PIXEL(mi); sp->bg = MI_BG_PIXEL(mi); #endif sp->blackpixel = MI_BLACK_PIXEL(mi); sp->whitepixel = MI_WHITE_PIXEL(mi); if ((sp->cmap = XCreateColormap(display, window, MI_VISUAL(mi), AllocNone)) == None) { free_swirl(display, sp); return; } XSetWindowColormap(display, window, sp->cmap); (void) XParseColor(display, sp->cmap, "black", &color); (void) XAllocColor(display, sp->cmap, &color); MI_BLACK_PIXEL(mi) = color.pixel; (void) XParseColor(display, sp->cmap, "white", &color); (void) XAllocColor(display, sp->cmap, &color); MI_WHITE_PIXEL(mi) = color.pixel; #ifndef STANDALONE (void) XParseColor(display, sp->cmap, background, &color); (void) XAllocColor(display, sp->cmap, &color); MI_BG_PIXEL(mi) = color.pixel; (void) XParseColor(display, sp->cmap, foreground, &color); (void) XAllocColor(display, sp->cmap, &color); MI_FG_PIXEL(mi) = color.pixel; #endif sp->colors = (XColor *) NULL; sp->ncolors = 0; } if ((sp->gc = XCreateGC(display, MI_WINDOW(mi), (unsigned long) 0, (XGCValues *) NULL)) == None) { free_swirl(display, sp); return; } } MI_CLEARWINDOW(mi); /* Set up colour map */ sp->direction = (LRAND() & 1) ? 1 : -1; if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (sp->colors != NULL) { if (sp->ncolors && !sp->no_colors) free_colors(display, sp->cmap, sp->colors, sp->ncolors); free(sp->colors); sp->colors = (XColor *) NULL; } sp->ncolors = MI_NCOLORS(mi); if (sp->ncolors < 2) sp->ncolors = 2; if (sp->ncolors <= 2) sp->mono_p = True; else sp->mono_p = False; if (sp->mono_p) sp->colors = (XColor *) NULL; else if ((sp->colors = (XColor *) malloc(sizeof (*sp->colors) * (sp->ncolors + 1))) == NULL) { free_swirl(display, sp); return; } sp->cycle_p = has_writable_cells(mi); if (sp->cycle_p) { if (MI_IS_FULLRANDOM(mi)) { if (!NRAND(8)) sp->cycle_p = False; else sp->cycle_p = True; } else { sp->cycle_p = cycle_p; } } if (!sp->mono_p) { if (!(LRAND() % 10)) make_random_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, True, &sp->cycle_p); else if (!(LRAND() % 2)) make_uniform_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, &sp->cycle_p); else make_smooth_colormap( #if STANDALONE display, MI_WINDOW(mi), #else mi, #endif sp->cmap, sp->colors, &sp->ncolors, True, &sp->cycle_p); } XInstallColormap(display, sp->cmap); if (sp->ncolors < 2) { sp->ncolors = 2; sp->no_colors = True; } else sp->no_colors = False; if (sp->ncolors <= 2) sp->mono_p = True; if (sp->mono_p) sp->cycle_p = False; } if (MI_IS_INSTALL(mi) && MI_NPIXELS(mi) > 2) { if (sp->mono_p) { sp->cur_color = MI_BLACK_PIXEL(mi); } } /* resolution starts off chunky */ sp->resolution = MIN_RES + 1; /* calculate the pixel step for this resulution */ sp->r = (1 << (sp->resolution - 1)); /* how many knots? */ sp->n_knots = random_no((unsigned int) MI_COUNT(mi) / 2) + MI_COUNT(mi) + 1; /* what type of knots? */ sp->knot_type = ALL; /* for now */ /* use two_plane mode occaisionally */ if (random_no(100) <= TWO_PLANE_PCNT) { sp->two_plane = sp->first_plane = True; sp->max_resolution = 2; } else sp->two_plane = False; /* fix the knot values */ if (!create_knots(sp)) { free_swirl(display, sp); return; } /* we are off */ sp->started = True; sp->drawing = False; }