X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Fglplanet.c;h=c30b306ede1f0168f28b4cbb5a9c375e200934cb;hb=78add6e627ee5f10e1fa6f3852602ea5066eee5a;hp=8c9dec8fff6ce1342d333d7d5182ceb112dbd567;hpb=d5186197bc394e10a4402f7f6d23fbb14103bc50;p=xscreensaver diff --git a/hacks/glx/glplanet.c b/hacks/glx/glplanet.c index 8c9dec8f..c30b306e 100644 --- a/hacks/glx/glplanet.c +++ b/hacks/glx/glplanet.c @@ -35,8 +35,10 @@ "*showFPS: False \n" \ "*wireframe: False \n" \ "*imageForeground: Green \n" \ - "*imageBackground: Blue \n" -# define refresh_planet 0 + "*imageBackground: Blue \n" \ + "*suppressRotationAnimation: True\n" \ + +# define release_planet 0 # include "xlockmore.h" /* from the xscreensaver distribution */ #else /* !STANDALONE */ # include "xlock.h" /* from the xlockmore distribution */ @@ -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}, }; @@ -107,21 +113,16 @@ ENTRYPOINT ModeSpecOpt planet_opts = {countof(opts), opts, countof(vars), vars, #ifdef USE_MODULES ModStruct planet_description = -{"planet", "init_planet", "draw_planet", "release_planet", - "draw_planet", "init_planet", NULL, &planet_opts, +{"planet", "init_planet", "draw_planet", NULL, + "draw_planet", "init_planet", "free_planet", &planet_opts, 1000, 1, 2, 1, 4, 1.0, "", "Animates texture mapped sphere (planet)", 0, NULL}; #endif -# ifdef __GNUC__ - __extension__ /* don't warn about "string length is greater than the length - ISO C89 compilers are required to support" when including - the following XPM file... */ -# endif -#include "../images/earth.xpm" -#include "../images/earth_night.xpm" +#include "images/gen/earth_png.h" +#include "images/gen/earth_night_png.h" -#include "xpm-ximage.h" +#include "ximage-loader.h" #include "rotator.h" #include "gltrackball.h" @@ -159,61 +160,44 @@ static planetstruct *planets = NULL; /* Set up and enable texturing on our object */ static void -setup_xpm_texture (ModeInfo *mi, char **xpm_data) +setup_xpm_texture (ModeInfo *mi, const unsigned char *data, unsigned long size) { - XImage *image = xpm_to_ximage (MI_DISPLAY (mi), MI_VISUAL (mi), - MI_COLORMAP (mi), xpm_data); + 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, */ - GL_UNSIGNED_INT_8_8_8_8_REV, - image->data); + GL_RGBA, GL_UNSIGNED_BYTE, 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; Visual *visual = mi->xgwa.visual; char buf[1024]; - Colormap cmap = mi->xgwa.colormap; - XImage *image = xpm_file_to_ximage (dpy, visual, cmap, filename); + XImage *image = file_to_ximage (dpy, visual, 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, - /* GL_UNSIGNED_BYTE, */ - GL_UNSIGNED_INT_8_8_8_8_REV, - image->data); + GL_RGBA, GL_UNSIGNED_BYTE, image->data); 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 +206,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); - setup_xpm_texture (mi, earth_xpm); - glGenTextures (1, &gp->tex2); - glBindTexture (GL_TEXTURE_2D, gp->tex2); - setup_xpm_texture (mi, earth_night_xpm); + BUILTIN1: + setup_xpm_texture (mi, earth_png, sizeof(earth_png)); } else { - glGenTextures (1, &gp->tex1); - glBindTexture (GL_TEXTURE_2D, gp->tex1); - setup_file_texture (mi, which_image); + 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_png, sizeof(earth_night_png)); + } + else + { + 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); @@ -261,12 +275,18 @@ init_stars (ModeInfo *mi) int max_size = 3; GLfloat inc = 0.5; int steps = max_size / inc; + GLfloat scale = 1; + + if (MI_WIDTH(mi) > 2560) { /* Retina displays */ + scale *= 2; + nstars /= 2; + } gp->starlist = glGenLists(1); glNewList(gp->starlist, GL_COMPILE); for (j = 1; j <= steps; j++) { - glPointSize(inc * j); + glPointSize(inc * j * scale); glBegin (GL_POINTS); for (i = 0; i < nstars / steps; i++) { @@ -299,16 +319,27 @@ init_stars (ModeInfo *mi) ENTRYPOINT void reshape_planet (ModeInfo *mi, int width, int height) { + planetstruct *gp = &planets[MI_SCREEN(mi)]; GLfloat h = (GLfloat) height / (GLfloat) width; + glXMakeCurrent(MI_DISPLAY(mi), gp->window, *(gp->glx_context)); + glViewport(0, 0, (GLint) width, (GLint) height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - glFrustum(-1.0, 1.0, -h, h, 5.0, 100.0); + glFrustum(-1.0, 1.0, -h, h, 5.0, 200.0); glMatrixMode(GL_MODELVIEW); 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); } @@ -334,13 +365,11 @@ init_planet (ModeInfo * mi) int screen = MI_SCREEN(mi); Bool wire = MI_IS_WIREFRAME(mi); - if (planets == NULL) { - if ((planets = (planetstruct *) calloc(MI_NUM_SCREENS(mi), - sizeof (planetstruct))) == NULL) - return; - } + MI_INIT (mi, planets); gp = &planets[screen]; + gp->window = MI_WINDOW(mi); + if ((gp->glx_context = init_GL(mi)) != NULL) { reshape_planet(mi, MI_WIDTH(mi), MI_HEIGHT(mi)); } @@ -418,7 +447,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 +519,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 +535,7 @@ draw_planet (ModeInfo * mi) glScalef (3, 3, 3); -# ifdef USE_IPHONE +# ifdef HAVE_MOBILE glScalef (2, 2, 2); # endif @@ -599,29 +629,18 @@ draw_planet (ModeInfo * mi) ENTRYPOINT void -release_planet (ModeInfo * mi) +free_planet (ModeInfo * mi) { - if (planets != NULL) { - int screen; - - for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) { - planetstruct *gp = &planets[screen]; - - if (gp->glx_context) { - /* Display lists MUST be freed while their glXContext is current. */ - /* but this gets a BadMatch error. -jwz */ - /*glXMakeCurrent(MI_DISPLAY(mi), gp->window, *(gp->glx_context));*/ - - if (glIsList(gp->platelist)) - glDeleteLists(gp->platelist, 1); - if (glIsList(gp->starlist)) - glDeleteLists(gp->starlist, 1); - } - } - (void) free((void *) planets); - planets = NULL; + planetstruct *gp = &planets[MI_SCREEN(mi)]; + + if (gp->glx_context) { + glXMakeCurrent(MI_DISPLAY(mi), gp->window, *(gp->glx_context)); + + if (glIsList(gp->platelist)) + glDeleteLists(gp->platelist, 1); + if (glIsList(gp->starlist)) + glDeleteLists(gp->starlist, 1); } - FreeAllGL(mi); }