Example #1
0
/* スプライト描画 */
void SpriteRenderer::ShowSprite(
	TexturePtr texture, int X, int Y, int Width, int Height,
	ArgbColor color, RECT* rect, int CenterX, int CenterY, TransformMatrix* matrix)
{
	if ((!sprite) || (!texture)) return; // ぬるぽは(・∀・)カエレ!!
	RECT defaultRect = {0, 0, Width, Height};
#if defined(_WIN32) && defined(WITH_DIRECTX)
	TransformMatrix defaultMatrix; D3DXMatrixIdentity(&defaultMatrix);
	D3DXMatrixScaling(&defaultMatrix, Geometry::WindowScale(), Geometry::WindowScale(), 0.0f);
	D3DXVECTOR3 Center(CenterX, CenterY, 0);
	D3DXVECTOR3 Pos((float)X, (float)Y, 0);
	sprite->SetTransform(matrix ? matrix : &defaultMatrix);
	sprite->Draw(texture, rect ? rect : &defaultRect, &Center, &Pos, color);
	sprite->Flush();
#else
	const TransformMatrix defaultMatrix = {
		Geometry::WindowScale(), 0,                                                         0, 0,
		0,                       Geometry::WindowScale(),                                   0, 0,
		0,                       0,                                                         1, 0,
		0,                       Geometry::WindowHeight * (1.0f - Geometry::WindowScale()), 0, 1,
	};

	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, Geometry::WindowWidth, 0, Geometry::WindowHeight, 0, 1);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glLoadMatrixf(matrix ? &((*matrix)[0]) : &defaultMatrix[0]);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, texture);
	RECT* txRect = rect ? rect : &defaultRect;

	glBegin(GL_QUADS);
	glColor4d(
		(double)((color & 0x00ff0000) >> 16) / 255.0,
		(double)((color & 0x0000ff00) >>  8) / 255.0,
		(double)((color & 0x000000ff)      ) / 255.0,
		(double)((color & 0xff000000) >> 24) / 255.0);
	const double lpos = (double)txRect->left   / (double)getTextureWidth (nullptr, texture);
	const double rpos = (double)txRect->right  / (double)getTextureWidth (nullptr, texture);
	const double tpos = (double)txRect->top    / (double)getTextureHeight(nullptr, texture);
	const double bpos = (double)txRect->bottom / (double)getTextureHeight(nullptr, texture);
	glTexCoord2d(lpos, bpos); glVertex2i(X         - CenterX, Geometry::WindowHeight - (Y + Height - CenterY));
	glTexCoord2d(rpos, bpos); glVertex2i(X + Width - CenterX, Geometry::WindowHeight - (Y + Height - CenterY));
	glTexCoord2d(rpos, tpos); glVertex2i(X + Width - CenterX, Geometry::WindowHeight - (Y          - CenterY));
	glTexCoord2d(lpos, tpos); glVertex2i(X         - CenterX, Geometry::WindowHeight - (Y          - CenterY));
	glEnd();
	//glFlush(); // ←[20130415]ボトルネックになることが判明。これを外したら26FPSが40FPSまで改善(デバッグビルド)。リリースだと50FPS→60FPS達成。(GeForce GT240で)

	glDisable(GL_TEXTURE_2D);
#endif
}
Example #2
0
    SWIGEXPORT jint JNICALL Java_org_scilab_modules_graphic_1objects_DataLoaderJNI_getTextureWidth(JNIEnv *jenv, jclass jcls, jstring jarg1)
    {
        jint jresult = 0 ;
        char *arg1 = (char *) 0 ;
        int result;

        (void)jenv;
        (void)jcls;
        arg1 = 0;
        if (jarg1)
        {
            arg1 = (char *)(*jenv)->GetStringUTFChars(jenv, jarg1, 0);
            if (!arg1)
            {
                return 0;
            }
        }
        result = (int)getTextureWidth(arg1);
        jresult = (jint)result;
        if (arg1)
        {
            (*jenv)->ReleaseStringUTFChars(jenv, jarg1, (const char *)arg1);
        }
        return jresult;
    }
Example #3
0
SWIGEXPORT jint JNICALL Java_org_scilab_modules_graphic_1objects_DataLoaderJNI_getTextureWidth(JNIEnv *jenv, jclass jcls, jint jarg1) {
  jint jresult = 0 ;
  int arg1 ;
  int result;
  
  (void)jenv;
  (void)jcls;
  arg1 = (int)jarg1; 
  result = (int)getTextureWidth(arg1);
  jresult = (jint)result; 
  return jresult;
}
Example #4
0
void UIFont::initText(void)
{
    // Create the font

    //Check if I have a FilePathAttachment
    const BoostPath* FilePath(FilePathAttachment::getFilePath(UIFontRefPtr(this)));
    if(FilePath != NULL)
    {
        //Create the font from a file
        _face = TextTXFFace::createFromFile(FilePath->string().c_str());
    }
    else
    {
        TextTXFParam param;
        param.size = getGlyphPixelSize();
        param.gap = getGap();
        param.textureWidth = getTextureWidth();

        //Use my Family Field to create font texture
        _face = TextTXFFace::create(getFamily(), static_cast<TextFace::Style>(getStyle()), param);
    }


    TextureObjChunkUnrecPtr TheChunk(TextureObjChunk::create());
    setTexture(TheChunk);

    if (_face != NULL)
    {
        ImageRefPtr image = _face->getTexture();
        getTexture()->setImage(image);
        getTexture()->setWrapS(GL_CLAMP);
        getTexture()->setWrapT(GL_CLAMP);
        //if(getAntiAliasing())
        //{
        getTexture()->setMinFilter(GL_LINEAR_MIPMAP_NEAREST);
        getTexture()->setMagFilter(GL_LINEAR);
        //}
        //else
        //{
        //getTexture()->setMinFilter(GL_NEAREST);
        //getTexture()->setMagFilter(GL_NEAREST);
        //}
        //getTexture()->setEnvMode(GL_MODULATE);
    }

    // We failed to create the font - fallback to the default font
    //if (_face == NULL)
    //{
    //    _face = getStatisticsDefaultFont();
    //    getTexture() = getStatisticsDefaultFontTexture();
    //}

}
Example #5
0
int MatPlotDecomposer::getTextureData(char * id, void ** address, unsigned int * size)
{
    int type = getTextureImageType(id);
    if (type == MATPLOT_INDEX)
    {
        // Indexed colors
        const int h = getTextureHeight(id);
        const int w = getTextureWidth(id);
        const int bsize = w * h * sizeof(int);
        unsigned char * buffer = new unsigned char[bsize];
        fillTextureData(id, buffer, bsize);

        *address = buffer;
        *size = bsize;

        return 1;
    }

    getGraphicObjectProperty(id, __GO_DATA_MODEL_MATPLOT_IMAGE_DATA__, jni_double_vector, address);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_MATPLOT_IMAGE_DATASIZE__, jni_int, (void **)&size);

    return 1;
}
Example #6
0
void Unit::generalBirth(){
	issueStopOrder();
	targetUnit=NULL;
	this->lastWaypointGeneration=-1;
	selected=false;
	selectedScaleX=getTextureWidth()/SelectedFX::textureW;
	selectedScaleY=getTextureHeight()/SelectedFX::textureH;
	maxSpeedFactor=attackSpeedFactor=maxHealthFactor=armorFactor=strengthFactor=1.0f;
	maxHealthIncrease=armorIncrease=strengthIncrease=0;
	p->armyStrength+=this->strengthEstimate();
	p->numCreated++;
	waypoints.clear();
	isDisturbed=0;
	if(typeid(*this)==typeid(Warrior))
		p->numWarriorsCreated++;
	if(typeid(*this)==typeid(WizardUnit))
		p->numWizardsCreated++;
	if(typeid(*this)==typeid(Ogre))
		p->numOgresCreated++;
	if(typeid(*this)==typeid(Archer))
		p->numArchersCreated++;
	if(typeid(*this)==typeid(Knight))
		p->numKnightsCreated++;
}
Example #7
0
int MatPlotDecomposer::fillTextureData(char* id, unsigned char* buffer, int bufferLength)
{
    // Indexed colors
    void * data = NULL;
    char * parentFigure = NULL;
    double * colormap = NULL;
    int colormapSize = 0;
    int * piColormapSize = &colormapSize;
    int datatype = -1;
    int * pidataType = &datatype;
    const int h = getTextureHeight(id);
    const int w = getTextureWidth(id);

    getGraphicObjectProperty(id, __GO_DATA_MODEL_Z__, jni_double_vector, &data);
    getGraphicObjectProperty(id, __GO_DATA_MODEL_MATPLOT_DATA_TYPE__, jni_int, (void**) &pidataType);
    getGraphicObjectProperty(id, __GO_PARENT_FIGURE__, jni_string, (void**) &parentFigure);
    getGraphicObjectProperty(parentFigure, __GO_COLORMAP__, jni_double_vector, (void**) &colormap);
    getGraphicObjectProperty(parentFigure, __GO_COLORMAP_SIZE__, jni_int, (void**) &piColormapSize);

    switch ((DataType)datatype)
    {
    case MATPLOT_HM1_Char :
    case MATPLOT_Char :
    {
        char * index = (char *)data;
        for (int i = 0 ; i < w * h; i++)
        {
            ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false);
        }

        break;
    }
    case MATPLOT_HM1_UChar :
    case MATPLOT_UChar :
    {
        unsigned char * index = (unsigned char *)data;
        for (int i = 0 ; i < w * h; i++)
        {
            ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false);
        }

        break;
    }
    case MATPLOT_Int :
    {
        int * index = (int *)data;
        for (int i = 0 ; i < w * h; i++)
        {
            ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false);
        }

        break;
    }
    case MATPLOT_UInt :
    {
        unsigned int * index = (unsigned int *)data;
        for (int i = 0 ; i < w * h; i++)
        {
            ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false);
        }

        break;
    }
    case MATPLOT_Short :
    {
        short * index = (short *)data;
        for (int i = 0 ; i < w * h; i++)
        {
            ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false);
        }

        break;
    }
    case MATPLOT_UShort :
    {
        unsigned short * index = (unsigned short *)data;
        for (int i = 0 ; i < w * h; i++)
        {
            ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false);
        }

        break;
    }
    case MATPLOT_HM1_Double :
    case MATPLOT_Double :
    {
        double * index = (double *)data;
        for (int i = 0 ; i < w * h ; i++)
        {
            ColorComputer::getDirectByteColor(index[i] - 1, colormap, colormapSize, &buffer[4 * i], false);
        }
        break;
    }
    }

    releaseGraphicObjectProperty(__GO_COLORMAP__, colormap, jni_double_vector, colormapSize);

    return bufferLength;
}
Example #8
0
void MapEditor::loadTexture(int texId, const char *path)
{
    textureList[texId] = LoadTexture(path);
    std::cout<<"WIDTH:"<<getTextureWidth(texId)<<std::endl;

}
	GaussianBlurFilter::GaussianBlurFilter(const TextureFilterBuilder *textureFilterBuilder, GaussianDirection gaussianDirection):
		TextureFilter(textureFilterBuilder),
		gaussianDirection(gaussianDirection),
		blurSize(textureFilterBuilder->getBlurSize()),
		nbTextureFetch(std::ceil(blurSize / 2.0f)),
		textureSize((GaussianDirection::VERTICAL==gaussianDirection) ? getTextureHeight() : getTextureWidth())
	{ //See http://rastergrid.com/blog/2010/09/efficient-gaussian-blur-with-linear-sampling/

		if(blurSize<=1)
		{
			throw std::invalid_argument("Blur size must be greater than one. Value: " + std::to_string(blurSize));
		}else if(blurSize%2==0)
		{
			throw std::invalid_argument("Blur size must be an odd number. Value: " + std::to_string(blurSize));
		}

		std::vector<float> weights = computeWeights();

		std::vector<float> weightsLinearSampling = computeWeightsLinearSampling(weights);
		weightsTab = toShaderVectorValues(weightsLinearSampling);

		std::vector<float> offsetsLinearSampling = computeOffsetsLinearSampling(weights, weightsLinearSampling);
		offsetsTab = toShaderVectorValues(offsetsLinearSampling);
	}