projects
/
xscreensaver
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
From http://www.jwz.org/xscreensaver/xscreensaver-5.37.tar.gz
[xscreensaver]
/
hacks
/
glx
/
engine.c
diff --git
a/hacks/glx/engine.c
b/hacks/glx/engine.c
index 3310bfe8f555b50e560f7d56eb6b2714545424a2..f26f68d10ae86359885ff8169ed74f3850157cb5 100644
(file)
--- a/
hacks/glx/engine.c
+++ b/
hacks/glx/engine.c
@@
-24,15
+24,17
@@
#ifdef STANDALONE
#define DEFAULTS "*delay: 30000 \n" \
"*showFPS: False \n" \
#ifdef STANDALONE
#define DEFAULTS "*delay: 30000 \n" \
"*showFPS: False \n" \
- "*titleFont: -*-helvetica-medium-r-normal-*-180-*\n" \
+ "*suppressRotationAnimation: True\n" \
+ "*titleFont: -*-helvetica-medium-r-normal-*-*-180-*-*-*-*-*-*\n" \
# define refresh_engine 0
# define refresh_engine 0
+# define release_engine 0
# include "xlockmore.h" /* from the xscreensaver distribution */
#else /* !STANDALONE */
# include "xlock.h" /* from the xlockmore distribution */
#endif /* !STANDALONE */
# include "xlockmore.h" /* from the xscreensaver distribution */
#else /* !STANDALONE */
# include "xlock.h" /* from the xlockmore distribution */
#endif /* !STANDALONE */
-#include "
glxfonts
.h"
+#include "
texfont
.h"
#include "rotator.h"
#include "gltrackball.h"
#include "rotator.h"
#include "gltrackball.h"
@@
-77,7
+79,7
@@
ENTRYPOINT ModeSpecOpt engine_opts = {countof(opts), opts, countof(vars), vars,
#ifdef USE_MODULES
ModStruct engine_description =
#ifdef USE_MODULES
ModStruct engine_description =
-{"engine", "init_engine", "draw_engine",
"release_engine"
,
+{"engine", "init_engine", "draw_engine",
NULL
,
"draw_engine", "init_engine", NULL, &engine_opts,
1000, 1, 2, 1, 4, 1.0, "",
"A four stroke engine", 0, NULL};
"draw_engine", "init_engine", NULL, &engine_opts,
1000, 1, 2, 1, 4, 1.0, "",
"A four stroke engine", 0, NULL};
@@
-109,8
+111,7
@@
typedef struct {
rotator *rot;
trackball_state *trackball;
Bool button_down_p;
rotator *rot;
trackball_state *trackball;
Bool button_down_p;
- XFontStruct *xfont;
- GLuint font_dlist;
+ texture_font_data *font_data;
char *engine_name;
int engineType;
int movepaused;
char *engine_name;
int engineType;
int movepaused;
@@
-280,13
+281,13
@@
static void make_tables(Engine *e)
float f;
f = ONEREV / (M_PI * 2);
float f;
f = ONEREV / (M_PI * 2);
- for (i = 0 ; i <
=
TWOREV ; i++) {
+ for (i = 0 ; i < TWOREV ; i++) {
e->sin_table[i] = sin(i/f);
}
e->sin_table[i] = sin(i/f);
}
- for (i = 0 ; i <
=
TWOREV ; i++) {
+ for (i = 0 ; i < TWOREV ; i++) {
e->cos_table[i] = cos(i/f);
}
e->cos_table[i] = cos(i/f);
}
- for (i = 0 ; i <
=
TWOREV ; i++) {
+ for (i = 0 ; i < TWOREV ; i++) {
e->tan_table[i] = tan(i/f);
}
}
e->tan_table[i] = tan(i/f);
}
}
@@
-327,8
+328,10
@@
static int cylinder (Engine *e, GLfloat x, GLfloat y, GLfloat z,
for (a = sangle ; a <= angle || b <= angle ; a+= step) {
y2=outer*(float)e->sin_table[a]+y;
z2=outer*(float)e->cos_table[a]+z;
for (a = sangle ; a <= angle || b <= angle ; a+= step) {
y2=outer*(float)e->sin_table[a]+y;
z2=outer*(float)e->cos_table[a]+z;
- if (endcaps)
- y2c[a] = y2; z2c[a] = z2; /* cache for later */
+ if (endcaps) {
+ y2c[a] = y2;
+ z2c[a] = z2; /* cache for later */
+ }
if (tube) {
Y2=inner*(float)e->sin_table[a]+y;
Z2=inner*(float)e->cos_table[a]+z;
if (tube) {
Y2=inner*(float)e->sin_table[a]+y;
Z2=inner*(float)e->cos_table[a]+z;
@@
-531,7
+534,8
@@
static int makepiston(Engine *e)
int polys = 0;
GLfloat colour[] = {0.6, 0.6, 0.6, 1.0};
int polys = 0;
GLfloat colour[] = {0.6, 0.6, 0.6, 1.0};
- e->piston_list = glGenLists(1);
+ /* if (e->piston_list) glDeleteLists(1, e->piston_list); */
+ if (! e->piston_list) e->piston_list = glGenLists(1);
glNewList(e->piston_list, GL_COMPILE);
glRotatef(90, 0, 0, 1);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colour);
glNewList(e->piston_list, GL_COMPILE);
glRotatef(90, 0, 0, 1);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, colour);
@@
-583,7
+587,7
@@
static int boom(Engine *e, GLfloat x, GLfloat y, int s)
glLightfv(GL_LIGHT1, GL_POSITION, e->boom_lpos);
glLightfv(GL_LIGHT1, GL_DIFFUSE, e->boom_red);
glLightfv(GL_LIGHT1, GL_SPECULAR, e->boom_red);
glLightfv(GL_LIGHT1, GL_POSITION, e->boom_lpos);
glLightfv(GL_LIGHT1, GL_DIFFUSE, e->boom_red);
glLightfv(GL_LIGHT1, GL_SPECULAR, e->boom_red);
- glLight
i
(GL_LIGHT1, GL_LINEAR_ATTENUATION, 1.3);
+ glLight
f
(GL_LIGHT1, GL_LINEAR_ATTENUATION, 1.3);
glLighti(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, e->boom_red);
glLighti(GL_LIGHT1, GL_CONSTANT_ATTENUATION, 0);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, e->boom_red);
@@
-598,8
+602,9
@@
static int boom(Engine *e, GLfloat x, GLfloat y, int s)
return polys;
}
return polys;
}
-static int display(
Engine *e
)
+static int display(
ModeInfo *mi
)
{
{
+ Engine *e = &engine[MI_SCREEN(mi)];
int polys = 0;
GLfloat zb, yb;
float rightSide;
int polys = 0;
GLfloat zb, yb;
float rightSide;
@@
-614,6
+619,16
@@
static int display(Engine *e)
e->lookat[0], e->lookat[1], e->lookat[2],
0.0, 1.0, 0.0);
glPushMatrix();
e->lookat[0], e->lookat[1], e->lookat[2],
0.0, 1.0, 0.0);
glPushMatrix();
+
+# ifdef HAVE_MOBILE /* Keep it the same relative size when rotated. */
+ {
+ GLfloat h = MI_HEIGHT(mi) / (GLfloat) MI_WIDTH(mi);
+ int o = (int) current_device_rotation();
+ if (o != 0 && o != 180 && o != -180)
+ glScalef (1/h, 1/h, 1/h);
+ }
+# endif
+
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_sp);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_sp);
glLightfv(GL_LIGHT0, GL_POSITION, lightpos);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_sp);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_sp);
@@
-623,9
+638,12
@@
static int display(Engine *e)
get_position (e->rot, &x, &y, &z, !e->button_down_p);
glTranslatef(x*16-9, y*14-7, z*16-10);
}
get_position (e->rot, &x, &y, &z, !e->button_down_p);
glTranslatef(x*16-9, y*14-7, z*16-10);
}
+
if (spin) {
double x, y, z;
if (spin) {
double x, y, z;
+
gltrackball_rotate (e->trackball);
gltrackball_rotate (e->trackball);
+
get_rotation(e->rot, &x, &y, &z, !e->button_down_p);
glRotatef(x*ONEREV, 1.0, 0.0, 0.0);
glRotatef(y*ONEREV, 0.0, 1.0, 0.0);
get_rotation(e->rot, &x, &y, &z, !e->button_down_p);
glRotatef(x*ONEREV, 1.0, 0.0, 0.0);
glRotatef(y*ONEREV, 0.0, 1.0, 0.0);
@@
-644,7
+662,7
@@
static int display(Engine *e)
/* init the ln[] matrix for speed */
if (e->ln_init == 0) {
/* init the ln[] matrix for speed */
if (e->ln_init == 0) {
- for (e->ln_init = 0 ; e->ln_init <
730
; e->ln_init++) {
+ for (e->ln_init = 0 ; e->ln_init <
countof(e->sin_table)
; e->ln_init++) {
zb = e->sin_table[e->ln_init];
yb = e->cos_table[e->ln_init];
/* y ordinate of piston */
zb = e->sin_table[e->ln_init];
yb = e->cos_table[e->ln_init];
/* y ordinate of piston */
@@
-770,7
+788,8
@@
static int makeshaft (Engine *e)
float crankThick = 0.2;
float crankDiam = 0.3;
float crankThick = 0.2;
float crankDiam = 0.3;
- e->shaft_list = glGenLists(1);
+ /* if (e->shaft_list) glDeleteLists(1, e->shaft_list); */
+ if (! e->shaft_list) e->shaft_list = glGenLists(1);
glNewList(e->shaft_list, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
glNewList(e->shaft_list, GL_COMPILE);
glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
@@
-831,7
+850,8
@@
ENTRYPOINT void reshape_engine(ModeInfo *mi, int width, int height)
glViewport(0,0,(GLint)width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glViewport(0,0,(GLint)width, (GLint) height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
- glFrustum(-1.0,1.0,-1.0,1.0,1.5,70.0);
+/* glFrustum(-1.0,1.0,-1.0,1.0,1.5,70.0);*/
+ gluPerspective(40.0,((GLdouble)width)/height,1.5,70.0);
glMatrixMode(GL_MODELVIEW);
e->win_h = height;
e->win_w = width;
glMatrixMode(GL_MODELVIEW);
e->win_h = height;
e->win_w = width;
@@
-843,11
+863,7
@@
ENTRYPOINT void init_engine(ModeInfo *mi)
int screen = MI_SCREEN(mi);
Engine *e;
int screen = MI_SCREEN(mi);
Engine *e;
- if (engine == NULL) {
- if ((engine = (Engine *) calloc(MI_NUM_SCREENS(mi),
- sizeof(Engine))) == NULL)
- return;
- }
+ MI_INIT(mi, engine, NULL);
e = &engine[screen];
e->window = MI_WINDOW(mi);
e = &engine[screen];
e->window = MI_WINDOW(mi);
@@
-887,10
+903,11
@@
ENTRYPOINT void init_engine(ModeInfo *mi)
move ? wander_speed : 0,
True);
move ? wander_speed : 0,
True);
- e->trackball = gltrackball_init ();
+ e->trackball = gltrackball_init (
True
);
}
}
- if ((e->glx_context = init_GL(mi)) != NULL) {
+ if (!e->glx_context && /* re-initting breaks print_texture_label */
+ (e->glx_context = init_GL(mi)) != NULL) {
reshape_engine(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
} else {
MI_CLEARWINDOW(mi);
reshape_engine(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
} else {
MI_CLEARWINDOW(mi);
@@
-904,7
+921,8
@@
ENTRYPOINT void init_engine(ModeInfo *mi)
make_tables(e);
e->engineType = find_engine(which_engine);
make_tables(e);
e->engineType = find_engine(which_engine);
- e->engine_name = malloc(200);
+ if (!e->engine_name)
+ e->engine_name = malloc(200);
sprintf (e->engine_name,
"%s\n%s%d%s",
engines[e->engineType].engineName,
sprintf (e->engine_name,
"%s\n%s%d%s",
engines[e->engineType].engineName,
@@
-916,7
+934,9
@@
ENTRYPOINT void init_engine(ModeInfo *mi)
e->shaft_polys = makeshaft(e);
e->piston_polys = makepiston(e);
e->shaft_polys = makeshaft(e);
e->piston_polys = makepiston(e);
- load_font (mi->dpy, "titleFont", &e->xfont, &e->font_dlist);
+
+ if (!e->font_data)
+ e->font_data = load_texture_font (mi->dpy, "titleFont");
}
ENTRYPOINT Bool
}
ENTRYPOINT Bool
@@
-927,36
+947,24
@@
engine_handle_event (ModeInfo *mi, XEvent *event)
if (event->xany.type == ButtonPress &&
event->xbutton.button == Button1)
{
if (event->xany.type == ButtonPress &&
event->xbutton.button == Button1)
{
- e->button_down_p = True;
- gltrackball_start (e->trackball,
- event->xbutton.x, event->xbutton.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
- e->movepaused = 1;
return True;
}
else if (event->xany.type == ButtonRelease &&
event->xbutton.button == Button1) {
return True;
}
else if (event->xany.type == ButtonRelease &&
event->xbutton.button == Button1) {
- e->button_down_p = False;
e->movepaused = 0;
e->movepaused = 0;
- return True;
}
}
- else if (event->xany.type == ButtonPress &&
- (event->xbutton.button == Button4 ||
- event->xbutton.button == Button5 ||
- event->xbutton.button == Button6 ||
- event->xbutton.button == Button7))
+
+ if (gltrackball_event_handler (event, e->trackball,
+ MI_WIDTH (mi), MI_HEIGHT (mi),
+ &e->button_down_p))
+ return True;
+ else if (screenhack_event_helper (MI_DISPLAY(mi), MI_WINDOW(mi), event))
{
{
- gltrackball_mousewheel (e->trackball, event->xbutton.button, 10,
-
!!event->xbutton.state
);
+ which_engine = NULL; /* randomize */
+
init_engine(mi
);
return True;
}
return True;
}
- else if (event->xany.type == MotionNotify &&
- e->button_down_p) {
- gltrackball_track (e->trackball,
- event->xmotion.x, event->xmotion.y,
- MI_WIDTH (mi), MI_HEIGHT (mi));
- return True;
- }
+
return False;
}
return False;
}
@@
-972,29
+980,19
@@
ENTRYPOINT void draw_engine(ModeInfo *mi)
glXMakeCurrent(disp, w, *(e->glx_context));
glXMakeCurrent(disp, w, *(e->glx_context));
- mi->polygon_count = display(
e
);
+ mi->polygon_count = display(
mi
);
+ glColor3f (1, 1, 0);
if (do_titles)
if (do_titles)
- print_gl_string (mi->dpy, e->xfont, e->font_dlist,
- mi->xgwa.width, mi->xgwa.height,
- 10, mi->xgwa.height - 10,
- e->engine_name, False);
+ print_texture_label (mi->dpy, e->font_data,
+ mi->xgwa.width, mi->xgwa.height,
+ 1, e->engine_name);
if(mi->fps_p) do_fps(mi);
glFinish();
glXSwapBuffers(disp, w);
}
if(mi->fps_p) do_fps(mi);
glFinish();
glXSwapBuffers(disp, w);
}
-ENTRYPOINT void
-release_engine(ModeInfo *mi)
-{
- if (engine != NULL) {
- (void) free((void *) engine);
- engine = NULL;
- }
- FreeAllGL(mi);
-}
-
XSCREENSAVER_MODULE ("Engine", engine)
#endif
XSCREENSAVER_MODULE ("Engine", engine)
#endif