X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fglplanet.c;h=20ccc5841f5a16db4e3469eff00bdd5a8e779f37;hb=refs%2Fheads%2Fmaster2;hp=8c9dec8fff6ce1342d333d7d5182ceb112dbd567;hpb=d5186197bc394e10a4402f7f6d23fbb14103bc50;p=xscreensaver diff --git a/hacks/glx/glplanet.c b/hacks/glx/glplanet.c index 8c9dec8f..20ccc584 100644 --- a/hacks/glx/glplanet.c +++ b/hacks/glx/glplanet.c @@ -35,7 +35,9 @@ "*showFPS: False \n" \ "*wireframe: False \n" \ "*imageForeground: Green \n" \ - "*imageBackground: Blue \n" + "*imageBackground: Blue \n" \ + "*suppressRotationAnimation: True\n" \ + # define refresh_planet 0 # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ @@ -62,6 +64,7 @@ #define DEF_STARS "True" #define DEF_RESOLUTION "128" #define DEF_IMAGE "BUILTIN" +#define DEF_IMAGE2 "BUILTIN" #undef countof #define countof(x) (sizeof((x))/sizeof((*x))) @@ -75,6 +78,7 @@ static int do_wander; static int do_texture; static int do_stars; static char *which_image; +static char *which_image2; static int resolution; static XrmOptionDescRec opts[] = { @@ -89,7 +93,8 @@ static XrmOptionDescRec opts[] = { {"-stars", ".glplanet.stars", XrmoptionNoArg, "true" }, {"+stars", ".glplanet.stars", XrmoptionNoArg, "false" }, {"-spin", ".glplanet.spin", XrmoptionSepArg, 0 }, - {"-image", ".glplanet.image", XrmoptionSepArg, 0 }, + {"-image", ".glplanet.image", XrmoptionSepArg, 0 }, + {"-image2", ".glplanet.image2", XrmoptionSepArg, 0 }, {"-resolution", ".glplanet.resolution", XrmoptionSepArg, 0 }, }; @@ -100,6 +105,7 @@ static argtype vars[] = { {&do_texture, "texture", "Texture", DEF_TEXTURE, t_Bool}, {&do_stars, "stars", "Stars", DEF_STARS, t_Bool}, {&which_image, "image", "Image", DEF_IMAGE, t_String}, + {&which_image2,"image2", "Image", DEF_IMAGE2, t_String}, {&resolution, "resolution","Resolution", DEF_RESOLUTION, t_Int}, }; @@ -165,6 +171,10 @@ setup_xpm_texture (ModeInfo *mi, char **xpm_data) 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, @@ -173,18 +183,10 @@ setup_xpm_texture (ModeInfo *mi, char **xpm_data) 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); } -static void +static Bool setup_file_texture (ModeInfo *mi, char *filename) { Display *dpy = mi->dpy; @@ -193,8 +195,11 @@ setup_file_texture (ModeInfo *mi, char *filename) Colormap cmap = mi->xgwa.colormap; XImage *image = xpm_file_to_ximage (dpy, visual, cmap, filename); + if (!image) return False; clear_gl_error(); + glPixelStorei(GL_UNPACK_ALIGNMENT, 4); + glPixelStorei(GL_UNPACK_ROW_LENGTH, image->width); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, image->width, image->height, 0, GL_RGBA, @@ -204,16 +209,7 @@ setup_file_texture (ModeInfo *mi, char *filename) sprintf (buf, "texture: %.100s (%dx%d)", filename, image->width, image->height); check_gl_error(buf); - - /* setup parameters for texturing */ - glPixelStorei(GL_UNPACK_ALIGNMENT, 4); - glPixelStorei(GL_UNPACK_ROW_LENGTH, image->width); - - 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); + return True; } @@ -222,25 +218,55 @@ setup_texture(ModeInfo * mi) { planetstruct *gp = &planets[MI_SCREEN(mi)]; + glGenTextures (1, &gp->tex1); + glBindTexture (GL_TEXTURE_2D, gp->tex1); + + /* Must be after glBindTexture */ + 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); + if (!which_image || !*which_image || !strcmp(which_image, "BUILTIN")) { - glGenTextures (1, &gp->tex1); - glBindTexture (GL_TEXTURE_2D, gp->tex1); + BUILTIN1: setup_xpm_texture (mi, earth_xpm); - glGenTextures (1, &gp->tex2); - glBindTexture (GL_TEXTURE_2D, gp->tex2); + } + else + { + if (! setup_file_texture (mi, which_image)) + goto BUILTIN1; + } + + check_gl_error("texture 1 initialization"); + + glGenTextures (1, &gp->tex2); + glBindTexture (GL_TEXTURE_2D, gp->tex2); + + /* Must be after glBindTexture */ + 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); + + if (!which_image2 || + !*which_image2 || + !strcmp(which_image2, "BUILTIN")) + { + BUILTIN2: setup_xpm_texture (mi, earth_night_xpm); } else { - glGenTextures (1, &gp->tex1); - glBindTexture (GL_TEXTURE_2D, gp->tex1); - setup_file_texture (mi, which_image); + if (! setup_file_texture (mi, which_image2)) + goto BUILTIN2; } - check_gl_error("texture initialization"); + check_gl_error("texture 2 initialization"); /* Need to flip the texture top for bottom for some reason. */ glMatrixMode (GL_TEXTURE); @@ -309,6 +335,14 @@ reshape_planet (ModeInfo *mi, int width, int height) glLoadIdentity(); glTranslatef(0.0, 0.0, -40); +# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */ + { + int o = (int) current_device_rotation(); + if (o != 0 && o != 180 && o != -180) + glScalef (h, h, h); + } +# endif + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } @@ -418,7 +452,9 @@ init_planet (ModeInfo * mi) gp->latlonglist = glGenLists(1); glNewList (gp->latlonglist, GL_COMPILE); glPushMatrix (); - glRotatef (90, 1, 0, 0); + glRotatef (90, 1, 0, 0); /* unit_sphere is off by 90 */ + glRotatef (8, 0, 1, 0); /* line up the time zones */ + unit_sphere (12, 24, 1); unit_sphere (12, 24, 1); glBegin(GL_LINES); glVertex3f(0, -2, 0); @@ -488,8 +524,7 @@ draw_planet (ModeInfo * mi) { glDisable(GL_TEXTURE_2D); glPushMatrix(); - glTranslatef(-x, -y, -z); - glScalef (40, 40, 40); + glScalef (60, 60, 60); glRotatef (90, 1, 0, 0); glRotatef (35, 1, 0, 0); glCallList (gp->starlist); @@ -505,7 +540,7 @@ draw_planet (ModeInfo * mi) glScalef (3, 3, 3); -# ifdef USE_IPHONE +# ifdef HAVE_MOBILE glScalef (2, 2, 2); # endif