Exemplo n.º 1
0
unsigned int Model::draw(bool wireframe)
{
    GP_ASSERT(_mesh);

    unsigned int partCount = _mesh->getPartCount();
    if (partCount == 0)
    {
        // No mesh parts (index buffers).
        if (_material)
        {
            Technique* technique = _material->getTechnique();
            GP_ASSERT(technique);
            unsigned int passCount = technique->getPassCount();
            for (unsigned int i = 0; i < passCount; ++i)
            {
                Pass* pass = technique->getPassByIndex(i);
                GP_ASSERT(pass);
                pass->bind();
                GL_ASSERT( glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0) );
                if (!wireframe || !drawWireframe(_mesh))
                {
                    GL_ASSERT( glDrawArrays(_mesh->getPrimitiveType(), 0, _mesh->getVertexCount()) );
                }
                pass->unbind();
            }
        }
    }
    else
    {
        for (unsigned int i = 0; i < partCount; ++i)
        {
            MeshPart* part = _mesh->getPart(i);
            GP_ASSERT(part);

            // Get the material for this mesh part.
            Material* material = getMaterial(i);
            if (material)
            {
                Technique* technique = material->getTechnique();
                GP_ASSERT(technique);
                unsigned int passCount = technique->getPassCount();
                for (unsigned int j = 0; j < passCount; ++j)
                {
                    Pass* pass = technique->getPassByIndex(j);
                    GP_ASSERT(pass);
                    pass->bind();
                    GL_ASSERT( glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, part->_indexBuffer) );
                    if (!wireframe || !drawWireframe(part))
                    {
                        GL_ASSERT( glDrawElements(part->getPrimitiveType(), part->getIndexCount(), part->getIndexFormat(), 0) );
                    }
                    pass->unbind();
                }
            }
        }
    }
    return partCount;
}
Exemplo n.º 2
0
void
drawScene(void)
{

  int i;
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);

  glClearColor(0.0, 0.0, 0.0, 0.0);
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glPushMatrix();

  glRotatef(ax, 1.0, 0.0, 0.0);
  glRotatef(-ay, 0.0, 1.0, 0.0);

  /* all the good stuff follows */

  if (stencilOn) {
    glEnable(GL_STENCIL_TEST);
    glClear(GL_STENCIL_BUFFER_BIT);
    glStencilMask(1);
    glStencilFunc(GL_ALWAYS, 0, 1);
    glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
  }
  glColor3f(1.0, 1.0, 0.0);
  for (i = 0; i < 6; i++) {
    drawWireframe(i);
    if (stencilOn) {
      glStencilFunc(GL_EQUAL, 0, 1);
      glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    }
    glColor3f(0.0, 0.0, 0.0);
    drawFilled(i);

    glColor3f(1.0, 1.0, 0.0);
    if (stencilOn) {
      glStencilFunc(GL_ALWAYS, 0, 1);
      glStencilOp(GL_INVERT, GL_INVERT, GL_INVERT);
    }
    glColor3f(1.0, 1.0, 0.0);
    drawWireframe(i);
  }
  glPopMatrix();

  if (stencilOn)
    glDisable(GL_STENCIL_TEST);

  /* end of good stuff */

  glutSwapBuffers();
}
Exemplo n.º 3
0
void display(void) 
{
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(64.0, aspect, zNear, zFar);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity(); 

    glTranslatef(0.0,0.0,-sdepth);
    glRotatef(-stheta, 1.0, 0.0, 0.0);
    glRotatef(sphi, 0.0, 0.0, 1.0);
    glTranslatef(-(float)((grid+1)/2-1), -(float)((grid+1)/2-1), 0.0);

      getFaceNorms();
    getVertNorms();

    switch (displayMode) 
    {
        case WIREFRAME: drawWireframe(); break;
        case HIDDENLINE: drawHiddenLine(); break;
        case FLATSHADED: drawFlatShaded(); break;
        case SMOOTHSHADED: drawSmoothShaded(); break;
        case TEXTURED: drawTextured(); break;
    }

    if (drawFaceNorms)    
    {
        getFaceNormSegs();
        drawFaceNormals();
    }

    glutSwapBuffers();
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
Exemplo n.º 4
0
/***
 *** The "draw" signal handler. All the OpenGL re-drawing should
 *** be done here. This is repeatedly called as the painting routine
 *** every time the 'draw' event is signalled.
 ***/
static gboolean
draw (GtkWidget *widget,
      cairo_t   *event,
      gpointer   data)
{
  /*** OpenGL BEGIN ***/
  if (!gtk_widget_begin_gl(widget))
    return FALSE;

  glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode (GL_PROJECTION);
  glLoadIdentity ();
  gluPerspective (64.0, aspect, zNear, zFar);
  glMatrixMode (GL_MODELVIEW);
  glLoadIdentity ();

  glTranslatef (0.0,0.0,-sdepth);
  glRotatef (-stheta, 1.0, 0.0, 0.0);
  glRotatef (sphi, 0.0, 0.0, 1.0);
  glTranslatef (-(float)((grid+1)/2-1), -(float)((grid+1)/2-1), 0.0);

  drawWireframe ();

  gtk_widget_end_gl (widget, TRUE);
  /*** OpenGL END ***/

  return TRUE;
}
void ParticleShaderTriangle::drawPre()
{
	ParticleOpenMesh &mesh=pm->mesh;
	mesh.update_face_normals();
	if (!faceNormal)
		mesh.update_vertex_normals();
	// Draw triangle mesh
	if (lineWidth>0)
		drawWireframe(mesh);
	else
		drawPolygon(mesh);
}
Exemplo n.º 6
0
void poShape3D::draw()
{
	po::setColor(fillColor, appliedAlpha());
	
	if(callListID != -1)
		glCallList(callListID);
	else if ( enableFill )
		drawFaces();
	else if ( strokeWidth != 0 )
		drawWireframe();
	else if ( enablePoints )
		drawVertices();
}
Exemplo n.º 7
0
void Node3D::treeDrawWireframe()
{
    if(!mIsVisible) return;

    // apply transform
    gl::pushModelView();

    // usual way to update modelview matrix
    gl::multModelView( mTransform );

    // draw this node by calling derived class
    drawWireframe();

    // draw this node's children
    NodeList::iterator itr;
    for(itr=mChildren.begin(); itr!=mChildren.end(); ++itr) {
        // only call other Node3D's
        Node3DRef node = std::dynamic_pointer_cast<Node3D>(*itr);
        if(node) node->treeDrawWireframe();
    }

    // restore transform
    gl::popModelView();
}
Exemplo n.º 8
0
	//----------
	void Device::drawWorld() {
		auto colorSource = this->getColorSource();
		auto depthSource = this->getDepthSource();
		auto bodySource = this->getBodySource();

		if (!depthSource) {
			ofLogError("ofxKinectForWindows2::Device::drawPrettyMesh") << "No depth source initialised";
			return;
		}
		
		//point cloud
		{
			//setup some point cloud properties for kicks
			bool usePointSize = true;

#if OF_VERSION_MAJOR > 0 || OF_VERSION_MINOR >= 10
			auto mainWindow = std::static_pointer_cast<ofAppGLFWWindow>(ofGetCurrentWindow());
			usePointSize = mainWindow ? mainWindow->getSettings().glVersionMajor <= 2 : false;
#endif

			usePointSize = false;

			if (usePointSize) {
				glPushAttrib(GL_POINT_BIT);
				glPointSize(5.0f);
				glEnable(GL_POINT_SMOOTH);
			}

			ofPushStyle();

			bool useColor = colorSource.get();
			if (useColor) {
				useColor &= colorSource->getTexture().isAllocated();
			}

			if (useColor) {
				//bind kinect color camera texture and draw mesh from depth (which has texture coordinates)
				colorSource->getTexture().bind();
			}

			auto opts = Source::Depth::PointCloudOptions(true, Source::Depth::PointCloudOptions::TextureCoordinates::ColorCamera);
			auto mesh = depthSource->getMesh(opts);

			//draw point cloud
			mesh.drawVertices();

			//draw triangles
			ofSetColor(255, 150);
			mesh.drawWireframe();

			//draw fills faded
			ofSetColor(255, 50);
			mesh.drawFaces();

			if (useColor) {
				//unbind colour camera
				colorSource->getTexture().unbind();
			}

			ofPopStyle();

			//clear the point cloud drawing attributes
			if (usePointSize) {
				glPopAttrib();
			}
		}
		
		//bodies and floor
		if (bodySource) {
			bodySource->drawWorld();

			ofPushMatrix();
			ofRotateDeg(90, 0, 0, 1);
			ofMultMatrix(bodySource->getFloorTransform());
			ofDrawGridPlane(5.0f);
			ofPopMatrix();
		}

		//draw the view cones of depth and colour cameras
		ofPushStyle();
		ofNoFill();
		ofSetLineWidth(2.0f);
		ofSetColor(100, 200, 100);
		depthSource->drawFrustum();
		if (colorSource) {
			ofSetColor(200, 100, 100);
			colorSource->drawFrustum();
		}
		ofPopStyle();
	}
Exemplo n.º 9
0
void MeshPainter::drawMesh(Viewport3dSettings *viewportSettings, GSProductMesh *meshProduct, PaintLayer layer, bool background, int reflectionCount)
{
	MMesh *mesh = &( meshProduct->getMMeshForDisplay() );

	if ( mesh->getVertices().size() == 0 )
	{
		return;
	}

	ViewSettings *viewSettings = viewportSettings->getViewSettings();
	bool verticesFlag = viewportSettings->bForegroundVertices;
	bool cullFlag = viewSettings->bBackfaceCull;
	bool multilayerFlag = viewSettings->bMultilayer;
	bool markedfacesFlag = viewportSettings->bForegroundMarkedFaces;
	MeshLiveSubdWireframeMode liveSubdWireMode = background  ?  meshLiveSubdivisionWireframeMode  :  viewSettings->meshLiveSubdivisionWireframeMode;
	bool bLiveSubdivision = background  ?  bMeshLiveSubdivisionEnabled  :  viewSettings->bMeshLiveSubdivisionEnabled;
	bool bBackgroundTransparent = viewportSettings->bBackgroundTransparent;

	bool wireframeFlag, solidFlag, smoothFlag, texturedFlag;

	if ( background )
	{
		wireframeFlag = viewportSettings->bBackgroundWireframe;
		solidFlag = viewportSettings->bBackgroundSolid;
		smoothFlag = viewportSettings->bBackgroundSmooth;
		texturedFlag = viewportSettings->bBackgroundMaterial;
	}
	else
	{
		wireframeFlag = viewportSettings->bForegroundWireframe;
		solidFlag = viewportSettings->bForegroundSolid;
		smoothFlag = viewportSettings->bForegroundSmooth;
		texturedFlag = viewportSettings->bForegroundMaterial;
	}


	MMesh *subdMesh = NULL;

	if ( bLiveSubdivision )
	{
		int subdIterations = background  ?  meshLiveSubdivisionIterations  :  viewSettings->meshLiveSubdivisionIterations;
		int subdMaxFaces = background  ?  meshLiveSubdivisionMaxFaces  :  viewSettings->meshLiveSubdivisionMaxFaces;
		MPreserveNormalSharpness normalSharpness = background  ?  meshLiveSubdivisionNormalSharpness  :  viewSettings->meshLiveSubdivisionNormalSharpness;
		subdMesh = mesh->getLiveSubdivisionMesh( subdIterations, subdMaxFaces, normalSharpness );
	}

	if ( background  &&  bBackgroundTransparent )
	{
		if ( reflectionCount & 0x1 )
		{
			glCullFace( GL_FRONT );
		}
		else
		{
			glCullFace( GL_BACK );
		}
		glEnable( GL_CULL_FACE );


		if ( bLiveSubdivision )
		{
			if ( solidFlag   &&   ( layer == PAINTLAYER_OVERLAY_BLEND  ||  layer == PAINTLAYER_OVERLAY_BLEND_NODEPTH ) )
			{
				beginSolidRendering();
				drawSolidTransparent( subdMesh, smoothFlag );
				endSolidRendering();
			}
		}
		else
		{
			if ( solidFlag   &&   ( layer == PAINTLAYER_OVERLAY_BLEND  ||  layer == PAINTLAYER_OVERLAY_BLEND_NODEPTH ) )
			{
				beginSolidRendering();
				drawSolidTransparent( mesh, smoothFlag );
				endSolidRendering();
			}
		}

		if ( wireframeFlag )
		{
			if ( layer == PAINTLAYER_OVERLAY_BLEND  ||  layer == PAINTLAYER_OVERLAY_BLEND_NODEPTH )
			{
				drawWireframe( mesh, background, layer == PAINTLAYER_OVERLAY_BLEND_NODEPTH, reflectionCount != 0, true );
			}
		}

		glDisable( GL_CULL_FACE );
	}
	else
	{
		if ( cullFlag )
		{
			if ( reflectionCount & 0x1 )
			{
				glCullFace( GL_FRONT );
			}
			else
			{
				glCullFace( GL_BACK );
			}
			glEnable( GL_CULL_FACE );
		}


		if ( bLiveSubdivision )
		{
			if ( solidFlag  &&  layer == PAINTLAYER_OBJECTS )
			{
				beginSolidRendering();
				drawSolidUntextured( subdMesh, background, false, true, true );
				endSolidRendering();
			}
		}
		else
		{
			if ( solidFlag  &&  layer == PAINTLAYER_OBJECTS )
			{
				beginSolidRendering();
				drawSolid( viewportSettings, mesh, background, texturedFlag, reflectionCount != 0, smoothFlag );
				endSolidRendering();
			}
		}

		if ( bLiveSubdivision  &&  liveSubdWireMode != MESHLIVESUBDWIRE_NONE  &&  !background )
		{
			if ( layer == PAINTLAYER_WIREFRAME  ||  ( layer == PAINTLAYER_TRANSPARENCY  &&  multilayerFlag ) )
			{
				drawSubdividedWireframe( subdMesh, layer == PAINTLAYER_TRANSPARENCY, liveSubdWireMode );
			}
		}

		if ( wireframeFlag )
		{
			if ( layer == PAINTLAYER_WIREFRAME  ||  ( layer == PAINTLAYER_TRANSPARENCY  &&  multilayerFlag ) )
			{
				drawWireframe( mesh, background, layer == PAINTLAYER_TRANSPARENCY, reflectionCount != 0, false );
			}
		}

		if ( verticesFlag  &&  !background )
		{
			if ( layer == PAINTLAYER_WIREFRAME  ||  ( layer == PAINTLAYER_TRANSPARENCY  && multilayerFlag ) )
			{
				drawVertices( mesh, layer == PAINTLAYER_TRANSPARENCY, reflectionCount != 0 );
			}
		}

		if ( cullFlag )
		{
			glDisable( GL_CULL_FACE );
		}

		if ( markedfacesFlag  &&  layer == PAINTLAYER_OVERLAY_BLEND  &&  !background  &&  reflectionCount == 0 )
		{
			drawMarkedFacesPass( mesh );
		}
	}
}