From 3dfe2108cfab31ba3ee5527e217d0d8e99a51162 Mon Sep 17 00:00:00 2001 From: git perforce import user Date: Tue, 25 Oct 2016 12:29:14 -0600 Subject: Initial commit: PhysX 3.4.0 Update @ 21294896 APEX 1.4.0 Update @ 21275617 [CL 21300167] --- KaplaDemo/samples/sampleViewer3/GLFontRenderer.cpp | 334 +++++++++++++++++++++ 1 file changed, 334 insertions(+) create mode 100644 KaplaDemo/samples/sampleViewer3/GLFontRenderer.cpp (limited to 'KaplaDemo/samples/sampleViewer3/GLFontRenderer.cpp') diff --git a/KaplaDemo/samples/sampleViewer3/GLFontRenderer.cpp b/KaplaDemo/samples/sampleViewer3/GLFontRenderer.cpp new file mode 100644 index 00000000..ec205445 --- /dev/null +++ b/KaplaDemo/samples/sampleViewer3/GLFontRenderer.cpp @@ -0,0 +1,334 @@ +#ifndef PHYSX_NO_RENDERER + +#include "GLFontData.h" +#include "GLFontRenderer.h" + +#include +#include +#include +#include +#include + +using namespace physx; + +bool GLFontRenderer::init() +{ + m_isInit=false; + m_textureObject=0; + m_screenWidth=640; + m_screenHeight=480; + m_color = 0xffffffff; + + glGenTextures(1, &m_textureObject); + if(m_textureObject == 0) + return false; + + glBindTexture(GL_TEXTURE_2D, m_textureObject); + + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + // expand to rgba + unsigned char* pNewSource = new unsigned char[OGL_FONT_TEXTURE_WIDTH*OGL_FONT_TEXTURE_HEIGHT*4]; + for(int i=0;i +void GLFontRenderer::print( float fontSize, const char* pString, bool forceMonoSpace, int monoSpaceWidth, bool doOrthoProj, TOperator inOperator ) +{ + if ( !m_isInit ) + init(); + unsigned int num = safeStrlen( pString ); + if ( !m_isInit || !num ) + return; + + glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + + glEnable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, m_textureObject); + + if(doOrthoProj) + { + glMatrixMode(GL_PROJECTION); + glPushMatrix(); + glLoadIdentity(); + + glOrtho(0, m_screenWidth, 0, m_screenHeight, -1, 1); + } + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glEnable(GL_BLEND); + + glColor4f((m_color&0xff) / float(0xff), ((m_color>>8)&0xff) / float(0xff), + ((m_color>>16)&0xff) / float(0xff), ((m_color>>24)&0xff) / float(0xff)); + + mVertList.resize( PxMax( num * 6 * 3, mVertList.size() ) ); + mTextureCoordList.resize( PxMax( num * 6 * 2, mTextureCoordList.size() ) ); + PxF32* pVertList = reinterpret_cast( mVertList.begin() ); + PxF32* pTextureCoordList = reinterpret_cast( mTextureCoordList.begin() ); + + int vertIndex = 0; + int textureCoordIndex = 0; + + float translateDown = 0.0f; + float translate = 0.0f; + unsigned int count = 0; + + const float glyphHeightUV = ((float)OGL_FONT_CHARS_PER_COL)/OGL_FONT_TEXTURE_HEIGHT*2-0.01f; + const float glyphWidthUV = ((float)OGL_FONT_CHARS_PER_ROW)/OGL_FONT_TEXTURE_WIDTH; + + for(unsigned int i=0;i