comment unnecessary code
This commit is contained in:
parent
3d1900d9ce
commit
bfbf02e49e
2 changed files with 89 additions and 88 deletions
|
@ -1,80 +1,80 @@
|
||||||
#include "ofxMsdfgen.h"
|
#include "ofxMsdfgen.h"
|
||||||
#include "BitmapRef.hpp"
|
//#include "BitmapRef.hpp"
|
||||||
#include "ofGraphicsConstants.h"
|
//#include "ofGraphicsConstants.h"
|
||||||
#include "ofPixels.h"
|
//#include "ofPixels.h"
|
||||||
|
|
||||||
bool ofxMsdfgen::generateAtlas(const char * fontFilename){
|
//bool ofxMsdfgen::generateAtlas(const char * fontFilename){
|
||||||
bool success = false;
|
//bool success = false;
|
||||||
// Initialize instance of FreeType library
|
//// Initialize instance of FreeType library
|
||||||
if(msdfgen::FreetypeHandle * ft = msdfgen::initializeFreetype()){
|
//if(msdfgen::FreetypeHandle * ft = msdfgen::initializeFreetype()){
|
||||||
// Load font file
|
//// Load font file
|
||||||
if(msdfgen::FontHandle * font = msdfgen::loadFont(ft, fontFilename)){
|
//if(msdfgen::FontHandle * font = msdfgen::loadFont(ft, fontFilename)){
|
||||||
// Storage for glyph geometry and their coordinates in the atlas
|
//// Storage for glyph geometry and their coordinates in the atlas
|
||||||
std::vector <msdf_atlas::GlyphGeometry> glyphs;
|
//std::vector <msdf_atlas::GlyphGeometry> glyphs;
|
||||||
// FontGeometry is a helper class that loads a set of glyphs from a single font.
|
//// FontGeometry is a helper class that loads a set of glyphs from a single font.
|
||||||
// It can also be used to get additional font metrics, kerning information, etc.
|
//// It can also be used to get additional font metrics, kerning information, etc.
|
||||||
msdf_atlas::FontGeometry fontGeometry(&glyphs);
|
//msdf_atlas::FontGeometry fontGeometry(&glyphs);
|
||||||
// Load a set of character glyphs:
|
//// Load a set of character glyphs:
|
||||||
// The second argument can be ignored unless you mix different font sizes in one atlas.
|
//// The second argument can be ignored unless you mix different font sizes in one atlas.
|
||||||
// In the last argument, you can specify a charset other than ASCII.
|
//// In the last argument, you can specify a charset other than ASCII.
|
||||||
// To load specific glyph indices, use loadGlyphs instead.
|
//// To load specific glyph indices, use loadGlyphs instead.
|
||||||
fontGeometry.loadCharset(font, 1.0, msdf_atlas::Charset::ASCII);
|
//fontGeometry.loadCharset(font, 1.0, msdf_atlas::Charset::ASCII);
|
||||||
// Apply MSDF edge coloring. See edge-coloring.h for other coloring strategies.
|
//// Apply MSDF edge coloring. See edge-coloring.h for other coloring strategies.
|
||||||
const double maxCornerAngle = 3.0;
|
//const double maxCornerAngle = 3.0;
|
||||||
for(msdf_atlas::GlyphGeometry & glyph : glyphs){
|
//for(msdf_atlas::GlyphGeometry & glyph : glyphs){
|
||||||
glyph.edgeColoring(&msdfgen::edgeColoringInkTrap, maxCornerAngle, 0);
|
//glyph.edgeColoring(&msdfgen::edgeColoringInkTrap, maxCornerAngle, 0);
|
||||||
}
|
//}
|
||||||
// TightAtlasPacker class computes the layout of the atlas.
|
//// TightAtlasPacker class computes the layout of the atlas.
|
||||||
msdf_atlas::TightAtlasPacker packer;
|
//msdf_atlas::TightAtlasPacker packer;
|
||||||
// Set atlas parameters:
|
//// Set atlas parameters:
|
||||||
// setDimensions or setDimensionsConstraint to find the best value
|
//// setDimensions or setDimensionsConstraint to find the best value
|
||||||
packer.setDimensionsConstraint(msdf_atlas::TightAtlasPacker::DimensionsConstraint::SQUARE);
|
//packer.setDimensionsConstraint(msdf_atlas::TightAtlasPacker::DimensionsConstraint::SQUARE);
|
||||||
// setScale for a fixed size or setMinimumScale to use the largest that fits
|
//// setScale for a fixed size or setMinimumScale to use the largest that fits
|
||||||
packer.setMinimumScale(24.0);
|
//packer.setMinimumScale(24.0);
|
||||||
// setPixelRange or setUnitRange
|
//// setPixelRange or setUnitRange
|
||||||
packer.setPixelRange(2.0);
|
//packer.setPixelRange(2.0);
|
||||||
packer.setMiterLimit(1.0);
|
//packer.setMiterLimit(1.0);
|
||||||
// Compute atlas layout - pack glyphs
|
//// Compute atlas layout - pack glyphs
|
||||||
packer.pack(glyphs.data(), glyphs.size());
|
//packer.pack(glyphs.data(), glyphs.size());
|
||||||
// Get final atlas dimensions
|
//// Get final atlas dimensions
|
||||||
int width = 0, height = 0;
|
//int width = 0, height = 0;
|
||||||
packer.getDimensions(width, height);
|
//packer.getDimensions(width, height);
|
||||||
// The ImmediateAtlasGenerator class facilitates the generation of the atlas bitmap.
|
//// The ImmediateAtlasGenerator class facilitates the generation of the atlas bitmap.
|
||||||
msdf_atlas::ImmediateAtlasGenerator <
|
//msdf_atlas::ImmediateAtlasGenerator <
|
||||||
float, // pixel type of buffer for individual glyphs depends on generator function
|
//float, // pixel type of buffer for individual glyphs depends on generator function
|
||||||
3, // number of atlas color channels
|
//3, // number of atlas color channels
|
||||||
& msdf_atlas::msdfGenerator, // function to generate bitmaps for individual glyphs
|
//& msdf_atlas::msdfGenerator, // function to generate bitmaps for individual glyphs
|
||||||
msdf_atlas::BitmapAtlasStorage <float, 3> // class that stores the atlas bitmap
|
//msdf_atlas::BitmapAtlasStorage <float, 3> // class that stores the atlas bitmap
|
||||||
// For example, a custom atlas storage class that stores it in VRAM can be used.
|
//// For example, a custom atlas storage class that stores it in VRAM can be used.
|
||||||
> generator(width, height);
|
//> generator(width, height);
|
||||||
// GeneratorAttributes can be modified to change the generator's default settings.
|
//// GeneratorAttributes can be modified to change the generator's default settings.
|
||||||
msdf_atlas::GeneratorAttributes attributes;
|
//msdf_atlas::GeneratorAttributes attributes;
|
||||||
generator.setAttributes(attributes);
|
//generator.setAttributes(attributes);
|
||||||
generator.setThreadCount(12);
|
//generator.setThreadCount(12);
|
||||||
// Generate atlas bitmap
|
//// Generate atlas bitmap
|
||||||
generator.generate(glyphs.data(), glyphs.size());
|
//generator.generate(glyphs.data(), glyphs.size());
|
||||||
// The atlas bitmap can now be retrieved via atlasStorage as a BitmapConstRef.
|
//// The atlas bitmap can now be retrieved via atlasStorage as a BitmapConstRef.
|
||||||
// The glyphs array (or fontGeometry) contains positioning data for typesetting text.
|
//// The glyphs array (or fontGeometry) contains positioning data for typesetting text.
|
||||||
success = submitAtlasBitmapAndLayout((msdfgen::BitmapConstRef <float, 3>)generator.atlasStorage(),
|
//success = submitAtlasBitmapAndLayout((msdfgen::BitmapConstRef <float, 3>)generator.atlasStorage(),
|
||||||
glyphs,
|
//glyphs,
|
||||||
width,
|
//width,
|
||||||
height);
|
//height);
|
||||||
// Cleanup
|
//// Cleanup
|
||||||
msdfgen::destroyFont(font);
|
//msdfgen::destroyFont(font);
|
||||||
}
|
//}
|
||||||
msdfgen::deinitializeFreetype(ft);
|
//msdfgen::deinitializeFreetype(ft);
|
||||||
}
|
//}
|
||||||
return success;
|
//return success;
|
||||||
}
|
//}
|
||||||
|
|
||||||
bool ofxMsdfgen::submitAtlasBitmapAndLayout(const msdfgen::BitmapConstRef <float, 3> & storage,
|
//bool ofxMsdfgen::submitAtlasBitmapAndLayout(const msdfgen::BitmapConstRef <float, 3> & storage,
|
||||||
const std::vector <msdf_atlas::GlyphGeometry> & glyphs,
|
//const std::vector <msdf_atlas::GlyphGeometry> & glyphs,
|
||||||
const int & width,
|
//const int & width,
|
||||||
const int & height){
|
//const int & height){
|
||||||
const msdfgen::Bitmap <float, 3> bitmap(storage);
|
//const msdfgen::Bitmap <float, 3> bitmap(storage);
|
||||||
ofImage image;
|
//ofImage image;
|
||||||
toOfImage(bitmap, image);
|
//toOfImage(bitmap, image);
|
||||||
image.save("atlas.png");
|
//image.save("atlas.png");
|
||||||
|
|
||||||
return true;
|
//return true;
|
||||||
}
|
//}
|
||||||
|
|
|
@ -1,20 +1,21 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "BitmapAtlasStorage.h"
|
//#include "BitmapAtlasStorage.h"
|
||||||
#include "GlyphGeometry.h"
|
//#include "GlyphGeometry.h"
|
||||||
#include "ofMain.h"
|
#include "ofMain.h"
|
||||||
#include "freetype2/freetype/freetype.h"
|
//#include FT_FREETYPE_H
|
||||||
#include <msdf-atlas-gen/msdf-atlas-gen.h>
|
//#include FT_MULTIPLE_MASTERS_H
|
||||||
#include "Atlas.h"
|
//#include <msdf-atlas-gen/msdf-atlas-gen.h>
|
||||||
#include "conversion.h"
|
#include "conversion.h"
|
||||||
|
#include "Atlas.h"
|
||||||
|
|
||||||
namespace ofxMsdfgen {
|
namespace ofxMsdfgen {
|
||||||
bool generateAtlas(const char * fontFilename);
|
//bool generateAtlas(const char * fontFilename);
|
||||||
|
|
||||||
// doesn't really do anything yet
|
//// doesn't really do anything yet
|
||||||
// just saves the atlas as a png
|
//// just saves the atlas as a png
|
||||||
bool submitAtlasBitmapAndLayout(const msdfgen::BitmapConstRef <float, 3> & storage,
|
//bool submitAtlasBitmapAndLayout(const msdfgen::BitmapConstRef <float, 3> & storage,
|
||||||
const std::vector <msdf_atlas::GlyphGeometry> & glyphs,
|
//const std::vector <msdf_atlas::GlyphGeometry> & glyphs,
|
||||||
const int & width,
|
//const int & width,
|
||||||
const int & height);
|
//const int & height);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue