void endPath(PathPtr p) { if (!path) { path = glGenPathsNV(1); } glPathCommandsNV(path, GLsizei(cmds.size()), &cmds[0], GLsizei(coords.size()), GL_FLOAT, &coords[0]); }
void initTiger() { unsigned int i; tiger_path_base = glGenPathsNV(tiger_path_count); for (i=0; i<tiger_path_count; i++) { const char *svg_str = tiger_path[i]; size_t svg_len = strlen(tiger_path[i]); GLfloat stroke_width = (GLfloat) fabs(tiger_style[i].stroke_width); glPathStringNV(tiger_path_base+i, GL_PATH_FORMAT_SVG_NV, (GLsizei)svg_len, svg_str); glPathParameterfNV(tiger_path_base+i, GL_PATH_STROKE_WIDTH_NV, stroke_width); } }
static int morph_shape(NSVGshape *shape, NSVGshape *shape2, float ratio) { //render_ctx *ctx = render; int cmds = 0, coords = 0; float om_ratio = 1.0f - ratio; NSVGpath *path, *path2; for (path = shape->paths; path != NULL; path = path->next) { if (path->npts > 2) { int ncubic = (path->npts - 1)/3; cmds += 1 + ncubic; coords += 2 + ncubic*6; if (path->closed) cmds++; } } GLubyte *cmd = (GLubyte *)alloca(cmds*sizeof(GLubyte)); GLfloat *coord = alloca(coords*sizeof(GLfloat)); cmds = 0, coords = 0; path2 = shape2->paths; for (path = shape->paths; path != NULL; path = path->next, path2 = path2->next) { if (path->npts > 2) { cmd[cmds] = GL_MOVE_TO_NV; int ncubic = (path->npts - 1)/3; memset(cmd + cmds + 1, GL_CUBIC_CURVE_TO_NV, ncubic); cmds += 1 + ncubic; for (int i = 0; i < (2 + ncubic*6); i++) coord[coords + i] = path->pts[i]*om_ratio + path2->pts[i]*ratio; coords += 2 + ncubic*6; if (path->closed) cmd[cmds++] = GL_CLOSE_PATH_NV; } } GLuint pathObj = glGenPathsNV(1); glPathCommandsNV(pathObj, cmds, cmd, coords, GL_FLOAT, coord); return pathObj; }
static int nvpr_cache_shape(void *render, NSVGshape *shape) { //render_ctx *ctx = render; int cmds = 0, coords = 0; GLuint pathObj = glGenPathsNV(1); NSVGpath *path; for (path = shape->paths; path != NULL; path = path->next) { if (path->npts > 2) { int ncubic = (path->npts - 1)/3; cmds += 1 + ncubic; coords += 2 + ncubic*6; if (path->closed) cmds++; } } GLubyte *cmd = (GLubyte *)alloca(cmds*sizeof(GLubyte)); GLfloat *coord = alloca(coords*sizeof(GLfloat)); cmds = 0, coords = 0; for (path = shape->paths; path != NULL; path = path->next) { if (path->npts > 2) { cmd[cmds] = GL_MOVE_TO_NV; int ncubic = (path->npts - 1)/3; memset(cmd + cmds + 1, GL_CUBIC_CURVE_TO_NV, ncubic); cmds += 1 + ncubic; memcpy(coord + coords, path->pts, (2 + ncubic*6)*sizeof(float)); coords += 2 + ncubic*6; if (path->closed) cmd[cmds++] = GL_CLOSE_PATH_NV; } } glPathCommandsNV(pathObj, cmds, cmd, coords, GL_FLOAT, coord); shape->cache = pathObj; return pathObj; }
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_NVPathRendering_nglGenPathsNV(JNIEnv *env, jclass clazz, jint range, jlong function_pointer) { glGenPathsNVPROC glGenPathsNV = (glGenPathsNVPROC)((intptr_t)function_pointer); GLuint __result = glGenPathsNV(range); return __result; }
void NVPFont::createGlyphs() { if ( mGlyphBase != 0 ) { glDeletePathsNV ( mGlyphBase, 1+numChars ); } mGlyphBase = 0; mPathTemplate = 0; /* Create a range of path objects corresponding to Latin-1 character codes. */ mGlyphBase = glGenPathsNV ( 1+numChars ); /* Use the path object at the end of the range as a template. */ mPathTemplate = mGlyphBase; //set stroke width of path as percentage of emscale glPathCommandsNV ( mPathTemplate, 0, NULL, 0, GL_FLOAT, NULL ); glPathParameteriNV ( mPathTemplate, GL_PATH_STROKE_WIDTH_NV, GLint ( mStrokeWidth * mEmScale ) ); glPathParameteriNV ( mPathTemplate, GL_PATH_JOIN_STYLE_NV, GL_ROUND_NV ); //attempt to load glyphs from mFontname system font. If mFontName can't be found then load Arial. if Arial can't be found //then load the default sans system font glPathGlyphRangeNV ( mGlyphBase, mSystemFont ? GL_SYSTEM_FONT_NAME_NV : GL_FILE_NAME_NV, mFontName.c_str(), GL_NONE, 0, numChars, GL_SKIP_MISSING_GLYPH_NV, mPathTemplate, GLfloat ( mEmScale ) ); glPathGlyphRangeNV ( mGlyphBase, GL_SYSTEM_FONT_NAME_NV, "Arial", GL_NONE, 0, numChars, GL_SKIP_MISSING_GLYPH_NV, mPathTemplate, GLfloat ( mEmScale ) ); glPathGlyphRangeNV ( mGlyphBase, GL_STANDARD_FONT_NAME_NV, "Sans", GL_NONE, 0, numChars, GL_USE_MISSING_GLYPH_NV, mPathTemplate, GLfloat ( mEmScale ) ); float font_data[4]; glGetPathMetricRangeNV ( GL_FONT_Y_MIN_BOUNDS_BIT_NV | GL_FONT_Y_MAX_BOUNDS_BIT_NV | GL_FONT_UNDERLINE_POSITION_BIT_NV | GL_FONT_UNDERLINE_THICKNESS_BIT_NV, mGlyphBase + ' ', /*count*/1, 4 * sizeof ( GLfloat ), font_data ); mFontMetrics.mYMin = font_data[0]; mFontMetrics.mYMax = font_data[1]; mFontMetrics.mUnderlinePosition = font_data[2]; mFontMetrics.mUnderlineThickness = font_data[3]; glGetPathMetricRangeNV ( GL_FONT_X_MIN_BOUNDS_BIT_NV | GL_FONT_X_MAX_BOUNDS_BIT_NV | GL_FONT_UNITS_PER_EM_BIT_NV | GL_FONT_ASCENDER_BIT_NV, mGlyphBase + ' ', /*count*/1, 4 * sizeof ( GLfloat ), font_data ); mFontMetrics.mXMin = font_data[0]; mFontMetrics.mXMax = font_data[1]; mFontMetrics.mEmUnits = font_data[2]; mFontMetrics.mAscender = font_data[3]; glGetPathMetricRangeNV ( GL_FONT_DESCENDER_BIT_NV | GL_FONT_HEIGHT_BIT_NV | GL_FONT_MAX_ADVANCE_WIDTH_BIT_NV | GL_FONT_MAX_ADVANCE_HEIGHT_BIT_NV, mGlyphBase + ' ', /*count*/1, 4 * sizeof ( GLfloat ), font_data ); mFontMetrics.mDescender = font_data[0]; mFontMetrics.mFontHeight = font_data[1]; mFontMetrics.mMaxAdvanceWidth = font_data[2]; mFontMetrics.mMaxAdvanceHeight = font_data[3]; GLfloat glyphMetrics[256]; mGlyphMetrics = GlyphMetrics::create(); //collect glyph metrics glGetPathMetricRangeNV ( GL_GLYPH_HORIZONTAL_BEARING_ADVANCE_BIT_NV, mGlyphBase, numChars, 0, /* stride of zero means sizeof(GLfloat) since 1 bit in mask */ glyphMetrics ); mGlyphMetrics->mHorizontalAdvance = std::vector<float> ( glyphMetrics, glyphMetrics + sizeof glyphMetrics / sizeof glyphMetrics[0] ); glGetPathMetricRangeNV ( GL_GLYPH_VERTICAL_BEARING_ADVANCE_BIT_NV, mGlyphBase, numChars, 0, /* stride of zero means sizeof(GLfloat) since 1 bit in mask */ glyphMetrics ); mGlyphMetrics->mVerticalAdvance = std::vector<float> ( glyphMetrics, glyphMetrics + sizeof glyphMetrics / sizeof glyphMetrics[0] ); glGetPathMetricRangeNV ( GL_GLYPH_WIDTH_BIT_NV, mGlyphBase, numChars, 0, /* stride of zero means sizeof(GLfloat) since 1 bit in mask */ glyphMetrics ); mGlyphMetrics->mGlyphWidth = std::vector<float> ( glyphMetrics, glyphMetrics + sizeof glyphMetrics / sizeof glyphMetrics[0] ); glGetPathMetricRangeNV ( GL_GLYPH_HEIGHT_BIT_NV, mGlyphBase, numChars, 0, /* stride of zero means sizeof(GLfloat) since 1 bit in mask */ glyphMetrics ); mGlyphMetrics->mGlyphHeight = std::vector<float> ( glyphMetrics, glyphMetrics + sizeof glyphMetrics / sizeof glyphMetrics[0] ); glGetPathMetricRangeNV ( GL_GLYPH_HORIZONTAL_BEARING_X_BIT_NV, mGlyphBase, numChars, 0, /* stride of zero means sizeof(GLfloat) since 1 bit in mask */ glyphMetrics ); mGlyphMetrics->mHorizontalBearingX = std::vector<float> ( glyphMetrics, glyphMetrics + sizeof glyphMetrics / sizeof glyphMetrics[0] ); glGetPathMetricRangeNV ( GL_GLYPH_HORIZONTAL_BEARING_Y_BIT_NV, mGlyphBase, numChars, 0, /* stride of zero means sizeof(GLfloat) since 1 bit in mask */ glyphMetrics ); mGlyphMetrics->mHorizontalBearingY = std::vector<float> ( glyphMetrics, glyphMetrics + sizeof glyphMetrics / sizeof glyphMetrics[0] ); glGetPathMetricRangeNV ( GL_GLYPH_VERTICAL_BEARING_X_BIT_NV, mGlyphBase, numChars, 0, /* stride of zero means sizeof(GLfloat) since 1 bit in mask */ glyphMetrics ); mGlyphMetrics->mVerticalBearingX = std::vector<float> ( glyphMetrics, glyphMetrics + sizeof glyphMetrics / sizeof glyphMetrics[0] ); glGetPathMetricRangeNV ( GL_GLYPH_VERTICAL_BEARING_Y_BIT_NV, mGlyphBase, numChars, 0, /* stride of zero means sizeof(GLfloat) since 1 bit in mask */ glyphMetrics ); mGlyphMetrics->mVerticalBearingY = std::vector<float> ( glyphMetrics, glyphMetrics + sizeof glyphMetrics / sizeof glyphMetrics[0] ); }