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
//********************************************
// ColorRamp.cpp
//********************************************
// alliez@usc.edu
// Created : 19/05/98
// Modified : 19/05/98
//********************************************

#include "stdafx.h"
#include "ColorRamp.h"

//********************************************
// Constructor
//********************************************
CColorRamp::CColorRamp()
{
	BuildDefault();
}

//********************************************
// Destructor
//********************************************
CColorRamp::~CColorRamp()
{
}

//********************************************
// Build
//********************************************
int CColorRamp::Build()
{
 int x1,y1,x2,y2;
 float a,b;
 ASSERT(m_NbNode >= 2);
 for(unsigned char k=0;k<3;k++)
	 for(int i=0;i<m_NbNode-1;i++)
   {
    x1 = (int)m_Node[i];
    x2 = (int)m_Node[i+1];

    ASSERT(x1<x2);
    y1 = m_Color[k][x1];
    y2 = m_Color[k][x2];

    a = (float)(y2-y1) / (float)(x2-x1);
    b = (float)y1 - a*(float)x1;

    for(int j=x1;j<x2;j++)
      m_Color[k][j]=(unsigned char)(a*(float)j+b);
   }
	return 1;
}

//********************************************
// Build
//********************************************
int CColorRamp::BuildNodes()
{
	// Check first and last are set
	m_Color[3][0] = 1;
	m_Color[3][m_Size-1] = 1;
	// Count nodes
	m_NbNode = 0;
	for(int i=0;i<m_Size;i++)
		if(m_Color[3][i]==1)
		{
			m_Node[m_NbNode]=(unsigned char)i;
			m_NbNode++;
		}
	TRACE("NbNode : %d\n",m_NbNode);
	ASSERT(m_NbNode>=2);
	return 1;
}

//********************************************
// ResetNodes
// Just first and last node
//********************************************
void CColorRamp::ResetNodes()
{
	for(int i=0;i<m_Size;i++)
		m_Color[3][i] = 0;
	m_Color[3][0] = 1;
	m_Color[3][m_Size-1] = 1;
	BuildNodes();
}

//********************************************
// BuildDefault
// 256 grey levels
//********************************************
void CColorRamp::BuildDefault()
{
	m_Size = 256;
	ResetNodes();

	// Grey scales
	for(unsigned char i=0;i<3;i++)
	{
		m_Color[i][0]=0;
		m_Color[i][255]=255;
	}
	Build();
}

//********************************************
// BuildDefault
// 256 grey levels
//********************************************
void CColorRamp::BuildRainbow()
{
	m_Size = 256;
	ResetNodes();

	// Rainbow
	m_Color[3][0] = 1;m_Color[0][0] = 0;m_Color[1][0] = 0;m_Color[2][0] = 255;
	m_Color[3][48] = 1;m_Color[0][48] = 0;m_Color[1][48] = 254;m_Color[2][48] = 255;
	m_Color[3][96] = 1;m_Color[0][96] = 0;m_Color[1][96] = 254;m_Color[2][96] = 0;
	m_Color[3][144] = 1;m_Color[0][144] = 255;m_Color[1][144] = 255;m_Color[2][144] = 0;
	m_Color[3][192] = 1;m_Color[0][192] = 255;m_Color[1][192] = 126;m_Color[2][192] = 0;
	m_Color[3][240] = 1;m_Color[0][240] = 255;m_Color[1][240] = 0;m_Color[2][240] = 0;
	m_Color[3][255] = 1;m_Color[0][255] = 255;m_Color[1][255] = 255;m_Color[2][255] = 255;

	BuildNodes();
	Build();
}

//********************************************
// Trace
//********************************************
void CColorRamp::Trace()
{
	TRACE("Ramp (%d elts)\n",m_Size);
	for(int i=0;i<m_Size;i++)
	{
		TRACE("  %3d %3d %3d\n",m_Color[0][i],m_Color[1][i],m_Color[2][i]);
	}
}

//** EOF **

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
Web03 | 2.8.1411023.1 | Last Updated 10 Jun 2003
Article Copyright 2001 by Pierre Alliez
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid