Exemplo n.º 1
0
//----------------------------------------------------------
void ofGLRenderer::draw(ofMesh & vertexData, ofPolyRenderMode renderType, bool useColors, bool useTextures, bool useNormals){
		if (bSmoothHinted) startSmoothing();
#ifndef TARGET_OPENGLES
		glPushAttrib(GL_POLYGON_BIT);
		glPolygonMode(GL_FRONT_AND_BACK, ofGetGLPolyMode(renderType));
		draw(vertexData,useColors,useTextures,useNormals);
		glPopAttrib(); //TODO: GLES doesnt support polygon mode, add renderType to gl renderer?
#else
		if(vertexData.getNumVertices()){
			glEnableClientState(GL_VERTEX_ARRAY);
			glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), vertexData.getVerticesPointer());
		}
		if(vertexData.getNumNormals() && useNormals){
			glEnableClientState(GL_NORMAL_ARRAY);
			glNormalPointer(GL_FLOAT, 0, vertexData.getNormalsPointer());
		}
		if(vertexData.getNumColors() && useColors){
			glEnableClientState(GL_COLOR_ARRAY);
			glColorPointer(4,GL_FLOAT, sizeof(ofFloatColor), vertexData.getColorsPointer());
		}

		if(vertexData.getNumTexCoords() && useTextures){
			glEnableClientState(GL_TEXTURE_COORD_ARRAY);
			glTexCoordPointer(2, GL_FLOAT, 0, vertexData.getTexCoordsPointer());
		}

		GLenum drawMode;
		switch(renderType){
		case OF_MESH_POINTS:
			drawMode = GL_POINTS;
			break;
		case OF_MESH_WIREFRAME:
			drawMode = GL_LINES;
			break;
		case OF_MESH_FILL:
			drawMode = ofGetGLPrimitiveMode(vertexData.getMode());
			break;
		default:
			drawMode = ofGetGLPrimitiveMode(vertexData.getMode());
			break;
		}

		if(vertexData.getNumIndices()){
			glDrawElements(drawMode, vertexData.getNumIndices(),GL_UNSIGNED_SHORT,vertexData.getIndexPointer());
		}else{
			glDrawArrays(drawMode, 0, vertexData.getNumVertices());
		}
		if(vertexData.getNumColors() && useColors){
			glDisableClientState(GL_COLOR_ARRAY);
		}
		if(vertexData.getNumNormals() && useNormals){
			glDisableClientState(GL_NORMAL_ARRAY);
		}
		if(vertexData.getNumTexCoords() && useTextures){
			glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		}
#endif
		if (bSmoothHinted) endSmoothing();
}
Exemplo n.º 2
0
//----------------------------------------------------------
void ofGLRenderer::draw(vector<ofPoint> & vertexData, ofPrimitiveMode drawMode){
	if(!vertexData.empty()) {
		if (bSmoothHinted) startSmoothing();
		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), &vertexData[0].x);
		glDrawArrays(ofGetGLPrimitiveMode(drawMode), 0, vertexData.size());
		if (bSmoothHinted) endSmoothing();
	}
}
Exemplo n.º 3
0
//----------------------------------------------------------
void ofGLRenderer::draw(ofPolyline & poly){
	// use smoothness, if requested:
	if (bSmoothHinted) startSmoothing();

	glEnableClientState(GL_VERTEX_ARRAY);
	glVertexPointer(3, GL_FLOAT, sizeof(ofVec3f), &poly.getVertices()[0].x);
	glDrawArrays(poly.isClosed()?GL_LINE_LOOP:GL_LINE_STRIP, 0, poly.size());

	// use smoothness, if requested:
	if (bSmoothHinted) endSmoothing();
}
Exemplo n.º 4
0
//----------------------------------------------------------
void ofLine(float x1,float y1,float x2,float y2){

	// use smoothness, if requested:
	if (bSmoothHinted) startSmoothing();

	// draw:
	glBegin( GL_LINES );
		glVertex2f(x1,y1);
		glVertex2f(x2,y2);
	glEnd();

	// back to normal, if smoothness is on
	if (bSmoothHinted) endSmoothing();

}
Exemplo n.º 5
0
//----------------------------------------------------------
void ofTriangle(float x1,float y1,float x2,float y2,float x3, float y3){


	// use smoothness, if requested:
	if (bSmoothHinted && drawMode == OF_OUTLINE) startSmoothing();

	// draw:
	glBegin( (drawMode == OF_FILLED) ? GL_TRIANGLES : GL_LINE_LOOP);
		glVertex2f(x1,y1);
		glVertex2f(x2,y2);
		glVertex2f(x3,y3);
	glEnd();

	// back to normal, if smoothness is on
	if (bSmoothHinted && drawMode == OF_OUTLINE) endSmoothing();
}
Exemplo n.º 6
0
//----------------------------------------------------------
void ofEllipse(float x, float y, float width, float height){

	if (!bSetupCircle) setupCircle();

	// use smoothness, if requested:
	if (bSmoothHinted && drawMode == OF_OUTLINE) startSmoothing();

	// draw:
	glPushMatrix();
		glTranslatef(x, y, 0);
		glScalef(width, height, 1);
		glBegin( (drawMode == OF_FILLED) ? GL_POLYGON : GL_LINE_LOOP);
		glCallList(precachedCircle);
		glEnd();
	glPopMatrix();

	// back to normal, if smoothness is on
	if (bSmoothHinted && drawMode == OF_OUTLINE) endSmoothing();
}
Exemplo n.º 7
0
void ofCircleSlice(float x,float y, float radius, float lowAngle, float highAngle, bool closed, bool radians) {
    if (!bSetupCircle) setupCircle();

    // use smoothness, if requested:
    if (bSmoothHinted && drawMode == OF_OUTLINE) startSmoothing();

    bool angleWrap = (lowAngle > highAngle); // are we doing the 0/360 wrap?

    if(!radians) {
        lowAngle = ofDegToRad(lowAngle);
        highAngle = ofDegToRad(highAngle);
    }

    int res = numCirclePts;
    float angle = lowAngle;
    float angleRange = ((!angleWrap)?(highAngle - lowAngle):(M_TWO_PI - lowAngle + highAngle));
    float angleAdder = angleRange / (float)res;
    int k = 0;
    for (int i = 0; i < numCirclePts; i++) {
        circlePtsScaled[k] = x + cos(angle) * radius;
        circlePtsScaled[k+1] = y - sin(angle) * radius;
        angle += angleAdder;
        k+=2;
    }

    // we draw the circle points ourself (vs. glDrawArrays) because it allows us to draw the center point, and have the triangles fan around it
    k = 0;
    glBegin((drawMode == OF_FILLED) ? GL_TRIANGLE_FAN : (closed?GL_LINE_LOOP:GL_LINE_STRIP));
    glVertex2f(x, y); // center vertex

    // now all the points around the circumference
    for (int i = 0; i < numCirclePts; i++) {
        glVertex2f(circlePtsScaled[k], circlePtsScaled[k+1]);
        k+=2;
    }
    glEnd();

    // back to normal, if smoothness is on
    if (bSmoothHinted && drawMode == OF_OUTLINE) endSmoothing();
};
Exemplo n.º 8
0
//----------------------------------------------------------
void ofRect(float x,float y,float w,float h){

	// use smoothness, if requested:
	if (bSmoothHinted && drawMode == OF_OUTLINE) startSmoothing();

	if (cornerMode == OF_RECTMODE_CENTER){
		glBegin( (drawMode == OF_FILLED) ? GL_QUADS : GL_LINE_LOOP);
		glVertex2f(x-w/2,y-h/2);
		glVertex2f(x+w/2,y-h/2);
		glVertex2f(x+w/2,y+h/2);
		glVertex2f(x-w/2,y+h/2);
		glEnd();
	} else {
		glBegin( (drawMode == OF_FILLED) ? GL_QUADS : GL_LINE_LOOP);
		glVertex2f(x,y);
		glVertex2f(x+w,y);
		glVertex2f(x+w,y+h);
		glVertex2f(x,y+h);
		glEnd();
	}
	// use smoothness, if requested:
	if (bSmoothHinted && drawMode == OF_OUTLINE) endSmoothing();
}
Exemplo n.º 9
0
//----------------------------------------------------------
void ofBeginShape(){

	if (bSmoothHinted && drawMode == OF_OUTLINE) startSmoothing();

	// just clear the vertices, just to make sure that
	// someone didn't do something improper, like :
	// a) ofBeginShape()
	// b) ofVertex(), ofVertex(), ofVertex() ....
	// c) ofBeginShape()
	// etc...

	clearTessVertices();
	
	
	// now get the tesselator object up and ready: 
	
	tobj = gluNewTess();


	// --------------------------------------------------------
	// note: 	you could write your own begin and end callbacks
	// 			if you wanted to...
	// 			for example, to count triangles or know which
	// 			type of object tess is giving back, etc...
	// --------------------------------------------------------

//	#if defined( TARGET_WIN32) || defined( TARGET_LINUX ) || defined( MAC_OS_X_VERSION_10_5 )
//		gluTessCallback( tobj, GLU_TESS_BEGIN, (void(CALLBACK*)())&glBegin);
//		gluTessCallback( tobj, GLU_TESS_VERTEX, (void(CALLBACK*)())&tessVertex);
//		gluTessCallback( tobj, GLU_TESS_COMBINE, (void(CALLBACK*)())&tessCombine);
//		gluTessCallback( tobj, GLU_TESS_END, (void(CALLBACK*)())&glEnd);
//		gluTessCallback( tobj, GLU_TESS_ERROR, (void(CALLBACK*)())&tessError);
//	#else
//		// xcode / osx complained, so we write it the way that makes it happy:
//		gluTessCallback( tobj, GLU_TESS_BEGIN, (void(CALLBACK*)(...))&glBegin);
//		gluTessCallback( tobj, GLU_TESS_VERTEX, (void(CALLBACK*)(...))&tessVertex);
//		gluTessCallback( tobj, GLU_TESS_COMBINE, (void(CALLBACK*)(...))&tessCombine);
//		gluTessCallback( tobj, GLU_TESS_END, (void(CALLBACK*)(...))&glEnd);
//		gluTessCallback( tobj, GLU_TESS_ERROR, (void(CALLBACK*)(...))&tessError);
//	#endif


	gluTessProperty( tobj, GLU_TESS_WINDING_RULE, polyMode);

	if (drawMode == OF_OUTLINE){
		gluTessProperty( tobj, GLU_TESS_BOUNDARY_ONLY, true);
	} else {
		gluTessProperty( tobj, GLU_TESS_BOUNDARY_ONLY, false);
	}

	gluTessProperty( tobj, GLU_TESS_TOLERANCE, 0);

	/* ------------------------------------------
	for 2d, this next call (normal) likely helps speed up ....
	quote : The computation of the normal represents about 10% of
	the computation time. For example, if all polygons lie in
	the x-y plane, you can provide the normal by using the
	-------------------------------------------  */

	gluTessNormal(tobj, 0.0, 0.0, 1.0);
	gluTessBeginPolygon( tobj, NULL);
	
}