Code Search for Developers
 
 
  

vp2.cxx from gzz at Krugle


Show vp2.cxx syntax highlighted

/*
vp2.cxx
 *    
 *    Copyright (c) 2003, Janne Kujala and Tuomas J. Lukka
 *    
 *    This file is part of Gzz.
 *    
 *    Gzz is free software; you can redistribute it and/or modify it under
 *    the terms of the GNU Lesser General Public License as published by
 *    the Free Software Foundation; either version 2 of the License, or
 *    (at your option) any later version.
 *    
 *    Gzz is distributed in the hope that it will be useful, but WITHOUT
 *    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 *    or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
 *    Public License for more details.
 *    
 *    You should have received a copy of the GNU Lesser General
 *    Public License along with Gzz; if not, write to the Free
 *    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *    
 *    
 */
/*
 * Written by Janne Kujala and Tuomas J. Lukka
 */

#include <math.h>
#include <iostream>
#include <vector>
#include <GL/glut.h>
#include <unistd.h>

#include <GummiBasic.hxx>

#define GLERR { int er = glGetError(); if(er != GL_NO_ERROR) {\
		    cout << "ERROR "<<__FILE__<<" "<<__LINE__ \
			<<gluErrorString(er)<<"\n"; \
			abort();\
}	\
	    }

using std::cout;


typedef Gummi::Point<float> Pt;
typedef Gummi::Point3<float> ZPt;
typedef Gummi::Vector<float> Vec;
typedef Gummi::Vector3<float> ZVec;

struct Err {};

double t = 0;
float offs = 0;
volatile long frames = 0;

inline float clamp(float x) { return x < 0 ? 0 : x > 1 ? 1 : x; }

inline float func4(float x) { return 1-sqrt(sqrt(1 - x*x*x*x)); }

void display() {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//    glClear(GL_ACCUM_BUFFER_BIT);

    // cout << "DISPLAY\n";

    glColor3f(1, 1, 1);

    glEnable(GL_BLEND);
    //glEnable(GL_ALPHA_TEST);
    //glAlphaFunc(GL_GREATER, 0.1);
    //glEnable(GL_DEPTH_TEST);

    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
//    glDisable(GL_TEXTURE_2D);
    /*
 cout << "Cell: " << cell;
    cell.tex.bind();
    glBegin(GL_QUADS);
	cell.texcoord(0, 0);
	glVertex2f(0, 0);
	cell.texcoord(0, 1);
	glVertex2f(0, 1000);
	cell.texcoord(1, 1);
	glVertex2f(1000, 1000);
	cell.texcoord(1, 0);
	glVertex2f(1000, 0);
    glEnd();
    */

    GLERR

    float noiseargs[3] = {
	1.5,
	2.3,
	offs * 0.1
    };

    float noise10args[3] = {
	1.5,
	2.3,
    };

#define NOISE (noiseargs[0] += 5.1, noiseargs[1] += 3.2, \
		Perlin::noise3(noiseargs))
#define NOISE_T (0.5 * NOISE)
#define NOISE_M (5 * NOISE)

	// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    //glVertexAttrib3fNV(14,  -1, -1, 0);
    //glVertexAttrib3fNV(15,   1,  1, 0);

    // Constants
    glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 5, .15, 1, 0, 0);
    glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 6, .1, 1.1, 1, 0);

#define DIV 64
#define NUM 2
    glColor3f(1, 1, 1);
    offs += 0.001;

    for (int i = 1; i < NUM; i++) {

	ZVec v0(-1, -1, 0);
	ZVec v1(1,  1, 0);

	double s = sin(offs*i*M_PI/32.0);
	double c = cos(offs*i*M_PI/32.0);

	ZVec xv(4*c, -4*s, 0);
	ZVec yv(s, c, 0);

	// End points of the contour
	glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 0, v0.x, v0.y, v0.z, 1); 
	glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 1, v1.x, v1.y, v1.z, 1); 

	// Tangent and normal vectors of the connector
	glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 2, xv.x, xv.y, xv.z, 0);
	glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 3, yv.x, yv.y, yv.z, 0);
	
	// Connector origin
	glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV, 4,  0, 0, 0, 1); 



	//glLineWidth(5);


	if (glIsEnabled(GL_VERTEX_PROGRAM_NV)) {
#if 0
	  glBegin(GL_LINE_STRIP);
	  for (double x = 0; x <= 1; x += 1.0/DIV)
	    glVertex3f(x, 0, 0);
	  glEnd();
#elif 0
	  glCallList(1);
#elif 1
	  int par[4] = { DIV, DIV, 1, 1 };
	  glMapParameterivNV(GL_EVAL_2D_NV, GL_MAP_TESSELLATION_NV, par);
	  GLERR;

	  float ctrl[2][2][4] = {
	    { { 0, 0, 0, 0 }, 
	      { 1, 0, 0, 0 } },
	    { { 0, .005, 0, 0 }, 
	      { 1, .005, 0, 0 } }, 
	  };

	  glMapControlPointsNV(GL_EVAL_2D_NV, 0, GL_FLOAT, 
			       4*sizeof(float), 4*2*sizeof(float),
			       2, 2, 
			       0,
			       (GLvoid*)ctrl);
	  GLERR;
	  glEvalMapsNV(GL_EVAL_2D_NV, GL_FILL);
	  GLERR;
	  
#else
	  // Very slow
	  float ctrl[] = { 0, 0, 0,
			   1, 0, 0 };
	  glEnable(GL_MAP1_VERTEX_3);
	  glMap1f(GL_MAP1_VERTEX_3, 0, 1, 3, 2, ctrl);
	  glMapGrid1f(DIV, 0, 1);
	  glEvalMesh1(GL_LINE, 0, DIV);
	  glDisable(GL_MAP1_VERTEX_3);
#endif
	} else  {
	  ZVec v = v1 - v0;
	  glBegin(GL_LINE_STRIP);
	  for (double x = 0; x <= 1; x += 1.0/DIV) {
	    ZVec pt = v0 + x * v;
	    double t = xv.dot(pt);
	    pt = pt + func4(clamp(1.1f-fabs(t))) * yv;
	    glVertex3f(pt.x, pt.y, pt.z);
	  }
	  glEnd();
	}

    }


	// glAccum(GL_ACCUM, 1.0/8);

    /*
    glProgramParameter4dNV(GL_VERTEX_PROGRAM_NV, 1,
	    sin(offs), sin(offs*1.67), sin(offs*2.31), sin(offs*3.16)
	    );
	    */


    // glAccum(GL_RETURN, 1.0);

    GLERR

    t += 0.02;

    glFlush();
    frames++;

    glutSwapBuffers();
    glFlush();

    //cout << "Drew...\n";

    GLERR
}

void reshape(int w, int h) {
    glViewport(0, 0, w, h);
    // glMatrixMode(GL_PROJECTION);
    // glLoadIdentity();
    // glOrtho(0, w, 0, h, -100, 100);
    // glTranslatef(0, h, 0);
    // glScalef(1, -1, 1);
    glMatrixMode(GL_MODELVIEW);
}

    int c;

const char *prog = "!!VP1.0\n\
    MOV R0, c[0];\n\
    ADD R1, c[1], -R0;\n\
    MAD R2, v[OPOS].xxxx, R1, R0;\n\
    ADD R3, R2, -c[4];\n\
    DP4 R4, R3, c[2];\n\
\
    # R4.x <-- (1/sqrt(abs(R4.x))-1)*.15 clamped to [0,1] \n\
    #RSQ R4, R4.x;\n\
    #MAD R4.x, R4.x, c[5].x, -c[5].x;\n\
    #MAX R4.x, R4.x, c[5].z;\n\
    #MIN R4.x, R4.x, c[5].y;\n\
\
    # R4.x <-- 1-sqrt(1-clamp(1.1-abs(R4.x))**2) \n\
    #MAX R4.x, R4.x, -R4.x;\n\
    #ADD R4.x, c[6].y, -R4.x;\n\
    #MIN R4.x, R4.x, c[6].z;\n\
    #MAX R4.x, R4.x, c[6].w;\n\
    #MAD R4.x, R4.x, -R4.x, c[6].z;\n\
    #RSQ R4.x, R4.x;\n\
    #RCP R4.x, R4.x;\n\
    #ADD R4.x, c[6].z, -R4.x;\n\
\
    # R4.x <-- 1-(1-clamp(1.1-abs(R4.x))**4)^(1/4) \n\
    MAX R4.x, R4.x, -R4.x;\n\
    ADD R4.x, c[6].y, -R4.x;\n\
    MIN R4.x, R4.x, c[6].z;\n\
    MAX R4.x, R4.x, c[6].w;\n\
    MUL R4.x, R4.x, R4.x;\n\
    MAD R4.x, R4.x, -R4.x, c[6].z;\n\
    RSQ R4.x, R4.x;\n\
    RSQ R4.x, R4.x;\n\
    ADD R4.x, c[6].z, -R4.x;\n\
\
    MAD R2, v[OPOS].yyyy, c[2], R2;\n\
    MAD o[HPOS], R4.xxxx, c[3], R2;\n\
    MOV o[COL0], v[COL0];\n\
    END\n";


void init() {
    glClearColor(0, 0, 0, 1);

    glEnable(GL_VERTEX_PROGRAM_NV);
    glLoadProgramNV(GL_VERTEX_PROGRAM_NV, 1, strlen(prog),
	    (const GLubyte *)prog);
    GLERR;
    glBindProgramNV(GL_VERTEX_PROGRAM_NV, 1);
    GLERR;
    // glShadeModel(GL_FLAT);

	glNewList(1, GL_COMPILE);
	  glBegin(GL_LINE_STRIP);
	  for (double x = 0; x <= 1; x += 1.0/DIV)
	    glVertex3f(x, 0, 0);
	  glEnd();
	glEndList();
}


void idle() { 
    glutPostRedisplay(); 
}

void keypress(unsigned char key, int x, int y) {
  cout << key << " pressed\n";
  switch (key) {
  case '0': glDisable(GL_VERTEX_PROGRAM_NV); break;
  case '1': glEnable(GL_VERTEX_PROGRAM_NV); break;
  }
}

void timer(int value) {
  glutTimerFunc(1000, timer, 0); 
  cout << frames << " frames\n";
  frames = 0;
}

int main(int argc, char **argv) {
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
    // glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA);
    glutInitWindowSize(800,800);
    glutInitWindowPosition(0,0);
    glutCreateWindow("fontTest");


    init();

    glutReshapeFunc(reshape);
    glutDisplayFunc(display);
    glutKeyboardFunc(keypress);
    timer(0); 
    glutIdleFunc(idle);
    glutMainLoop();
    return 0;
}





See more files for this project here

gzz

An implementation of Ted Nelson's ZZstructure. ZZstructure is a new type of programming platform for structured data.

Project homepage: http://savannah.nongnu.org/projects/gzz
Programming language(s): C++,Java,Python
License: lgpl21

  pdlimg/
    Makefile
    Makefile.PL
    bg.pl
    cell.pl
    cellimages.ly
    draw.cxx
    draw2.cxx
    draw3.cxx
    draw4.cxx
    lib.pl
    mask_tcell0.png
    mask_tcell1.png
    mask_tcell2.png
    mask_tcell3.png
    mask_tcell4.png
    mask_tcell5.png
    mask_tcell6.png
    mask_tcell7.png
    mask_tconn0.png
    mask_tconn1.png
    mask_tconn2.png
    mask_tconn3.png
    mask_tconn4.png
    mask_tconn5.png
    mask_tconn6.png
    mask_tconn7.png
    mask_tconn8.png
    mkf
    pdlperlin.pd
    simplecell.pl
    slice.pl
    tcell.png
    tcell0.png
    tcell1.png
    tcell2.png
    tcell3.png
    tcell4.png
    tcell5.png
    tcell6.png
    tcell7.png
    tconn.png
    tconn0.png
    tconn1.png
    tconn2.png
    tconn3.png
    tconn4.png
    tconn5.png
    tconn6.png
    tconn7.png
    tconn8.png
    test.pl
    volturb.pl
  bgtest.cxx
  colorvis.cxx
  solid.cxx
  vp1.cxx
  vp2.cxx
  vp3.cxx