-/* Sky Tentacles, Copyright (c) 2008 Jamie Zawinski <jwz@jwz.org>
+/* Sky Tentacles, Copyright (c) 2008-2018 Jamie Zawinski <jwz@jwz.org>
*
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
"*showFPS: False \n" \
"*wireframe: False \n" \
-# define refresh_tentacles 0
+# define free_tentacles 0
# define release_tentacles 0
#undef countof
#define countof(x) (sizeof((x))/sizeof((*x)))
#include "gltrackball.h"
#include <ctype.h>
-#include "xpm-ximage.h"
-#include "../images/scales.xpm"
-
-static char *grey_texture[] = {
- "16 1 3 1",
- "X c #808080",
- "x c #C0C0C0",
- ". c #FFFFFF",
- "XXXxxxxx........"
-};
+#include "ximage-loader.h"
+#include "images/gen/scales_png.h"
#ifdef USE_GL /* whole file */
+# ifndef HAVE_JWZGLES
+# define HAVE_POLYGONMODE
+# endif
+
#define DEF_SPEED "1.0"
#define DEF_SMOOTH "True"
#define DEF_TEXTURE "True"
{
tentacles_configuration *tc = &tcs[MI_SCREEN(mi)];
GLfloat h = (GLfloat) height / (GLfloat) width;
+ int y = 0;
+
+ if (width > height * 5) { /* tiny window: show middle */
+ height = width * 9/16;
+ y = -height/2;
+ h = height / (GLfloat) width;
+ }
- glViewport (0, 0, (GLint) width, (GLint) height);
+ glViewport (0, y, (GLint) width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
t->mi->polygon_count += points/2;
}
-
static void
-draw_tentacle (tentacle *t, Bool front_p)
+draw_tentacle_1 (tentacle *t, Bool front_p, Bool outline_p)
{
tentacles_configuration *tc = &tcs[MI_SCREEN(t->mi)];
int i;
}
+# ifdef HAVE_POLYGONMODE
if (cel_p)
glPolygonMode (GL_FRONT_AND_BACK, (front_p ? GL_FILL : GL_LINE));
+# endif
glPushMatrix();
glTranslatef (t->x, t->y, t->z);
glPopAttrib();
}
- if (!front_p)
+ if (!front_p || outline_p)
glColor4fv (tc->outline_color);
else if (wire)
glColor4fv (t->tentacle_color);
if (j <= indented_points/2 || j >= arg_slices-indented_points/2)
r *= 0.75; /* indent the stripe */
+ if (outline_p)
+ r *= 1.1;
+
ring[j].x = r * ucirc[j].x;
ring[j].y = 0;
ring[j].z = r * ucirc[j].y;
GLfloat ts = j / (double) arg_slices;
- if (!front_p)
+ if (!front_p || outline_p)
glColor4fv (tc->outline_color);
else if (j <= indented_points/2 ||
j >= arg_slices-indented_points/2)
nsuckers = (i % segs_per_sucker) ? 0 : 1;
}
- if (front_p)
+ if (outline_p)
+ {
+ glColor4fv (tc->outline_color);
+ glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE,
+ tc->outline_color);
+ }
+ else if (front_p)
{
glColor4fv (t->sucker_color);
glMaterialfv (GL_FRONT, GL_AMBIENT_AND_DIFFUSE,
scale = t->segments[i].thickness / arg_thickness;
scale *= 0.7 * sucker_size;
+
glScalef (scale, scale, scale * 4);
glTranslatef (0, 0, -0.1); /* embed */
+ if (outline_p)
+ {
+ scale = 1.1;
+ glScalef (scale, scale, scale);
+ }
+
glTranslatef (1, 0, 0); /* left */
draw_sucker (t, front_p);
/* Now draw the end caps.
*/
glLineWidth (tc->line_thickness);
- if (i == 0 || i == t->nsegments-1)
+ if (!outline_p && (i == 0 || i == t->nsegments-1))
{
int j;
GLfloat ctrz = ctr.z + ((i == 0 ? -1 : 1) *
}
+static void
+draw_tentacle (tentacle *t, Bool front_p)
+{
+# ifndef HAVE_POLYGONMODE
+ Bool wire = MI_IS_WIREFRAME (t->mi);
+ if (!wire && cel_p && front_p)
+ {
+ draw_tentacle_1 (t, front_p, True);
+ glClear (GL_DEPTH_BUFFER_BIT);
+ }
+# endif /* HAVE_POLYGONMODE */
+
+ draw_tentacle_1 (t, front_p, False);
+}
+
+
static void
move_tentacle (tentacle *t)
{
{
tentacles_configuration *tc = &tcs[MI_SCREEN(mi)];
- if (event->xany.type == ButtonPress &&
- event->xbutton.button == Button1)
- {
- tc->button_down_p = True;
- gltrackball_start (tc->trackball,
- event->xbutton.x, event->xbutton.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
- return True;
- }
- else if (event->xany.type == ButtonRelease &&
- event->xbutton.button == Button1)
- {
- tc->button_down_p = False;
- return True;
- }
- else if (event->xany.type == ButtonPress &&
- (event->xbutton.button == Button4 ||
- event->xbutton.button == Button5 ||
- event->xbutton.button == Button6 ||
- event->xbutton.button == Button7))
- {
- gltrackball_mousewheel (tc->trackball, event->xbutton.button, 10,
- !!event->xbutton.state);
- return True;
- }
- else if (event->xany.type == MotionNotify &&
- tc->button_down_p)
- {
- gltrackball_track (tc->trackball,
- event->xmotion.x, event->xmotion.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
- return True;
- }
+ if (gltrackball_event_handler (event, tc->trackball,
+ MI_WIDTH (mi), MI_HEIGHT (mi),
+ &tc->button_down_p))
+ return True;
else if (event->xany.type == KeyPress)
{
KeySym keysym;
XLookupString (&event->xkey, &c, 1, &keysym, 0);
if (c == ' ')
{
- gltrackball_reset (tc->trackball);
+ gltrackball_reset (tc->trackball, 0, 0);
return True;
}
}
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);
- }
- }
+ MI_INIT (mi, tcs);
tc = &tcs[MI_SCREEN(mi)];
glEnable (GL_LIGHT0);
}
- tc->trackball = gltrackball_init ();
+ tc->trackball = gltrackball_init (False);
tc->left_p = !(random() % 5);
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 (cel_p)
+ {
+ /* "16 1 3 1",
+ "X c #808080",
+ "x c #C0C0C0",
+ ". c #FFFFFF",
+ "XXXxxxxx........"
+ */
+ int w = 16;
+ tc->texture = XCreateImage (MI_DISPLAY(mi), MI_VISUAL(mi),
+ 32, ZPixmap, 0, 0, w, 1, 32, 0);
+ tc->texture->data = (char *) calloc(1, tc->texture->bytes_per_line);
+ /* ABGR */
+ for (i = 0; i < 3; i++) XPutPixel (tc->texture, i, 0, 0xFF808080);
+ for (; i < 8; i++) XPutPixel (tc->texture, i, 0, 0xFFC0C0C0);
+ for (; i < w; i++) XPutPixel (tc->texture, i, 0, 0xFFFFFFFF);
+ }
+ else
+ tc->texture = image_data_to_ximage (MI_DISPLAY(mi), MI_VISUAL(mi),
+ scales_png, sizeof(scales_png));
+
if (!tc->texture) texture_p = cel_p = False;
}
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);
+ GL_RGBA, GL_UNSIGNED_BYTE, tc->texture->data);
check_gl_error("texture");
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
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);
+ GL_RGBA, GL_UNSIGNED_BYTE, tc->texture->data);
check_gl_error("texture");
glTexParameterf(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix ();
-
+ glRotatef(current_device_rotation(), 0, 0, 1);
# if 1
glScalef (3, 3, 3);