/* * Texture feedback demo * Simon Green 6/97 * si@sgi.com * * Compile: * cc -o feedback feedback.c -lglut -lGLU -lGL -lXmu -lXext -lX11 -lm * * Description: * This is an old effect - it's kind of like pointing a video camera at a TV * displaying the signal from itself. * * It also demonstrates the OpenGL 1.1 glCopyTexImage2D function to copy * texture data direct from the framebuffer. You'll need a machine with * reasonably fast texture mapping for it to be fun. * * Usage: * Start it up, hold down the left mouse button and move the mouse up and down * and left and right slowly. Play with the menus. Enjoy! * * Left mouse button - zoom / rotate * Right mouse button - translate (advanced users only) * * Bugs: * Don't try resizing the window. Don't stare at it for too long. */ #include #include #include #include #include #ifdef GL_VERSION_1_1 /* Some files do not define M_PI... */ #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #define MAXSIZE 512 /* Set this to your maximum texture size (square) */ #define TEXT_MESSAGE "OpenGL" float ang = 2.0; float scale = 1.05; float tx = 0.0, ty = 0.0; int oldx, oldy; int lmb = 0; int mmb = 0; int autospin = 0; float atime = 0.0; int smooth = 1; int seedmode = 0; float seedsize = 0.1; int primtype = GL_LINES; float primsize = 1.0; int nprims = 10; float r, g, b; float dr, dg, db; int randomcolours = 0; /* returns a random floating point number between 0.0 and 1.0 */ float frand(void) { return (float) (rand() / 32767.0); } void init_colours(float speed) { r = frand(); g = frand(); b = frand(); dr = frand() / speed; dg = frand() / speed; db = frand() / speed; } void bounce(float *n, float *dn) { *n += *dn; if (*n > 1.0) { *n = 1.0; *dn = -*dn; } if (*n < 0.0) { *n = 0.0; *dn = -*dn; } } /* generate pretty colours by bouncing rgb values up and down */ void set_colour(void) { if (randomcolours) { glColor3f(frand(), frand(), frand()); } else { bounce(&r, &dr); bounce(&g, &dg); bounce(&b, &db); glColor3f(r, g, b); } } /* seed pattern with some random primitives in centre of screen */ void seed(void) { int i; glBegin(primtype); for(i=0; i