Esempio n. 1
0
        static Sprite * _loadGLCharacterIntoFont( SpriteFont & xMap, GLCharacter * xGLChar )
        {
                if ( xGLChar == NULL )
                {
                        SISULOG("GLCharacter was NULL.");
                        exit( -1 );
                }

                if ( xMap.find( xGLChar->getCharacter( ) ) != xMap.end( ) )
                {
                        // character already loaded!
                        return xMap[ xGLChar->getCharacter( ) ];
                }

                Sprite * pT = new Sprite( );

                pT->texData = xGLChar->allocGLBuffer( );

                pT->tex.initialize( ( pT->w = xGLChar->getWidth( )  )
                                  , ( pT->h = xGLChar->getHeight( ) )
                                  , ( uint8_t* )pT->texData );

                xMap[ xGLChar->getCharacter( ) ] = pT;

	        return pT;
        }
Esempio n. 2
0
SDLShader::SDLShader( ShaderPathPair const & xShaderPaths )
        : mProgramID( 0 )
        , mVertexShaderSource( fileToString( xShaderPaths.VertexPath ) )
        , mFragmentShaderSource( fileToString(  xShaderPaths.FragmentPath ) )
{
        SISULOG( "In SDLShader Ctor" );
}
Esempio n. 3
0
SDLShader::SDLShader( ShaderSourcePair const & xShaderSources )
        : mProgramID( 0 )
        , mVertexShaderSource( xShaderSources.VertexSource )
        , mFragmentShaderSource( xShaderSources.FragmentSource )
{
        SISULOG( "In SDLShader Ctor" );
}
Esempio n. 4
0
		CursorRenderer( )
			: mCursor( NULL )
#ifdef LINUX
			, mDisplay( XOpenDisplay( NULL ) )
			, mCursorGrabbed( false )
#endif
		{
			SISULOG( "In CursorRenderer Ctor" );
		}
Esempio n. 5
0
		TextRenderer( )
			: mDefaultWriter( "resources/terminus.ttf"
					, 32
					, "" )
			, mSpriteFont( )
			, mW( 0 )
			, mH( 0 )
		{
			SISULOG( "In TextRenderer Ctor" );
		}
Esempio n. 6
0
		void initialize( uint32_t const xW, uint32_t const xH )
		{
			SISULOG("In TextRenderer::Initialize" );
			mW = xW;
			mH = xH;

                        for ( char c = '!'; c < '~'; c++ )
			{
#ifdef ANDROID
		                __android_log_print( ANDROID_LOG_VERBOSE
		                                    , "sisu"
		                                    , "Load character %c \n"
						    , c );
#endif
				_loadGLCharacterIntoFont( mSpriteFont, mDefaultWriter[ c ] );
			}

			mQuad.initialize( );
			SISULOG("Out TextRenderer::Initialize" );
		}
Esempio n. 7
0
	void _loadPNGTexture( std::vector<Texture2D> & xTextures
		   	     , const char * xPath
			     , eTexture2DType const xLocalEquivalent )
	{
		SISULOG( "IN _loadPNGTexture" );
		std::cerr << "xPath = " << xPath << std::endl;
		DevILImage * image = new DevILImage( xPath );

                Texture2D texture( xLocalEquivalent );

		texture.initialize( image->getWidth( )
				   , image->getHeight( )
				   , image->toGLTextureBuffer( )
				   , aiString( xPath ) );

                xTextures.push_back( texture );
                mTextures.push_back( texture );
		mTextureData.push_back( image );
		SISULOG( "OUT _loadPNGTexture" );
	}
Esempio n. 8
0
    std::vector<uint8_t> _makePNG( char const xC )
    {
        mFont.loadGlyph( xC, 0.0f );

        PNGImage output( { mFont.getGlyphWidth( ), mFont.getGlyphHeight( ) } );

        mFont.printSpans( output, mOutlineColor, mFillColor );

#if 0
        SISULOG("Creating filename.");
        std::stringstream filename;

        _makeFilename( filename, xC );
#endif

        SISULOG("Blitting.");
        output.blit( );

        uint8_t *    data = output.getData( );
        size_t const size = output.getDataSize( );

        SISULOG("Writing to file for posterity.");

        std::cout << "Output data size was: " << size << std::endl;

#if 0
        memoryToFile( filename.str( ).c_str( ), data, size );
#endif

        std::vector<uint8_t> buffer;

        buffer.assign( data, data + size );

        SISULOG("_makePNG OUT");

        return buffer;
    }
Esempio n. 9
0
    GLCharacterMap( const char * xFontPath
                    , uint32_t const xFontSize // fixed for now
                    , const char * xTextureStoragePath
                    , _FontPixel32 const & xOutline = _FontPixel32( 255, 255, 255 )
                            , _FontPixel32 const & xFill    = _FontPixel32( 255, 255, 255 ) )// TODO: Hook in memory font support if it becomes necessary (like streaming from net)
        : mFont( xFontPath )
        , mFontSize( xFontSize )
        , mTextureStorage( xTextureStoragePath )
        , mOutlineColor( xOutline )
        , mFillColor( xFill )
    {
        if ( xTextureStoragePath == NULL )
        {
            SISULOG("Texture storage location was not specified (null).");
            exit( -1 );
        }

        mFont.setFontSize( xFontSize );
    }
Esempio n. 10
0
	void _loadTextures( std::vector< Texture2D > & xTextures, aiMesh * xMesh, const aiScene * xScene )
	{
	        if( xMesh->mMaterialIndex >= 0)
	        {
	        	aiMaterial* material = xScene->mMaterials[ xMesh->mMaterialIndex ];

			auto __loadMatTex = [&]( aiTextureType const xAssimpType, eTexture2DType const xLocalType )
			{
				std::vector< Texture2D > maps = _loadMaterialTextures( material, xAssimpType, xLocalType );
				xTextures.insert( xTextures.end( ), maps.begin( ), maps.end( ) );
			};

			__loadMatTex( aiTextureType_DIFFUSE , eTexture2DType_Diffuse  );
			__loadMatTex( aiTextureType_SPECULAR, eTexture2DType_Specular );
			__loadMatTex( aiTextureType_HEIGHT  , eTexture2DType_Normal   ); // ? Bug ? TODO: Ask joey.
			__loadMatTex( aiTextureType_AMBIENT , eTexture2DType_Height   );
		}
		else
		{
			SISULOG("No materials found.");
		}
	}
Esempio n. 11
0
void SDLQuadShader::initialize( OpenGLAttributes const & xAttributes )
{
        SDLTestShaderWindow::initialize( xAttributes );

        // TODO: Automate these procedural things so it can be used like a key.
        // i.e myshaderProgram["LVertexPos2D"] = new value
        // structure should be map<GLint, std::string> or similar
        mVertexPos2DLocation = glGetAttribLocation( mShader.getProgramID( ), "LVertexPos2D" );

        if( mVertexPos2DLocation == -1 )
        {
                SISULOG( "GLSL program variable LVertexPOS2D not found." );
                exit( -1 );
        }

        glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );


        GLfloat vertexData[] =
                {
                        -0.5f, -0.5f,
                         0.5f, -0.5f,
                         0.5f,  0.5f,
                        -0.5f,  0.5f
                };

        GLuint indexData[] = { 0, 1, 2, 3 };

        glGenBuffers( 1, &mVBO );
        glBindBuffer( GL_ARRAY_BUFFER, mVBO );
        glBufferData( GL_ARRAY_BUFFER, 2 * 4 * sizeof(GLfloat), vertexData, GL_STATIC_DRAW );

        glGenBuffers( 1, &mIBO );
        glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, mIBO );
        glBufferData( GL_ELEMENT_ARRAY_BUFFER, 4 * sizeof(GLuint), indexData, GL_STATIC_DRAW );
}
Esempio n. 12
0
			Keyboard( double const xDebounceTicks = 18000000.0 )
				: mM( )
				, mQuit( )
				, mCallbacks( )
				, mInitialized( false )
				, mKeyboardListener( [ & ] ( int64_t const xSleepIntervalNs ) -> uint32_t
		  		{
			                bool pressedLastTime[ SDL_NUM_SCANCODES ];

					for ( uint16_t ii = 0; ii < SDL_NUM_SCANCODES; ++ii )
					{
						pressedLastTime [ ii ] = false;
					}

					double continueDebounceAccum = 0.0;

					Stopwatch t;

					while ( !mQuit.isSet( ) )
					{
						if ( xSleepIntervalNs > 0 )
						{
							sleep::ns( xSleepIntervalNs );
						}

						const Uint8 * state = SDL_GetKeyboardState( NULL );

		        	                for ( uint16_t ii = 0; ii < SDL_NUM_SCANCODES; ++ii )
	        	        	        {
							eKeyState keyState = eKeyState_None;

							auto runCallbacks = [&]()
							{
								mM.run([&]( )
								{
									for ( auto callback : mCallbacks )
									{
										callback( KeyboardEvent( keyState, ii, state ) );
									}
								});
							};

		        	                        if ( state[ ii ] && !pressedLastTime[ ii ] )
		                	                {
								keyState = eKeyState_Down;
								t.startMs( );
			                                }
							else if ( state[ ii ] && pressedLastTime[ ii ] )
							{
								continueDebounceAccum += t.stop( );

								if ( continueDebounceAccum > mDebounceTicks )
								{
									keyState = eKeyState_Continue;
									continueDebounceAccum = 0;
									t.startMs( );
								}
							}
		        	                        else if ( !state[ ii ] && pressedLastTime[ ii ] )
		                	                {
								keyState = eKeyState_Up;
			                                }

							if ( keyState != eKeyState_None )
							{
								runCallbacks( );
							}

			                                pressedLastTime[ ii ] = state[ ii ];
						}
					}
				})
				, mDebounceTicks( xDebounceTicks )
			{
				SISULOG( "In Keyboard Ctor" );
			}