Exemplo n.º 1
0
//----------------------------------------------------------
void ofFbo::activateAllDrawBuffers(){
	if(!bIsAllocated) return;
#ifndef TARGET_OPENGLES
    vector<int> activeBuffers(getNumTextures(),0);
    for(int i=0; i < getNumTextures(); i++){
    	activeBuffers[i] = i;
    }
    setActiveDrawBuffers(activeBuffers);
#endif
}
Exemplo n.º 2
0
void ofFbo::activateAllDrawBuffers(){
	#ifndef TARGET_OPENGLES
    vector<GLenum> attachments;
    for(int i=0; i < getNumTextures(); i++){
        if (i < getNumTextures()){
            GLenum e = GL_COLOR_ATTACHMENT0 + i;
            attachments.push_back(e);
        }else{
            ofLog(OF_LOG_WARNING,"trying to activate texture "+ofToString(i) + " for drawing that is out of the range (0->" + ofToString(getNumTextures()) + ") of allocated textures for this fbo.");
        }
    }
    glDrawBuffers(attachments.size(),&attachments[0]);
	#endif
}
Exemplo n.º 3
0
void ofFbo::activateAllDrawBuffers(){
	if(!bIsAllocated) return;
#ifndef TARGET_OPENGLES
    vector<GLenum> attachments;
    for(int i=0; i < getNumTextures(); i++){
        if (i < getNumTextures()){
            GLenum e = GL_COLOR_ATTACHMENT0 + i;
            attachments.push_back(e);
        }else{
            ofLogWarning("ofFbo") << "activateAllDrawBuffers(): fbo " << fbo << " couldn't set texture " << i << ", only " << getNumTextures() << "allocated";
        }
    }
    glDrawBuffers(attachments.size(),&attachments[0]);
#endif
}
FontAtlas * FontDefinitionTTF::createFontAtlas()
{
    FontAtlas *retAtlas = new FontAtlas( *_textImages->getFont() );
    
    if (!retAtlas)
        return 0;
    
    // add all the textures
    int numTextures = getNumTextures();
    if (!numTextures)
        return 0;
    
    for (int c = 0; c<numTextures; ++c)
        retAtlas->addTexture(*getTexture(c), c);
    
    // set the common line height
    retAtlas->setCommonLineHeight(getCommonLineHeight() * 0.8);
    
    
    for( auto &item: _fontLettersDefinitionUTF16 )
    {
        if ( item.second.validDefinition )
        {
            FontLetterDefinition tempDefinition = item.second;
            tempDefinition.offsetX = 0;
            tempDefinition.anchorX = 0.0f;
            tempDefinition.anchorY = 1.0f;
            retAtlas->addLetterDefinition(tempDefinition);
        }
    }
    
    // done here
    return retAtlas;
}
Exemplo n.º 5
0
//TODO: Should we also check against card's max attachments or can we assume that's taken care of in texture setup? Still need to figure out MSAA in conjunction with MRT
void ofFbo::setActiveDrawBuffer(int i){
#ifndef TARGET_OPENGLES
    if (i < getNumTextures()){
        GLenum e = GL_COLOR_ATTACHMENT0 + i;
        glDrawBuffer(e);
    }else{
        ofLog(OF_LOG_WARNING,"trying to activate texture "+ofToString(i) + " for drawing that is out of the range (0->" + ofToString(getNumTextures()) + ") of allocated textures for this fbo.");
    }
	#endif
}
Exemplo n.º 6
0
//TODO: Should we also check against card's max attachments or can we assume that's taken care of in texture setup? Still need to figure out MSAA in conjunction with MRT
void ofFbo::setActiveDrawBuffer(int i){
#ifndef TARGET_OPENGLES
    if (i < getNumTextures()){
        GLenum e = GL_COLOR_ATTACHMENT0 + i;
        glDrawBuffer(e);
    }else{
        ofLogWarning("ofFbo") << "trying to activate texture " << i << " for drawing that is out of the range (0->" << getNumTextures() << ") of allocated textures for this fbo.";
    }
	#endif
}
Exemplo n.º 7
0
//TODO: Should we also check against card's max attachments or can we assume that's taken care of in texture setup? Still need to figure out MSAA in conjunction with MRT
void ofFbo::setActiveDrawBuffer(int i){
	if(!bIsAllocated) return;
#ifndef TARGET_OPENGLES
    if (i < getNumTextures()){
        GLenum e = GL_COLOR_ATTACHMENT0 + i;
        glDrawBuffer(e);
    }else{
		ofLogWarning("ofFbo") << "setActiveDrawBuffer(): fbo " << fbo << " couldn't set texture " << i << ", only " << getNumTextures() << "allocated";
    }
#endif
}
Exemplo n.º 8
0
void ofFbo::setActiveDrawBuffers(const vector<int>& ids){
	#ifndef TARGET_OPENGLES
    vector<GLenum> attachments;
    for(int i=0; i < (int)ids.size(); i++){
      int id = ids[i];
        if (id < getNumTextures()){
            GLenum e = GL_COLOR_ATTACHMENT0 + id;
            attachments.push_back(e);
        }else{
            ofLogWarning("ofFbo") << "trying to activate texture " << id << " for drawing that is out of the range (0->" << getNumTextures() << ") of allocated textures for this fbo.";
        }
    }
    glDrawBuffers(attachments.size(),&attachments[0]);
	#endif
}
Exemplo n.º 9
0
//----------------------------------------------------------
void ofFbo::setActiveDrawBuffers(const vector<int>& ids){
	if(!bIsAllocated) return;
#ifndef TARGET_OPENGLES
    int numBuffers = activeDrawBuffers.size();
	activeDrawBuffers.clear();
	activeDrawBuffers.resize(numBuffers, GL_NONE); // we initialise the vector with GL_NONE, so a buffer will not be written to unless activated.
    for(int i=0; i < (int)ids.size(); i++){
      int id = ids[i];
        if (id < getNumTextures()){
            GLenum e = GL_COLOR_ATTACHMENT0 + id;
            activeDrawBuffers[id] = e; // activate requested buffers
			dirty[id] = true; // dirty activated draw buffers.
        }else{
            ofLogWarning("ofFbo") << "setActiveDrawBuffers(): fbo " << fbo << " couldn't set texture " << i << ", only " << getNumTextures() << "allocated";
        }
    }
    glDrawBuffers(activeDrawBuffers.size(),&activeDrawBuffers[0]);
#endif
}
Exemplo n.º 10
0
/**
 * Sets a grid to the ::IND_Surface object. A grid is just a mesh which vertices
 * can be moved in order to deform the graphical object. You can set grids of different levels
 * of tesselation.
 *
 * Using grids you can apply lot of different morphing effects to your sprites or animations
 * (waves, bubble animation, etc). It is also possible to change the position of all the vertices
 * so it would be possible to create for example a "snake" sprite that could simulate the crawling
 * when moving.
 * 
 * There is a restriction: the amount of horizontal and vertical blocks should be power of two.
 *
 * Example:
 * - SetGrid ( 4, 4) => Correct!
 * - SetGrid (16, 2) => Correct!
 * - SetGrid ( 1, 8) => Correct!
 * - SetGrid ( 1, 3) => Incorrect!
 *
 * @param pNumBlocksX					Number of horizontal blocks.
 * @param pNumBlocksY					Number of vertical blocks.
 */
bool IND_Surface::setGrid(int pNumBlocksX, int pNumBlocksY) {
	// At least one block
	if (pNumBlocksX < 1 || pNumBlocksY < 1) return 0;

	// Only power of two values allowed
	IND_Math mMath;
	if (!mMath.isPowerOfTwo(pNumBlocksX) || !mMath.isPowerOfTwo(pNumBlocksY)) return 0;

	// Only 1-texture-IND_Surfaces allowed
	if (getNumTextures() != 1) return 0;

	// Reset attributes
	_surface->_attributes._isHaveGrid        = 1;
	_surface->_attributes._blocksX           = pNumBlocksX;
	_surface->_attributes._blocksY           = pNumBlocksY;
	_surface->_attributes._widthBlock        = (_surface->_attributes._width / _surface->_attributes._blocksX);
	_surface->_attributes._heightBlock       = (_surface->_attributes._height / _surface->_attributes._blocksY);
	_surface->_attributes._numBlocks         = _surface->_attributes._blocksX * _surface->_attributes._blocksY;
	
	// Reset the vertex array
	DISPOSEARRAY(_surface->_vertexArray);
	_surface->_vertexArray = new CUSTOMVERTEX2D [_surface->_attributes._blocksX * _surface->_attributes._blocksY * 4];

	// Current position of the vertex
	int _posX = 0;
	int _posY = _surface->_attributes._height;
	int mPosZ = 0;

	// Position in which we are storing a vertex
	int mPosVer = 0;

	// Create the new vertex array
	// We iterate the blocks starting from the lower row
	// We MUST draw the blocks in this order, because the image starts drawing from the lower-left corner
	for (int i = getBlocksY(); i > 0; i--) {
		for (int j = 1; j < getBlocksX() + 1; j++) {
			// ----- Block creation (using the position, uv coordiantes and texture) -----

			// We push into the buffer the 4 vertices of the block

			// Normal block
			if (i != 1 && j !=  getBlocksX()) {
				push4Vertices(_surface->_vertexArray,                     // Pointer to the buffer
				              mPosVer,                                    // Position in wich we are storing a vertex
				              _posX,                                      // x
				              _posY,                                      // y
				              mPosZ,                                      // z
				              _surface->_attributes._widthBlock,          // Block width
				              _surface->_attributes._heightBlock,         // Block height
				              _surface->_attributes._width,               // U mapping coordinate
				              _surface->_attributes._height);             // V mapping coordinate
			}

			// The ones of the right column
			if (i != 1 && j ==  getBlocksX()) {
				push4Vertices(_surface->_vertexArray,                     // Pointer to the buffer
				              mPosVer,                                    // Position in wich we are storing a vertex
				              _posX,                                      // x
				              _posY,                                      // y
				              mPosZ,                                      // z
				              _surface->_attributes._widthBlock,          // Block width
				              _surface->_attributes._heightBlock,         // Block height
				              _surface->_attributes._width,               // U mapping coordinate
				              _surface->_attributes._height);             // V mapping coordinate
			}

			// The ones of the upper row
			if (i == 1 && j != getBlocksX()) {
				push4Vertices(_surface->_vertexArray,                     // Pointer to the buffer
				              mPosVer,                                    // Position in wich we are storing a vertex
				              _posX,                                      // x
				              _posY,                                      // y
				              mPosZ,                                      // z
				              _surface->_attributes._widthBlock,          // Block width
				              _surface->_attributes._heightBlock,         // Block height
				              _surface->_attributes._width,               // U mapping coordinate
				              _surface->_attributes._height);             // V mapping coordinate
			}

			// The one of the upper-right corner
			if (i == 1 && j ==  getBlocksX()) {
				push4Vertices(_surface->_vertexArray,                     // Pointer to the buffer
				              mPosVer,                                    // Position in wich we are storing a vertex
				              _posX,                                      // x
				              _posY,                                      // y
				              mPosZ,                                      // z
				              _surface->_attributes._widthBlock,          // Block width
				              _surface->_attributes._heightBlock,         // Block height
				              _surface->_attributes._width,               // U mapping coordinate
				              _surface->_attributes._height);             // V mapping coordinate
			}

			// ----- Advance -----

			// Increase the vertex's position by 4
			mPosVer += 4;

			// ----- Column change -----

			// We point to the next block
			_posX += _surface->_attributes._widthBlock;
		}

		// ----- Row change -----

		// We point to the next block
		_posX = 0;
		_posY -= _surface->_attributes._heightBlock;
	}

	return 1;
}