~ubuntu-branches/debian/sid/xscreensaver/sid

« back to all changes in this revision

Viewing changes to hacks/glx/starwars.c

  • Committer: Bazaar Package Importer
  • Author(s): Jose Luis Rivas, Tormod Volden, Jose Luis Rivas
  • Date: 2008-07-15 14:48:48 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20080715144848-c6c6mhyxij0dk2p7
Tags: 5.05-3
[ Tormod Volden ]
* debian/patches/10_jwz-xscreensaver-randr-patch-3.patch:
  from upstream, addresses issues with xrandr/xinerama
  (Closes: #482385, #428797, #471920, #453708, #473681, #479715, #480231)
* fixed typo "screen < real_nscreens" in driver/lock:1527 from above patch
* drop 61_DualHead-nVidia_bug471920.patch (obsolete)
* drop 67_XineRama-mode_bug473681.patch (obsolete)
* fix m6502.o typo in hacks/Makefile.in
* refresh 53_XScreenSaver.ad.in.patch
* refresh (disabled) 60_add-ant-hack.patch

[ Jose Luis Rivas ]
* add xscreensaver-demo desktop file, thanks to Daniel Dickinson
  (Closes: #480592)
* update package descriptions (thanks jwz)
* fix categories in xscreensaver.menu
* change build-deps from xlibmesa-gl-dev to libgl1-mesa-dev,
  xutils to xutils-dev, x-dev to x11proto-core-dev.
* bump Standards-Version to 3.8.0
* add Vcs fields and Homepage to debian/control
* Flurry is not installed until the bug get fixed (Closes: #484112)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * starwars, Copyright (c) 1998-2005 Jamie Zawinski <jwz@jwz.org> and
 
2
 * starwars, Copyright (c) 1998-2007 Jamie Zawinski <jwz@jwz.org> and
3
3
 * Claudio Matsuoka <claudio@helllabs.org>
4
4
 *
5
5
 * Permission to use, copy, modify, distribute, and sell this software and its
26
26
 *     starwars -program 'cat starwars.txt' -columns 25 -no-wrap -texture
27
27
 */
28
28
 
29
 
#include <X11/Intrinsic.h>
30
 
 
31
 
extern XtAppContext app;
32
 
 
33
 
#define PROGCLASS       "StarWars"
34
 
#define HACK_INIT       init_sws
35
 
#define HACK_DRAW       draw_sws
36
 
#define HACK_RESHAPE    reshape_sws
37
 
#define sws_opts        xlockmore_opts
 
29
#ifdef HAVE_CONFIG_H
 
30
# include "config.h"
 
31
#endif /* HAVE_CONFIG_H */
 
32
 
 
33
#include <ctype.h>
 
34
#include <sys/stat.h>
 
35
 
 
36
#ifdef HAVE_UNISTD_H
 
37
# include <unistd.h>
 
38
#endif
 
39
 
 
40
#ifdef HAVE_UNAME
 
41
# include <sys/utsname.h>
 
42
#endif /* HAVE_UNAME */
 
43
 
 
44
#ifndef HAVE_COCOA
 
45
# include <X11/Intrinsic.h>
 
46
#endif
 
47
 
 
48
 
 
49
#define DEFAULTS "*delay:    40000     \n" \
 
50
                 "*showFPS:  False     \n" \
 
51
                 "*fpsTop:   True      \n" \
 
52
                 "*font:   " DEF_FONT "\n"
 
53
 
 
54
# define refresh_sws 0
 
55
# define sws_handle_event 0
 
56
#undef countof
 
57
#define countof(x) (sizeof((x))/sizeof((*x)))
 
58
 
 
59
#include "xlockmore.h"
 
60
 
 
61
#ifdef USE_GL /* whole file */
 
62
 
 
63
/* Should be in <GL/glext.h> */
 
64
# ifndef  GL_TEXTURE_MAX_ANISOTROPY_EXT
 
65
#  define GL_TEXTURE_MAX_ANISOTROPY_EXT     0x84FE
 
66
# endif
 
67
# ifndef  GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT
 
68
#  define GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT 0x84FF
 
69
# endif
 
70
 
38
71
 
39
72
#define DEF_PROGRAM    "xscreensaver-text --cols 0"  /* don't wrap */
40
73
#define DEF_LINES      "125"
65
98
#define FONT_WEIGHT       14
66
99
#define KEEP_ASPECT
67
100
 
68
 
#define DEFAULTS "*delay:    40000     \n" \
69
 
                 "*showFPS:  False     \n" \
70
 
                 "*fpsTop:   True      \n" \
71
 
                 "*font:   " DEF_FONT "\n" \
72
 
 
73
 
#undef countof
74
 
#define countof(x) (sizeof((x))/sizeof((*x)))
75
 
 
76
 
#include "xlockmore.h"
77
 
 
78
 
#ifdef USE_GL /* whole file */
79
 
 
80
 
#include <ctype.h>
81
 
#include <GL/glu.h>
82
 
#include <sys/stat.h>
83
101
#include "texfont.h"
84
102
#include "glutstroke.h"
85
103
#include "glut_roman.h"
86
104
#define GLUT_FONT (&glutStrokeRoman)
87
105
 
88
 
#ifdef HAVE_UNAME
89
 
# include <sys/utsname.h>
90
 
#endif /* HAVE_UNAME */
91
 
 
92
 
 
93
106
typedef struct {
 
107
  Display *dpy;
94
108
  GLXContext *glx_context;
95
109
 
96
110
  GLuint text_list, star_list;
99
113
 
100
114
  FILE *pipe;
101
115
  XtInputId pipe_id;
 
116
  XtIntervalId pipe_timer;
102
117
  Time subproc_relaunch_delay;
103
118
 
104
119
  char *buf;
157
172
  {"-wrap",        ".lineWrap",  XrmoptionNoArg,  "True"   },
158
173
  {"-no-wrap",     ".lineWrap",  XrmoptionNoArg,  "False"  },
159
174
  {"-nowrap",      ".lineWrap",  XrmoptionNoArg,  "False"  },
 
175
  {"-alignment",   ".alignment", XrmoptionSepArg, 0        },
160
176
  {"-left",        ".alignment", XrmoptionNoArg,  "Left"   },
161
177
  {"-right",       ".alignment", XrmoptionNoArg,  "Right"  },
162
178
  {"-center",      ".alignment", XrmoptionNoArg,  "Center" },
179
195
  {&debug_p,        "debug",     "Boolean",    DEF_DEBUG,     t_Bool},
180
196
};
181
197
 
182
 
ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
 
198
ENTRYPOINT ModeSpecOpt sws_opts = {countof(opts), opts, countof(vars), vars, NULL};
183
199
 
184
200
 
185
201
 
287
303
static void
288
304
launch_text_generator (sws_configuration *sc)
289
305
{
290
 
  char *oprogram = get_string_resource ("program", "Program");
 
306
  XtAppContext app = XtDisplayToApplicationContext (sc->dpy);
 
307
  char *oprogram = get_string_resource (sc->dpy, "program", "Program");
291
308
  char *program = (char *) malloc (strlen (oprogram) + 10);
292
309
  strcpy (program, "( ");
293
310
  strcat (program, oprogram);
311
328
relaunch_generator_timer (XtPointer closure, XtIntervalId *id)
312
329
{
313
330
  sws_configuration *sc = (sws_configuration *) closure;
 
331
  if (!sc->pipe_timer) abort();
 
332
  sc->pipe_timer = 0;
314
333
  launch_text_generator (sc);
315
334
}
316
335
 
321
340
static void
322
341
drain_input (sws_configuration *sc)
323
342
{
 
343
  XtAppContext app = XtDisplayToApplicationContext (sc->dpy);
324
344
  if (sc->buf_tail < sc->buf_size - 2)
325
345
    {
326
346
      int target = sc->buf_size - sc->buf_tail - 2;
357
377
          sc->buf[sc->buf_tail] = 0;
358
378
 
359
379
          /* Set up a timer to re-launch the subproc in a bit. */
360
 
          XtAppAddTimeOut (app, sc->subproc_relaunch_delay,
361
 
                           relaunch_generator_timer,
362
 
                           (XtPointer) sc);
 
380
          sc->pipe_timer = XtAppAddTimeOut (app, sc->subproc_relaunch_delay,
 
381
                                            relaunch_generator_timer,
 
382
                                            (XtPointer) sc);
363
383
        }
364
384
    }
365
385
}
643
663
 
644
664
/* Window management, etc
645
665
 */
646
 
void
 
666
ENTRYPOINT void
647
667
reshape_sws (ModeInfo *mi, int width, int height)
648
668
{
649
669
  sws_configuration *sc = &scs[MI_SCREEN(mi)];
727
747
{
728
748
  sws_configuration *sc = &scs[MI_SCREEN(mi)];
729
749
 
730
 
  program = get_string_resource ("program", "Program");
 
750
  program = get_string_resource (mi->dpy, "program", "Program");
731
751
 
732
752
  glDisable (GL_LIGHTING);
733
753
  glDisable (GL_DEPTH_TEST);
752
772
}
753
773
 
754
774
 
755
 
void 
 
775
ENTRYPOINT void 
756
776
init_sws (ModeInfo *mi)
757
777
{
758
778
  double font_height;
759
779
 
760
 
  sws_configuration *sc;
 
780
  sws_configuration *sc = 0;
761
781
 
762
782
  if (!scs) {
763
783
    scs = (sws_configuration *)
766
786
      fprintf(stderr, "%s: out of memory\n", progname);
767
787
      exit(1);
768
788
    }
769
 
 
770
 
    sc = &scs[MI_SCREEN(mi)];
771
 
    sc->lines = (char **) calloc (max_lines+1, sizeof(char *));
772
789
  }
773
790
 
774
791
  sc = &scs[MI_SCREEN(mi)];
775
792
 
 
793
  sc->dpy = MI_DISPLAY(mi);
 
794
  sc = &scs[MI_SCREEN(mi)];
 
795
  sc->lines = (char **) calloc (max_lines+1, sizeof(char *));
 
796
 
776
797
  if ((sc->glx_context = init_GL(mi)) != NULL) {
777
798
    gl_init(mi);
778
799
    reshape_sws (mi, MI_WIDTH(mi), MI_HEIGHT(mi));
791
812
 
792
813
      check_gl_error ("loading font");
793
814
 
794
 
# ifdef GL_TEXTURE_MAX_ANISOTROPY_EXT
795
815
      /* "Anistropic filtering helps for quadrilateral-angled textures.
796
816
         A sharper image is accomplished by interpolating and filtering
797
817
         multiple samples from one or more mipmaps to better approximate
798
818
         very distorted textures.  This is the next level of filtering
799
819
         after trilinear filtering." */
800
 
      if (smooth_p)
801
 
        glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);
802
 
      clear_gl_error();
803
 
# endif
 
820
      if (smooth_p && 
 
821
          strstr ((char *) glGetString(GL_EXTENSIONS),
 
822
                  "GL_EXT_texture_filter_anisotropic"))
 
823
      {
 
824
        GLfloat anisotropic = 0.0;
 
825
        glGetFloatv (GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &anisotropic);
 
826
        if (anisotropic >= 1.0)
 
827
          glTexParameterf (GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 
 
828
                           anisotropic);
 
829
      }
804
830
    }
805
831
  else
806
832
    {
903
929
  glPopMatrix ();
904
930
}
905
931
 
906
 
void
 
932
ENTRYPOINT void
907
933
draw_sws (ModeInfo *mi)
908
934
{
909
935
  sws_configuration *sc = &scs[MI_SCREEN(mi)];
 
936
/*  XtAppContext app = XtDisplayToApplicationContext (sc->dpy);*/
910
937
  Display *dpy = MI_DISPLAY(mi);
911
938
  Window window = MI_WINDOW(mi);
912
939
  int i;
914
941
  if (!sc->glx_context)
915
942
    return;
916
943
 
 
944
#if 0
917
945
  if (XtAppPending (app) & (XtIMTimer|XtIMAlternateInput))
918
946
    XtAppProcessEvent (app, XtIMTimer|XtIMAlternateInput);
 
947
#endif
919
948
 
920
949
  glDrawBuffer (GL_BACK);
921
950
  glXMakeCurrent (dpy, window, *(sc->glx_context));
1055
1084
  sc->star_theta += star_spin;
1056
1085
}
1057
1086
 
 
1087
ENTRYPOINT void
 
1088
release_sws (ModeInfo *mi)
 
1089
{
 
1090
  if (scs) {
 
1091
    int screen;
 
1092
    for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
 
1093
      sws_configuration *sc = &scs[screen];
 
1094
      if (sc->pipe_id)
 
1095
        XtRemoveInput (sc->pipe_id);
 
1096
      if (sc->pipe)
 
1097
        pclose (sc->pipe);
 
1098
      if (sc->pipe_timer)
 
1099
        XtRemoveTimeOut (sc->pipe_timer);
 
1100
 
 
1101
      /* #### there's more to free here */
 
1102
    }
 
1103
    free (scs);
 
1104
    scs = 0;
 
1105
  }
 
1106
  FreeAllGL(mi);
 
1107
}
 
1108
 
 
1109
 
 
1110
XSCREENSAVER_MODULE_2 ("StarWars", starwars, sws)
 
1111
 
1058
1112
#endif /* USE_GL */