Beispiel #1
0
void Polygon_plot_mesh(Patch*p, color_t bg_color)
{
    //glShadeModel(GL_SMOOTH);
    if(bg_color.alpha != 0.0f) {   // if hidden line removal
		glPushAttrib(GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT );
		glDisable(GL_LIGHTING);
		glEnable(GL_POLYGON_OFFSET_FILL);
		glPolygonOffset(1.0, 1.0);
        glColorc(bg_color);

        glBegin(GL_POLYGON);
        for (int j=0; j<p->pointCount; j++) {
            glVertex4dv(p->position[j]);
        }
        glEnd();
		glDisable(GL_POLYGON_OFFSET_FILL);	
		glPopAttrib();
	}


    for (int j=0; j<p->pointCount; j++) {
        glBegin(GL_LINES);
            glVertex4dv(p->position[j]);
            glVertex4dv(p->position[(j+1)%p->pointCount]);
        glEnd();
    }
}
Beispiel #2
0
/** 
 * Pass large doubles to OpenGL and see what
 * happens when converted to float. 
 */
bool
test_float_overflow(void)
{
	bool pass = true;
	int i;
	GLdouble v[3][4];
	GLdouble mat[16];

	/* Make some nice vertices */
	for (i = 0; i < 3; i++) {
		v[i][0] = 0.0;
		v[i][1] = 0.0;
		v[i][2] = 0.0;
		v[i][3] = 1.0;
	}

	/* Set problematic values */
	v[0][0] = 1.0e300;
	v[0][1] = -1.0e300;
	v[1][0] = 1.0e-300;
	v[1][1] = 1.0e-300;

	/* Create a problematic matrix */
	/* Identity * a scalar value of 1e100 */
	for (i = 0; i < 15; i++)
		mat[i] = 0.0;
	mat[0] = mat[5] = mat[10] = mat[15] = 1.0e100;

	/*
	 * Why are these functions the double version? 
	 *
	 * Answer: Because the GL driver may not support double precision 
	 * and may automatically convert the doubles to floats. 
	 * (See glLoadMatrix in OpenGL 2.1 Reference Pages)
	 */

	/* Send matrix to GL */
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadMatrixd(mat);
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	/* Send vertices to GL */
	glBegin(GL_POLYGON);
	glVertex4dv(v[0]);
	glVertex4dv(v[1]);
	glVertex4dv(v[2]);
	glEnd();
	pass &= piglit_check_gl_error(GL_NO_ERROR);

	glPopMatrix();

	return pass;
}
Beispiel #3
0
// I thought about making a lookup table for this, but it would involve an STL map of STL vectors
// and some weird function casts, so I'm doing it the naive way instead.
void GeomRenderer::sendVertex(GLuint vertexIndex)
{
    assert(vertexData.size >= 2 && vertexData.size <= 4);

    switch(vertexData.type)
    {
        case GL_SHORT:
            if (vertexData.size == 2) glVertex2sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 3) glVertex3sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 4) glVertex4sv((const GLshort*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            break;

        case GL_INT:
            if (vertexData.size == 2) glVertex2iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 3) glVertex3iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 4) glVertex4iv((const GLint*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            break;

        case GL_FLOAT:
            if (vertexData.size == 2) glVertex2fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 3) glVertex3fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 4) glVertex4fv((const GLfloat*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            break;

        case GL_DOUBLE:
            if (vertexData.size == 2) glVertex2dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 3) glVertex3dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            if (vertexData.size == 4) glVertex4dv((const GLdouble*)((const char*)vertexData.pointer + vertexIndex*vertexData.stride));
            break;
    }
}
Beispiel #4
0
void Maze::draw(){
	glBegin(GL_QUADS);
	for(auto& i : quads){
		glVertex4dv((double *)&i);
	}
	glEnd();
}
Beispiel #5
0
static void
DrawPoints1(void)
{
  GLint i;

  glColor3f(0.0, 1.0, 0.0);
  glPointSize(2);
  glBegin(GL_POINTS);
  for (i = 0; i < VORDER; i++) {
    glVertex4dv(&point1[i * 4]);
  }
  glEnd();
}
Beispiel #6
0
void __glXDisp_Vertex4dv(GLbyte *pc)
{

#ifdef __GLX_ALIGN64
	if ((unsigned long)(pc) & 7) {
	    __GLX_MEM_COPY(pc-4, pc, 32);
	    pc -= 4;
	}
#endif
	glVertex4dv( 
		(GLdouble *)(pc + 0)
	);
}
Beispiel #7
0
static void
DrawPoints2(void)
{
  GLint i, j;

  glColor3f(1.0, 0.0, 1.0);
  glPointSize(2);
  glBegin(GL_POINTS);
  for (i = 0; i < VMAJOR_ORDER; i++) {
    for (j = 0; j < VMINOR_ORDER; j++) {
      glVertex4dv(&point2[i * 4 * VMINOR_ORDER + j * 4]);
    }
  }
  glEnd();
}
Beispiel #8
0
////////////////////////////////////////////////////////////////
//
//  plot the high light
//
void Highlight(int n, vector* P, vector* N, vector A, vector H, real hl_step, int highlight_type) {

	real func[40];
    int i;

	// calculate the highlight values according to point and normal
	for(i = 0; i<n; i++) 
	{
		if(highlight_type == HIGHLIGHTLINE) {
            func[i] = calc_D( P[i], N[i], A, H);
            //if (calc_D( P[i], N[i], A, H, &func[i]))
			if (hl_error)	
				return; // return if the patch is numerically unstable,
		}
		else {
            func[i] = calc_ref_line( P[i], N[i], A, H);
            //if (calc_ref_line( P[i], N[i], A, H, eye, &func[i]))
			if (hl_error)	
				return; // return if the patch is numerically unstable,
		}
	}


    glEnable(GL_TEXTURE_1D);
    glDisable(GL_LIGHTING);
    glEnable(GL_LIGHTING);

	glBegin(GL_POLYGON);
    for(i=0;i<n;i++) {
		real f = func[i];
		real color;

		color = f/hl_step;

		glTexCoord1d(color);
        glNormal3dv(N[i]);
        glVertex4dv(P[i]);
	}
	glEnd();

    glEnable(GL_LIGHTING);
	glDisable(GL_TEXTURE_1D);
	
}
Beispiel #9
0
void Polygon_plot_patch(Patch*p)
{
    int j, pt;

	glPushAttrib(GL_ENABLE_BIT);
    glEnable(GL_LIGHTING);

    glBegin(GL_POLYGON);
    for (j=0; j<p->pointCount; j++) {
        if(!p->normal_flipped)  // reverse the orientation of the polygon
            pt =  (j);
        else
            pt =  (p->pointCount-1-j);

        glNormal3dv(p->normal[pt]);

        double size = 64.0;
        glTexCoord2d((p->position[pt])[0]/size,(p->position[pt])[2]/size);
        glVertex4dv(p->position[pt]);
    }
    glEnd();

	glPopAttrib();
}
Beispiel #10
0
void vertex4(const Point &p)
{
    glVertex4dv(p.v);
}
Beispiel #11
0
template< > inline void glVertex4v< Vector3r >		( const Vector3r v )		{	glVertex4dv((double*)&v);		};
Beispiel #12
0
/////////////////////////////////////////////////////////
// Render
//
void GEMglVertex4dv :: render(GemState *state) {
	glVertex4dv (v);
}
inline void glVertex4v( const GLdouble * v )	{ glVertex4dv( v ); }
Beispiel #14
0
M(void, glVertex4dv, jobject v) {
	glVertex4dv(BUFF(GLdouble, v));
}
Beispiel #15
0
// return 1 if this patch needs to be subdivided 
// ( triangles intersect the normal to the opposite direction)
// return 0 if ok
int EncQuadBezier::make_lam()
{
    VEC  nor, bend, hv0, hv1; // bend = bdir
    double  lam, h;
    int  i,j, m, sm,sp,s2, idx[4][2], sd, ii,jj,
         nsgn, nnsgn, cr,ncr; // booleans
    VEC  env[2][4]; // env[1]=(upper)=outer

	int  need_subdiv = 0; // return value

    for (i=0; i<d1; i++) 
        for (j=0; j<d1; j++) 
            lambda[i][j][0]= lambda[i][j][1]= 0;
    for (i=0; i<segu; i++) {
        for (j=0; j<segv; j++) {
            // normal at center determines which bilinear
            // to choose, eg +++ in all components means
            //  ubd ubd ubd = outer
            //  lbd lbd lbd = inner
            // determine diagonal:
            // curvature  - +
            //            + -
            VEC mid[2][2];

            for(m=0;m<DIM;m++) {
                mid[0][0][m] =(get_enc(1,i,j)[m]   + get_enc(0,i,j)[m])/2;
                mid[0][1][m] =(get_enc(1,i,j+1)[m] + get_enc(0,i,j+1)[m])/2;
                mid[1][0][m] =(get_enc(1,i+1,j)[m] + get_enc(0,i+1,j)[m])/2;
                mid[1][1][m] =(get_enc(1,i+1,j+1)[m] + get_enc(0,i+1,j+1)[m])/2;
            }

            for (m=0; m<DIM; m++) 
                bend[m] = mid[0][0][m]+mid[1][1][m]-mid[0][1][m]-mid[1][0][m];

            VVminus(mid[1][1],mid[0][0],hv0);
            VVminus(mid[0][1],mid[1][0],hv1);
            VVcross(hv0,hv1, nor);

            // if (crease >= 0)  // triangles |/| or flat
            h = VVmult(sup_nor[i][j],nor);
            if (h < 0) printf("h %lf\n",h);
            h = VVmult(bend,nor);
            cr = (h >=  0); // convex up in normal direction == cr=1

            cralong[i*(segv)+j] = cr; // record crease of bilinear

            // translation table 
            // 3 2
            // 0 1
            idx[0][0] = i; idx[0][1] = j;
            idx[1][0] = i+1; idx[1][1] = j;
            idx[2][0] = i+1; idx[2][1] = j+1;
            idx[3][0] = i; idx[3][1] = j+1;


            // quadrant of the normal decides on choice of bilinear
            // depends on whether the normal is "outward" pointing
            // bd[1]...[x]: x component larger
            for (m=0; m<DIM; m++) {
                nsgn = (nor[m] >= 0); // if 1 then want bd[1] -- except when
                // normal is inward pointing (cube)
                nnsgn = (nsgn+1)%2;
                for (sd=0; sd<4; sd++) {
                    // (nsgn=1) want upper bd in normal dir (env[1]..)
                    ii = idx[sd][0]; jj = idx[sd][1];
                    env[1][sd][m] = get_enc(nsgn,ii,jj)[m]; 
                    env[0][sd][m] = get_enc(nnsgn,ii,jj)[m];
                }
            }

            if(0) // draw the nor (put it in the center of the quad)
            {
                VEC center, sum;
                for(m=0;m<DIM;m++)
                {
                    // center of all four up-enclosure corners
                    center[m] = (env[1][0][m] + env[1][1][m] +
                                 env[1][2][m] + env[1][3][m])/4;
                }
                Normalize(nor);
                VVadd(1.0, center, 20, nor, sum);
                glDisable(GL_LIGHTING);
                glColor3f(0.3,0.0, 1.0);
                glBegin(GL_LINES);
                glVertex4dv(center);
                glVertex4dv(sum);
                glEnd();
                glEnable(GL_LIGHTING);
            }

            // compute lambdas based on crease orientation 
            // cr==1 for ridge 02 in normal direction 
            //       isect with  2 env[1] and 1 env[0]
            for (sd=0; sd<4; sd++) { // intersect with 3 total!

                ii = idx[sd][0]; jj = idx[sd][1];
                sp = (sd+1)%4; s2 = (sd+2)%4; sm = (sd+3)%4;
                ncr = (cr+1)%2;
                //  sm---s2
                //   |    |
                //  sd---sp

                lam = plane_intersect(sup_pt[ii][jj], sup_nor[ii][jj],
                    env[cr][sd], env[cr][sp], env[cr][s2]);

                // Why (cr) selection? if cr then q=nor same dir as bend, as
                // supnor  -- so compare with the two planes of the
                // triangles (cr) and then with the other (ncr)
                //
                if (cr) { if (lam > lambda[ii][jj][1])  lambda[ii][jj][1] = lam;
                } else  { 
                    if (lam < lambda[ii][jj][0])  { lambda[ii][jj][0] = lam; }
                }

                if ((cr && (lam < -tol) ) || (ncr && (lam > tol)))
                {
                    printf("not ok 1 cr %d lam %lf iijj %d %d \n",cr,lam,ii,jj);
					need_subdiv = 1; // need to be subdivied
                }
                    if(debugchoice & EXTTRI) {
                        set_color(ncr);
                        if(!ncr)  // only outter enclosure
                        DrawTri(env[cr][sd], env[cr][sp], env[cr][s2]);
                    }


                //else printf(" ok 1 \n");
                lam = plane_intersect(sup_pt[ii][jj], sup_nor[ii][jj], 
                    env[cr][sd], env[cr][s2], env[cr][sm]);
                if (cr) { if (lam > lambda[ii][jj][1])  lambda[ii][jj][1] = lam;
                } else  { 
                    if (lam < lambda[ii][jj][0]){ lambda[ii][jj][0] = lam; }
                }

                if ((cr && (lam < -tol) ) || (ncr && (lam > tol)))
                {
                    printf("not ok 2 cr %d lam %lf iijj %d %d \n",cr,lam,ii,jj);
					need_subdiv = 1; // need to be subdivied
                }
                    if(debugchoice & EXTTRI) {
                        set_color(ncr);
                        if(!ncr)  // only outter enclosure
                        DrawTri(env[cr][sd], env[cr][s2], env[cr][sm]);
                    }
                //else printf(" ok 2 \n");

                lam = plane_intersect(sup_pt[ii][jj], sup_nor[ii][jj], 
                    env[ncr][sd], env[ncr][sp], env[ncr][sm]);
                if (ncr) { if (lam > lambda[ii][jj][1])  lambda[ii][jj][1] = lam;
                } else  { 
                    if (lam < lambda[ii][jj][0]) { lambda[ii][jj][0] = lam; }
                }


                if ((cr && (lam > tol) ) || (ncr && (lam < -tol)))
                {
                    printf("not ok 3 cr %d lam %lf iijj %d %d \n",cr,lam,ii,jj);
					need_subdiv = 1; // need to be subdivied
                }
                    if(debugchoice & EXTTRI) {
                        set_color(cr);
                        if(!cr)  // only outter enclosure
                        DrawTri(env[ncr][sd], env[ncr][sp], env[ncr][sm]);
                    }

                //else printf(" ok 3 \n");

                cr = ncr;  // crease opposite at next point
            }
            // w...[1] has pos (in normal dir) values
        }
    }

	// subdivide the patch if needed
	return need_subdiv;
}