JNIEXPORT void JNICALL Java_org_lwjgl_opengl_NVPathRendering_nglCoverFillPathInstancedNV(JNIEnv *env, jclass clazz, jint numPaths, jint pathNameType, jlong paths, jint pathBase, jint coverMode, jint transformType, jlong transformValues, jlong function_pointer) { const GLvoid *paths_address = (const GLvoid *)(intptr_t)paths; const GLfloat *transformValues_address = (const GLfloat *)(intptr_t)transformValues; glCoverFillPathInstancedNVPROC glCoverFillPathInstancedNV = (glCoverFillPathInstancedNVPROC)((intptr_t)function_pointer); glCoverFillPathInstancedNV(numPaths, pathNameType, paths_address, pathBase, coverMode, transformType, transformValues_address); }
void NVPTextBox::draw ( Vec2f offset ) { if ( mInvalid ) render(); if ( mFont ) { float pixelSize = mFontPt; float resolution = DPI; float fScale = mFontPt * resolution / ( DPI * emScale ); //not sure why this scale is needed to match point size? float fscal = fScale * .75f; glEnable ( GL_STENCIL_TEST ); glStencilFunc ( GL_NOTEQUAL, 0, ~0 ); glStencilOp ( GL_KEEP, GL_KEEP, GL_ZERO ); glStencilMask ( 0xFFFFFFFF ); gl::pushMatrices(); gl::translate ( offset ); gl::scale ( fscal, -fscal, fscal ); NVPFont::FontMetrics metrics = mFont->getFontMetrics(); if ( mUnderline ) { /* Draw an underline with conventional OpenGL rendering. */ float position = metrics.mUnderlinePosition, half_thickness = metrics.mUnderlineThickness / 2; glDisable ( GL_STENCIL_TEST ); gl::color ( mFillColor ); glBegin ( GL_QUAD_STRIP ); { glVertex2f ( 0, position + half_thickness ); glVertex2f ( 0, position - half_thickness ); glVertex2f ( mTotalAdvance, position + half_thickness ); glVertex2f ( mTotalAdvance, position - half_thickness ); } glEnd(); glEnable ( GL_STENCIL_TEST ); } gl::translate ( -mInitialOffset, 0.f ); if ( mFont->getStrokeWidth() > 0.f ) { /* Add stroking "behind" the filled characters. */ glStencilStrokePathInstancedNV ( ( GLsizei ) mMessageLen, GL_UNSIGNED_BYTE, mText.c_str(), mFont->getGlyphs(), 1, ~0, /* Use all stencil bits */ GL_TRANSLATE_X_NV, xtranslate ); gl::color ( mStrokeColor ); glCoverStrokePathInstancedNV ( ( GLsizei ) mMessageLen, GL_UNSIGNED_BYTE, mText.c_str(), mFont->getGlyphs(), GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV, GL_TRANSLATE_X_NV, xtranslate ); } if ( mFilling ) { /* STEP 1: stencil message into stencil buffer. Results in samples within the message's glyphs to have a non-zero stencil value. */ glStencilFillPathInstancedNV ( ( GLsizei ) mMessageLen, GL_UNSIGNED_BYTE, mText.c_str(), mFont->getGlyphs(), GL_PATH_FILL_MODE_NV, ~0, /* Use all stencil bits */ GL_TRANSLATE_X_NV, xtranslate ); gl::color ( mFillColor ); glCoverFillPathInstancedNV ( ( GLsizei ) mMessageLen, GL_UNSIGNED_BYTE, mText.c_str(), mFont->getGlyphs(), GL_BOUNDING_BOX_OF_BOUNDING_BOXES_NV, GL_TRANSLATE_X_NV, xtranslate ); } gl::translate ( mInitialOffset, 0.f ); if ( mDebugDraw ) { gl::translate ( -mInitialOffset, 0.f ); glDisable ( GL_STENCIL_TEST ); for ( int i = 0; i < int ( mMessageLen ); i++ ) { int charInd = mText.c_str() [i]; float glyphWidth = mFont->getGlyphMetrics()->mGlyphWidth[charInd]; float glyphHeight = mFont->getGlyphMetrics()->mGlyphHeight[charInd]; float horizontalBearingX = mFont->getGlyphMetrics()->mHorizontalBearingX[charInd]; float horizontalBearingY = mFont->getGlyphMetrics()->mHorizontalBearingY[charInd]; float verticalBearingX = mFont->getGlyphMetrics()->mVerticalBearingX[charInd]; float verticalBearingY = mFont->getGlyphMetrics()->mVerticalBearingY[charInd]; float nextXBearing = mFont->getGlyphMetrics()->mHorizontalBearingX[mText.c_str() [i + 1]]; float lastXBearing; if ( i > 0 ) lastXBearing = mFont->getGlyphMetrics()->mHorizontalBearingX[mText.c_str() [i - 1]]; float startX = xtranslate[i]; //draw glyph bounds gl::color ( Color ( 0.f, 1.f, 0.f ) ); gl::drawStrokedRect ( Rectf ( startX + horizontalBearingX, horizontalBearingY - glyphHeight, startX + horizontalBearingX + glyphWidth, horizontalBearingY ) ); } gl::translate ( mInitialOffset, 0.f ); gl::color ( Color ( 0.f, 0.f, 1.f ) ); gl::drawStrokedRect ( Rectf ( 0, metrics.mDescender, mTotalAdvance, metrics.mAscender + metrics.mDescender ) ); gl::color ( Color ( 1.f, 0.f, 0.f ) ); gl::drawSolidCircle ( Vec2f ( 0.f, 0.f ), 100 ); glEnable ( GL_STENCIL_TEST ); } gl::popMatrices(); glDisable ( GL_STENCIL_TEST ); } }