Click here to Skip to main content
Click here to Skip to main content
Articles » Multimedia » OpenGL » General » Downloads
 
Add your own
alternative version

Achieving PostScript and Wmf outputs for OpenGL

, 9 Jun 2003
This article explains how to generate resolution independent versions of 3D meshes rendered by OpenGL/MFC programs, i.e. how to export the rendering results to vectorial formats such as encapsulated postscript (EPS) and Windows enhanced metafile (EMF) formats. The main goal consists of being able to
gl_export.zip
Src
Mesh.dsp
Mesh.dsw
Mesh.plg
Mesh.aps
Mesh.clw
Lib3D
res
Mesh.ico
MeshDoc.ico
Toolbar.bmp
Mesh.ncb
Mesh.opt
Bin
knot2.wrl
mnt.wrl
mannequin.wrl
venus.wrl
knot1.wrl
nefertiti.wrl
geosphere.wrl
metafile.emf
Mesh.exe
samples_eps.zip
nefertiti_flat.eps
nefertiti_line_light.eps
nefertiti_line.eps
nefertiti_line_color.eps
nefertiti_smooth_light.eps
nefertiti_line_smooth_light.eps
nefertiti_vertex_color.eps
sample_ppt.zip
sample.ppt
//********************************************
// Face3d.h
// class CFace3d
//********************************************
// A triangular face :
// + three vertex ref (subdivision added)
// + three faces ref
// + normal vector
// + color
// + material ref
//********************************************
// m_pFace : shares edges
//********************************************
// alliez@usc.edu
// Created : 15/12/97
// Modified : 18/02/98
//********************************************

#ifndef _FACE_3D_
#define _FACE_3D_

#include "Object3d.h"
#include "Vector3d.h"
#include "Color.h"

class CVertex3d;
class CVectorSet3d;
class CMesh3d;
class CArray3d;

class CFace3d : public CObject3d
{

private :

	CVertex3d *m_pVertex[6];      // Vertices (subdivision included)
	CFace3d *m_pFace[3];          // Neighbors
	CVector3d m_Normal;           // Normal
	CColor m_Color;               // Color
	unsigned int m_IndexMaterial; // Material
	int m_Flag;                   // Flag (processings)

public :

	// Constructors
	CFace3d();
	CFace3d(CVertex3d *pVertex1,CVertex3d *pVertex2,CVertex3d *pVertex3);
	CFace3d(CFace3d *pFace);
	virtual ~CFace3d() {}

	// General
	int IsValid();
	void Clear();
	int Equal(CFace3d *pFace);
	void Set(CVertex3d *pVertex1,CVertex3d *pVertex2,CVertex3d *pVertex3);
	void Set(CFace3d *pFace1,CFace3d *pFace2,CFace3d *pFace3);
	void Set(CVertex3d *pVertex1,CVertex3d *pVertex2,CVertex3d *pVertex3,
		       CFace3d *pFace1,CFace3d *pFace2,CFace3d *pFace3);
	void Set(CFace3d *pFace);
	CVertex3d* GetCenter(void);
	CVertex3d *FindNearestVertex(CVertex3d *pVertex);

	// Neighboring
	int BuildArrayNeighbor(CArray3d<CFace3d> *pArrayFace,int depth = 1);

	// Color
	CColor *GetColor(void) { return &m_Color; }
	void SetColor(CColor &color) { m_Color.Set(color); }
	void SetColor(unsigned char r,unsigned char g,unsigned char b) { m_Color.Set(r,g,b); }

	// Flag
	int GetFlag(void) { return m_Flag; }
	void SetFlag(int flag) { m_Flag = flag; }
	void SetFlagOnVerticesIfDiff(int FlagDiff,int flag);

	// Per vertex
	void v1(CVertex3d *pVertex) { m_pVertex[0] = pVertex; }
	void v2(CVertex3d *pVertex) { m_pVertex[1] = pVertex; }
	void v3(CVertex3d *pVertex) { m_pVertex[2] = pVertex; }
	void v(int index,CVertex3d *pVertex) { m_pVertex[index%6] = pVertex; }
	int IndexFrom(CVertex3d *pVertex);

	// Per neighboring face
	void f1(CFace3d *pFace) { m_pFace[0] = pFace; }
	void f2(CFace3d *pFace) { m_pFace[1] = pFace; }
	void f3(CFace3d *pFace) { m_pFace[2] = pFace; }
	void f(int index,CFace3d *pFace) { m_pFace[index%3] = pFace; }

	// Normal
	void SetNormal(float x,float y,float z) { m_Normal.Set(x,y,z); }
	CVector3d * GetNormal() { return &m_Normal; }
	int HasNormal() { return (m_Normal.GetNormL2Square() != 0);}
	void CalculateNormal();

	// Sharp edges
	void ColorSharpEdge(double threshold,CColor &color);
	int GetSharpEdge(double threshold,int *SharpEdge);
	int HasSharpEdge(double threshold);

	virtual int GetType();

	// Numbers
	int NbVertex();
	int NbFaceNeighbor();

	// Per vertex
	CVertex3d *v1(void) { return m_pVertex[0]; }
	CVertex3d *v2(void) { return m_pVertex[1]; }
	CVertex3d *v3(void) { return m_pVertex[2]; }
	CVertex3d *v(int index) { return m_pVertex[index%6]; }

	// Per face
	CFace3d *f1(void) { return m_pFace[0]; }
	CFace3d *f2(void) { return m_pFace[1]; }
	CFace3d *f3(void) { return m_pFace[2]; }
	CFace3d *f(int index) { return m_pFace[index%3]; }

	// Find whenever face contain pVertex
	int HasVertex(CVertex3d *pVertex);
	int HasVertex(CVertex3d *pVertex,int *index);
	int HasVertexWithFlag(int flag);

	// Find whenever face contain pFace
	int HasNeighbor(CFace3d *pFace);
	int HasNeighbor(CFace3d *pFace,int *index);
	CFace3d *GetFaceNeighborExclusive(CFace3d *pF0,CFace3d *pF1);
	CFace3d *GetNeighborExclusive(CVertex3d *pVertexHas,CVertex3d *pVertexHasNot);
	CVertex3d *GetVertexExclusive(CVertex3d *pV0,CVertex3d *pV1);
	CVertex3d *GetVertexExclusive(CVertex3d *pV,CFace3d *pFace);
	CVertex3d *GetVertexFaceNeighborExclusive(unsigned int index);
	CVertex3d *GetVertexFaceNeighborExclusive(int index);
	int JointNeighbor(CFace3d **pFace0,CFace3d **pFace1);

	// Vertex sharing
	int Share1Vertex(CFace3d *pFace);
	int Share2Vertex(CFace3d *pFace);
	int Share2Vertex(CFace3d *pFace,int *IndexEdgeThis,int *IndexEdgeOther);
	int Share2Vertex(CFace3d *pFace,CVertex3d **pSharedV1,CVertex3d **pSharedV2);

	// Find whenever face contain pOld, and update it to pNew
	int UpdateVertex(CVertex3d *pOld,CVertex3d *pNew);
	int UpdateNeighbor(CFace3d *pOld,CFace3d *pNew);
	int UpdateVertexRecursive(CVertex3d *pVertexOld,CVertex3d *pVertexNew);

	// OpenGL
	void glDraw(unsigned char *ColorFace,CMesh3d *pMesh = NULL,unsigned char *ColorNeightbor = NULL);

	// Debug
	void Trace();

	// Geometric values
	double Area(); 
	double Perimeter();
	double Compacity();

};

#endif // _FACE_3D_

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Pierre Alliez

France France
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 10 Jun 2003
Article Copyright 2001 by Pierre Alliez
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid