Esempio n. 1
0
TextureManager::TextureManager() : nextTexModuleId(0) {
    int length = TEXTURE_SIZE * TEXTURE_SIZE * 4;
    unsigned char *data = new unsigned char[length];
    memset(data, 0, sizeof(unsigned char) * length);

    for(int i = 0; i < TEXTURE_COUNT; ++i) {
        Texture2D *tex = new Texture2D();
        tex->initWithData(data, length, Texture2D::PixelFormat::RGBA8888, TEXTURE_SIZE, TEXTURE_SIZE, Size(TEXTURE_SIZE, TEXTURE_SIZE));
        textures.push_back(tex);
        TextureBinPack *bin = new TextureBinPack(TEXTURE_SIZE, TEXTURE_SIZE);
        textureBins.push_back(bin);
    }

    CC_SAFE_DELETE_ARRAY(data);

    reloadShaders();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
    /** listen the event that renderer was recreated on Android/WP8 */
    _backToForegroundlistener = EventListenerCustom::create(EVENT_RENDERER_RECREATED, [this](EventCustom *) {
		CCLOG("texturemanager reload textures");
        reloadShaders();
        reloadTextures();
    });
    Director::getInstance()->getEventDispatcher()->addEventListenerWithFixedPriority(_backToForegroundlistener, -1);
#endif
}
Esempio n. 2
0
//--------------------------------------------------------------
// restore device resources
void mgGL33Services::createBuffers()
{
  initView();

  reloadTextures();
  setCursorTexture(m_cursorFileName, m_cursorHotX, m_cursorHotY);
}
Esempio n. 3
0
        void TextureManager::addCollection(TextureCollection* collection, size_t index) {
            assert(index <= m_collections.size());

            TextureCollectionList::iterator insertPos = m_collections.begin();
            std::advance(insertPos, index);
            m_collections.insert(insertPos, collection);

            reloadTextures();
        }
Esempio n. 4
0
//--------------------------------------------------------------
void testApp::setup() {
    linearSmooth = false;
    reloadTextures();
    
    srcBlend = 8;
    dstBlend = 9;
    
    currAlphaMode = 0;
    currSizeMode = 0;
}
Esempio n. 5
0
        TextureCollection* TextureManager::removeCollection(size_t index) {
            assert(index < m_collections.size());
            TextureCollection* collection = m_collections[index];

            TextureCollectionList::iterator removePos = m_collections.begin();
            std::advance(removePos, index);
            m_collections.erase(removePos);

            reloadTextures();
            return collection;
        }
void
Java_cc_openframeworks_OFAndroid_onSurfaceCreated( JNIEnv*  env, jclass  thiz ){
	ofLog(OF_LOG_NOTICE,"onSurfaceCreated");
	reloadTextures();
	if(androidApp){
		androidApp->resume();
		androidApp->reloadTextures();
	}
	ofPopStyle();
	paused = false;
}
void
Java_cc_openframeworks_OFAndroid_onResume( JNIEnv*  env, jobject  thiz ){

	reloadTextures();
	if(androidApp){
		androidApp->resume();
		androidApp->reloadTextures();
	}
	paused = false;
	ofxAndroidSoundStreamResume();
}
void
Java_cc_openframeworks_OFAndroid_onSurfaceCreated( JNIEnv*  env, jclass  thiz ){
	ofLog(OF_LOG_NOTICE,"onSurfaceCreated");
	if(!surfaceDestroyed){
		ofUnloadAllFontTextures();
		ofPauseVideoGrabbers();
	}
	reloadTextures();
	if(androidApp){
		androidApp->reloadTextures();
	}
	ofSetStyle(ofGetStyle());
	ofSetOrientation(ofGetOrientation());
	surfaceDestroyed = false;

}
Esempio n. 9
0
//--------------------------------------------------------------
void testApp::keyPressed(int key) {
    switch (key) {
        case 's':
            linearSmooth = !linearSmooth;
        case ' ':
            reloadTextures();
            break;
        
        case 'f':
            currSizeMode = (currSizeMode+1)%4;
            tex.setSizeMode(currSizeMode);
            break;
        
        case OF_KEY_UP:
            srcBlend = (srcBlend+1)%10;
            break;
        case OF_KEY_DOWN:
            srcBlend = (srcBlend-1)%10;
            break;
            
        case OF_KEY_RIGHT:
            dstBlend = (dstBlend+1)%10;
            break;
        case OF_KEY_LEFT:
            dstBlend = (dstBlend-1)%10;
            break;
            
        case ',':
        case '<':
            currAlphaMode = (currAlphaMode-1)%5;
            tex.setAlphaMode(currAlphaMode);
            break;
        case '.':
        case '>':
            currAlphaMode = (currAlphaMode+1)%5;
            tex.setAlphaMode(currAlphaMode);
            break;
    }
    
    printf("src:%d\t\tdst:%d\t\talpha:%d\t\tsize:%d\n", srcBlend, dstBlend, currAlphaMode, currSizeMode);
}
Esempio n. 10
0
int MS3D::LoadModelData(const char *path, const char *filename)
{
    _path = path;
    std::stringstream fn;
    fn << path << filename;
    ifstream inputFile(fn.str().c_str(), ios::in | ios::binary);
    if ( inputFile.fail())
        return false;

    char pathTemp[PATH_MAX+1];
    int pathLength;
    for ( pathLength = strlen( fn.str().c_str() ); pathLength--; ) 
        if ( fn.str().c_str()[pathLength] == '/' || fn.str().c_str()[pathLength] == '\\' ) 
            break;

    strncpy( pathTemp, fn.str().c_str(), pathLength );

    inputFile.seekg( 0, ios::end );
    long fileSize = inputFile.tellg();
    inputFile.seekg( 0, ios::beg );

    char *pBuffer = new char[fileSize];
    inputFile.read(pBuffer, fileSize );
    inputFile.close();

    const byte *pPtr = reinterpret_cast<unsigned char*>(pBuffer);
    MS3DHeader *pHeader = ( MS3DHeader* )pPtr;
    pPtr += sizeof( MS3DHeader );

    if ( strncmp( pHeader->m_ID, "MS3D000000", 10 ) != 0 )
    {
        printf("Not a valid Milkshape3D model file.\n");
        return -1; // "Not a valid Milkshape3D model file."
    }

    if ( pHeader->m_version < 3 || pHeader->m_version > 4 )
    {
        printf("Unhandled file version. Only Milkshape3D Version 1.3 and 1.4 is supported.\n");
        return -1; // "Unhandled file version. Only Milkshape3D Version 1.3 and 1.4 is supported." );
    }

    int nVertices = *( word* )pPtr;
    m_numVertices = nVertices;
    m_pVertices = new Vertex[nVertices];
    pPtr += sizeof( word );

    int i;
    for ( i = 0; i < nVertices; i++ )
    {
        MS3DVertex *pVertex = ( MS3DVertex* )pPtr;
        m_pVertices[i].m_boneID = pVertex->m_boneID;
        memcpy( m_pVertices[i].m_location, pVertex->m_vertex, sizeof( float )*3 );
        pPtr += sizeof( MS3DVertex );
    }

    int nTriangles = *( word* )pPtr;
    m_numTriangles = nTriangles;
    m_pTriangles = new Triangle[nTriangles];
    pPtr += sizeof( word );

    for ( i = 0; i < nTriangles; i++ )
    {
        MS3DTriangle *pTriangle = ( MS3DTriangle* )pPtr;
        int vertexIndices[3] = { pTriangle->m_vertexIndices[0], pTriangle->m_vertexIndices[1], pTriangle->m_vertexIndices[2] };
        float t[3] = { 1.0f-pTriangle->m_t[0], 1.0f-pTriangle->m_t[1], 1.0f-pTriangle->m_t[2] };
        memcpy( m_pTriangles[i].m_vertexNormals, pTriangle->m_vertexNormals, sizeof( float )*3*3 );
        memcpy( m_pTriangles[i].m_s, pTriangle->m_s, sizeof( float )*3 );
        memcpy( m_pTriangles[i].m_t, t, sizeof( float )*3 );
        memcpy( m_pTriangles[i].m_vertexIndices, vertexIndices, sizeof( int )*3 );
        pPtr += sizeof( MS3DTriangle );
    }



    int nGroups = *( word* )pPtr;
    m_numMeshes = nGroups;
    m_pMeshes = new Mesh[nGroups];
    pPtr += sizeof( word );
    for ( i = 0; i < nGroups; i++ )
    {
        pPtr += sizeof( byte );	// flags
        pPtr += 32;				// name

        word nTriangles = *( word* )pPtr;
        pPtr += sizeof( word );
        int *pTriangleIndices = new int[nTriangles];
        for ( int j = 0; j < nTriangles; j++ )
        {
            pTriangleIndices[j] = *( word* )pPtr;
            pPtr += sizeof( word );
        }

        char materialIndex = *( char* )pPtr;
        pPtr += sizeof( char );

        m_pMeshes[i].m_materialIndex = materialIndex;
        m_pMeshes[i].m_numTriangles = nTriangles;
        m_pMeshes[i].m_pTriangleIndices = pTriangleIndices;
    }



    int nMaterials = *( word* )pPtr;
    m_numMaterials = nMaterials;
    m_pMaterials = new Material[nMaterials];
    pPtr += sizeof( word );
    for ( i = 0; i < nMaterials; i++ )
    {
        MS3DMaterial *pMaterial = ( MS3DMaterial* )pPtr;
        memcpy( m_pMaterials[i].m_ambient, pMaterial->m_ambient, sizeof( float )*4 );
        memcpy( m_pMaterials[i].m_diffuse, pMaterial->m_diffuse, sizeof( float )*4 );
        memcpy( m_pMaterials[i].m_specular, pMaterial->m_specular, sizeof( float )*4 );
        memcpy( m_pMaterials[i].m_emissive, pMaterial->m_emissive, sizeof( float )*4 );
        m_pMaterials[i].m_shininess = pMaterial->m_shininess;
        if ( strncmp( pMaterial->m_texture, ".\\", 2 ) == 0 ) {
            // MS3D 1.5.x relative path
            strcpy( pathTemp + pathLength, pMaterial->m_texture + 1 );
            m_pMaterials[i].m_pTextureFilename = new char[strlen( pathTemp )+1];
            strcpy( m_pMaterials[i].m_pTextureFilename, pathTemp );
        }
        else {
            // MS3D 1.4.x or earlier - absolute path
            m_pMaterials[i].m_pTextureFilename = new char[strlen( pMaterial->m_texture )+1];
            strcpy( m_pMaterials[i].m_pTextureFilename, pMaterial->m_texture );
        }
        pPtr += sizeof( MS3DMaterial );
    }

    reloadTextures();
    delete[] pBuffer;

    int num;
    num=glGenLists(1);      //I generate a unique identifier for the list
    glNewList(num,GL_COMPILE);
    
    GLboolean texEnabled = glIsEnabled(GL_TEXTURE_2D);

    for ( int i = 0; i < m_numMeshes; i++ )                     // draw in groups
    {
        int materialIndex = m_pMeshes[i].m_materialIndex;
        if ( materialIndex >= 0 )
        {
            glMaterialfv( GL_FRONT, GL_AMBIENT,   m_pMaterials[materialIndex].m_ambient );
            glMaterialfv( GL_FRONT, GL_DIFFUSE,   m_pMaterials[materialIndex].m_diffuse );
            glMaterialfv( GL_FRONT, GL_SPECULAR,  m_pMaterials[materialIndex].m_specular );
            glMaterialfv( GL_FRONT, GL_EMISSION,  m_pMaterials[materialIndex].m_emissive );
            glMaterialf(  GL_FRONT, GL_SHININESS, m_pMaterials[materialIndex].m_shininess );

            if ( m_pMaterials[materialIndex].m_texture > 0 )
            {
                glBindTexture( GL_TEXTURE_2D, m_pMaterials[materialIndex].m_texture );
                glEnable(GL_TEXTURE_2D);
                glEnable(GL_BLEND);
            }
            else
            {
                glDisable(GL_BLEND);
                glDisable(GL_TEXTURE_2D);
            }
        }
        else
        {
            glDisable(GL_BLEND);
            glDisable(GL_TEXTURE_2D);
        }

        glBegin( GL_TRIANGLES );
        {
            for ( int j = 0; j < m_pMeshes[i].m_numTriangles; j++ )
            {
                int triangleIndex = m_pMeshes[i].m_pTriangleIndices[j];
                const Triangle* pTri = &m_pTriangles[triangleIndex];

                for ( int k = 0; k < 3; k++ )
                {
                    int index = pTri->m_vertexIndices[k];

                    glNormal3fv( pTri->m_vertexNormals[k] );
                    glTexCoord2f( pTri->m_s[k], pTri->m_t[k] );
                    glVertex3fv( m_pVertices[index].m_location );
                }
            }
        }
        glEnd();
    }

    /*if ( texEnabled )
    {
        glEnable(GL_BLEND);
        glEnable(GL_TEXTURE_2D);
    }
    else*/
    {
        glDisable(GL_BLEND);
        glDisable( GL_TEXTURE_2D );
    }
    glEndList();
    Cleanup();
    return num;
}
Esempio n. 11
0
bool MilkshapeModel::loadModelData( const char *filename )
{
	ifstream inputFile( filename, ios::in | ios::binary | ios::nocreate );
	if ( inputFile.fail())
		return false;	// "Couldn't open the model file."

	inputFile.seekg( 0, ios::end );
	long fileSize = inputFile.tellg();
	inputFile.seekg( 0, ios::beg );

	byte *pBuffer = new byte[fileSize];
	inputFile.read( pBuffer, fileSize );
	inputFile.close();

	const byte *pPtr = pBuffer;
	MS3DHeader *pHeader = ( MS3DHeader* )pPtr;
	pPtr += sizeof( MS3DHeader );

	if ( strncmp( pHeader->m_ID, "MS3D000000", 10 ) != 0 ) {
		printf("Not a valid Milkshape3D model file.\n");
		return false; // "Not a valid Milkshape3D model file."
	}

	if ( pHeader->m_version < 3 || pHeader->m_version > 4 ) {
		printf("Unhandled file version. Only Milkshape3D Version 1.3 and 1.4 is supported.\n");
		return false; // "Unhandled file version. Only Milkshape3D Version 1.3 and 1.4 is supported." );
	}

	int nVertices = *( word* )pPtr; 
	m_numVertices = nVertices;
	m_pVertices = new Vertex[nVertices];
	pPtr += sizeof( word );

	int i;
	for ( i = 0; i < nVertices; i++ )
	{
		MS3DVertex *pVertex = ( MS3DVertex* )pPtr;
		m_pVertices[i].m_boneID = pVertex->m_boneID;
		memcpy( m_pVertices[i].m_location, pVertex->m_vertex, sizeof( float )*3 );
		pPtr += sizeof( MS3DVertex );
	}

	int nTriangles = *( word* )pPtr;
	m_numTriangles = nTriangles;
	m_pTriangles = new Triangle[nTriangles];
	pPtr += sizeof( word );

	for ( i = 0; i < nTriangles; i++ )
	{
		MS3DTriangle *pTriangle = ( MS3DTriangle* )pPtr;
		int vertexIndices[3] = { pTriangle->m_vertexIndices[0], pTriangle->m_vertexIndices[1], pTriangle->m_vertexIndices[2] };
		float t[3] = { 1.0f-pTriangle->m_t[0], 1.0f-pTriangle->m_t[1], 1.0f-pTriangle->m_t[2] };
		memcpy( m_pTriangles[i].m_vertexNormals, pTriangle->m_vertexNormals, sizeof( float )*3*3 );
		memcpy( m_pTriangles[i].m_s, pTriangle->m_s, sizeof( float )*3 );
		memcpy( m_pTriangles[i].m_t, t, sizeof( float )*3 );
		memcpy( m_pTriangles[i].m_vertexIndices, vertexIndices, sizeof( int )*3 );
		pPtr += sizeof( MS3DTriangle );
	}

	int nGroups = *( word* )pPtr;
	m_numMeshes = nGroups;
	m_pMeshes = new Mesh[nGroups];
	pPtr += sizeof( word );
	for ( i = 0; i < nGroups; i++ )
	{
		pPtr += sizeof( byte );	// flags
		pPtr += 32;				// name

		word nTriangles = *( word* )pPtr;
		pPtr += sizeof( word );
		int *pTriangleIndices = new int[nTriangles];
		for ( int j = 0; j < nTriangles; j++ )
		{
			pTriangleIndices[j] = *( word* )pPtr;
			pPtr += sizeof( word );
		}

		char materialIndex = *( char* )pPtr;
		pPtr += sizeof( char );
	
		m_pMeshes[i].m_materialIndex = materialIndex;
		m_pMeshes[i].m_numTriangles = nTriangles;
		m_pMeshes[i].m_pTriangleIndices = pTriangleIndices;
	}

	int nMaterials = *( word* )pPtr;
	m_numMaterials = nMaterials;
	m_pMaterials = new Material[nMaterials];
	pPtr += sizeof( word );
	for ( i = 0; i < nMaterials; i++ )
	{
		MS3DMaterial *pMaterial = ( MS3DMaterial* )pPtr;
		memcpy( m_pMaterials[i].m_ambient, pMaterial->m_ambient, sizeof( float )*4 );
		memcpy( m_pMaterials[i].m_diffuse, pMaterial->m_diffuse, sizeof( float )*4 );
		memcpy( m_pMaterials[i].m_specular, pMaterial->m_specular, sizeof( float )*4 );
		memcpy( m_pMaterials[i].m_emissive, pMaterial->m_emissive, sizeof( float )*4 );
		m_pMaterials[i].m_shininess = pMaterial->m_shininess;
		m_pMaterials[i].m_pTextureFilename = new char[strlen( pMaterial->m_texture )+1];
		strcpy( m_pMaterials[i].m_pTextureFilename, pMaterial->m_texture );
		pPtr += sizeof( MS3DMaterial );
	}

	reloadTextures();

	delete[] pBuffer;

	return true;
}