Exemple #1
0
GLCube::GLCube(GLuint texId)
    : m_bOwnsTexture(false), m_nTexID(0)
{
  m_aabb.Min() = Eigen::Vector3d(-0.5,-0.5,-0.5);
  m_aabb.Max() = Eigen::Vector3d(+0.5,+0.5,+0.5);
  SetTexture(texId);
}
bool VImageState::Build(VWindowBase *pOwner, TiXmlElement *pNode, const char *szPath, bool bWrite)
{
  if (!pNode)
    return false;

  // button texture name
  const char *szTexture = XMLHelper::Exchange_String(pNode,"texture",NULL,bWrite);
  if (szTexture) // only assign when defined to preserve normal state
    SetTexture(VGUIManager::LoadTexture(szTexture,szPath));

  // texture coordinates and stretch mode
  float *texCoordData = (float*)(&texCoord.m_vMin);
  XMLHelper::Exchange_Floats(pNode,"texcoords",texCoordData,4,bWrite);
  const char *szStretchMode = XMLHelper::Exchange_String(pNode,"stretchmode",NULL,bWrite);
  if (szStretchMode)
    m_eStretchMode = GetStretchMode(szStretchMode);

  // button color
  XMLHelper::Exchange_Color(pNode,"color",m_iColor,bWrite);
  XMLHelper::Exchange_Transparency(pNode,"transparency",m_eTranspType,bWrite);

  // other states
  bool bFiltering = false;
  XMLHelper::Exchange_Bool(pNode,"filtering",bFiltering,bWrite);
  if (bFiltering)
    m_iAdditionalStateFlags |= RENDERSTATEFLAG_FILTERING;

  // mouse over cursor
  const char *szCursor = XMLHelper::Exchange_String(pNode,"cursor",NULL,bWrite);
  if (szCursor) // only assign when defined to preserve normal state
    m_spCursor = pOwner->GetMenuManager()->LoadCursorResource(szCursor,szPath);

  return true;
}
void Texture_Text::RenderText_Shaded( SDL_Renderer* renderer, const std::string &str )
{
	// Render with a text color
	SDL_Surface* surface = TTF_RenderText_Shaded( textFont, str.c_str(), textColor, backgroundColor );

	SetTexture( renderer, surface );
}
void Texture_Text::RenderText_Blended( SDL_Renderer* renderer, const std::string &str )
{
	// Render with a text color, nicer than TTF_RenderText_Shaded, but slower
	SDL_Surface* surface = TTF_RenderText_Blended( textFont, str.c_str(), textColor );

	SetTexture( renderer, surface );
}
	void CDX9Renderer::FillGradient(const rect& r, cr_float angle, point hotspot, const color& c1, const color& c2, gradient_direction dir)
	{
		quad q((r - hotspot).rotate_to_quad(angle, r.topleft()));

		SetTexture(NULL);

		color vs[4];

		switch (dir) {
		case dir_up:
			SetVertices(vs, c2, c2, c1, c1);
			Quad(r, vs);
			break;
		case dir_down:
			SetVertices(vs, c1, c1, c2, c2);
			Quad(r, vs);
			break;
		case dir_left:
			SetVertices(vs, c2, c1, c2, c1);
			Quad(r, vs);
			break;
		case dir_right:
			SetVertices(vs, c1, c2, c1, c2);
			Quad(r, vs);
			break;
		}
	}
void Texture_Text::RenderText_Solid( SDL_Renderer* renderer, const std::string &str )
{
	// Just render the text ( background will be transparent )
	SDL_Surface* surface = TTF_RenderText_Solid( textFont, str.c_str(), textColor );

	SetTexture( renderer, surface );
}
	void CDX9Renderer::Fill(const rect& r, cr_float angle, point hotspot, const color& c)
	{
		quad q((r - hotspot).rotate_to_quad(angle, r.topleft()));

		SetTexture(NULL);
		Quad(q, c, NULL);
	}
	void CDX9Renderer::FillGradient(const rect& r, const color& c1, const color& c2, gradient_direction dir)
	{
		SetTexture(NULL);

		color vs[4];

		switch (dir) {
		case dir_up:
			SetVertices(vs, c2, c2, c1, c1);
			Quad(r, vs);
			break;
		case dir_down:
			SetVertices(vs, c1, c1, c2, c2);
			Quad(r, vs);
			break;
		case dir_left:
			SetVertices(vs, c2, c1, c2, c1);
			Quad(r, vs);
			break;
		case dir_right:
			SetVertices(vs, c1, c2, c1, c2);
			Quad(r, vs);
			break;
		}
	}
	void CDX9Renderer::Box(const rect& r, cr_float angle, point hotspot, const color& c)
	{
		// No support for textured lines
		SetTexture(NULL);

		quad q((r - hotspot).rotate_to_quad(angle, r.topleft()));

		BeginBatch(batch_linestrip);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		D3DCOLOR color = c.getD3DCOLOR();

		// 4 vertices and use 5th index to repeat first vertex closing the strip as a box
		AddVertex(color, q.tl, 0.0f, 0.0f);
		AddVertex(color, q.tr, 0.0f, 0.0f);
		AddVertex(color, q.br, 0.0f, 0.0f);
		AddVertex(color, q.bl, 0.0f, 0.0f);

		unsigned short index = draw_op->vertex_count;
		AddIndex(index);
		AddIndex(index + 1);
		AddIndex(index + 2);
		AddIndex(index + 3);
		AddIndex(index);

		draw_op->vertex_count += 4;
		draw_op->index_count += 5;
	}
	void CDX9Renderer::Box(const rect& r, const color& c)
	{
		// No support for textured lines
		SetTexture(NULL);

		BeginBatch(batch_linestrip);
		CBatch_Draw* draw_op = reinterpret_cast<CBatch_Draw*>(batch.back());

		D3DCOLOR color = c.getD3DCOLOR();

		// 4 vertices and use 5th index to repeat first vertex closing the strip as a box
		AddVertex(color, r.topleft(), 0.0f, 0.0f);
		AddVertex(color, r.topright(), 0.0f, 0.0f);
		AddVertex(color, r.bottomright(), 0.0f, 0.0f);
		AddVertex(color, r.bottomleft(), 0.0f, 0.0f);

		unsigned short index = draw_op->vertex_count;
		AddIndex(index);
		AddIndex(index + 1);
		AddIndex(index + 2);
		AddIndex(index + 3);
		AddIndex(index);

		draw_op->vertex_count += 4;
		draw_op->index_count += 5;
	}
Exemple #11
0
void Textbox::OnCreate()
{
    myTexture = Scene.Get()->GetAssetManager()->CreateFromMemory<Texture>("");
    UpdateText();
    SetTexture(myTexture);
    GUISprite::OnCreate();
}
void CCryTBRenderer::RenderBatch(Batch* batch)
{
	auto pRenderer = gEnv->pRenderer;
	const float fZ = 1.f;

	SVF_P3F_C4B_T2F* verts = new SVF_P3F_C4B_T2F[batch->vertex_count];

	for (int i = 0; i < batch->vertex_count; ++i)
	{
		auto batchVtx = batch->vertex[i];
		verts[i].xyz = Vec3{ batchVtx.x, batchVtx.y, fZ };
		verts[i].st = Vec2{ batchVtx.u, batchVtx.v };
		verts[i].color.dcolor = batchVtx.col;
	}

	auto btmp = static_cast<CCryTBBitmap*>(batch->bitmap);

	pRenderer->Set2DMode(true,
		pRenderer->GetWidth(), pRenderer->GetHeight());

	pRenderer->SetTexture(btmp->GetCryTexture()->GetTextureID());

	pRenderer->SetColorOp(eCO_MODULATE, eCO_MODULATE, DEF_TEXARG0, DEF_TEXARG0);
	pRenderer->SetState(GS_NODEPTHTEST);

	pRenderer->DrawDynVB(verts, nullptr,
		batch->vertex_count, 0,
		prtTriangleList);

	pRenderer->Set2DMode(false, 0, 0);

	SAFE_DELETE_ARRAY(verts);
}
Exemple #13
0
void Test28()
{
	InitWindow();

	static Bitmap bm;
	bm.w = bm.h = 256; bm.form = BMFORMAT_B8G8R8A8; bm.pal = 0;
	bm.pix = (uchar*)malloc(bm.w * bm.h * 4);
	memset(bm.pix, 127, bm.w * bm.h * 4);

	static int px = 61, py = 89, vx = 2, vy = -3;
	*(uint*)(bm.pix + (py*bm.w + px) * 4) = -1;

	static texture t = CreateTexture(&bm, 1);
	while(!appexit)
	{
		px += vx; if(px < 0 || px >= 256) {px -= vx; vx = -vx;}
		py += vy; if(py < 0 || py >= 256) {py -= vy; vy = -vy;}
		*(uint*)(bm.pix + (py*bm.w + px) * 4) = -1;
		renderer->UpdateTexture(t, &bm);
		BeginDrawing();
		InitRectDrawing();
		SetTexture(0, t);
		DrawRect(0, 0, 256, 256, -1);
		EndDrawing();
		HandleWindow();
	}
}
Exemple #14
0
void PolyDrawArgs::SetTexture(FTexture *texture, uint32_t translationID, bool forcePal)
{
	if (translationID != 0xffffffff && translationID != 0)
	{
		FRemapTable *table = TranslationToTable(translationID);
		if (table != nullptr && !table->Inactive)
		{
			if (PolyRenderer::Instance()->RenderTarget->IsBgra())
				mTranslation = (uint8_t*)table->Palette;
			else
				mTranslation = table->Remap;

			mTextureWidth = texture->GetWidth();
			mTextureHeight = texture->GetHeight();
			mTexturePixels = texture->GetPixels();
			return;
		}
	}
	
	if (forcePal)
	{
		mTextureWidth = texture->GetWidth();
		mTextureHeight = texture->GetHeight();
		mTexturePixels = texture->GetPixels();
	}
	else
	{
		SetTexture(texture);
	}
}
Exemple #15
0
void RectDrawArgs::SetTexture(FSoftwareTexture *texture, uint32_t translationID, FRenderStyle style)
{
	// Alphatexture overrides translations.
	if (translationID != 0xffffffff && translationID != 0 && !(style.Flags & STYLEF_RedIsAlpha))
	{
		FRemapTable *table = TranslationToTable(translationID);
		if (table != nullptr && !table->Inactive)
		{
			if (PolyTriangleDrawer::IsBgra())
				mTranslation = (uint8_t*)table->Palette;
			else
				mTranslation = table->Remap;

			mTexture = texture;
			mTextureWidth = texture->GetWidth();
			mTextureHeight = texture->GetHeight();
			mTexturePixels = texture->GetPixels(style);
			return;
		}
	}

	if (style.Flags & STYLEF_RedIsAlpha)
	{
		mTexture = texture;
		mTextureWidth = texture->GetWidth();
		mTextureHeight = texture->GetHeight();
		mTexturePixels = texture->GetPixels(style);
	}
	else
	{
		SetTexture(texture, style);
	}
}
Exemple #16
0
void RectDrawArgs::SetStyle(const FRenderStyle &renderstyle, double alpha, uint32_t fillcolor, uint32_t translationID, FSoftwareTexture *tex, bool fullbright)
{
	SetTexture(tex, translationID, renderstyle);
	SetColor(0xff000000 | fillcolor, fillcolor >> 24);

	if (renderstyle == LegacyRenderStyles[STYLE_Normal] || (r_drawfuzz == 0 && renderstyle == LegacyRenderStyles[STYLE_OptFuzzy]))
	{
		SetStyle(Translation() ? TriBlendMode::NormalTranslated : TriBlendMode::Normal, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_Add] && fullbright && alpha == 1.0 && !Translation())
	{
		SetStyle(TriBlendMode::SrcColor, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_SoulTrans])
	{
		SetStyle(Translation() ? TriBlendMode::AddTranslated : TriBlendMode::Add, transsouls);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_Fuzzy] || (r_drawfuzz == 1 && renderstyle == LegacyRenderStyles[STYLE_OptFuzzy]))
	{
		SetColor(0xff000000, 0);
		SetStyle(TriBlendMode::Fuzzy);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_Shadow] || (r_drawfuzz == 2 && renderstyle == LegacyRenderStyles[STYLE_OptFuzzy]))
	{
		SetColor(0xff000000, 0);
		SetStyle(Translation() ? TriBlendMode::TranslucentStencilTranslated : TriBlendMode::TranslucentStencil, 1.0 - 160 / 255.0);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_Stencil])
	{
		SetStyle(Translation() ? TriBlendMode::StencilTranslated : TriBlendMode::Stencil, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_Translucent])
	{
		SetStyle(Translation() ? TriBlendMode::TranslucentTranslated : TriBlendMode::Translucent, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_Add])
	{
		SetStyle(Translation() ? TriBlendMode::AddTranslated : TriBlendMode::Add, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_Shaded])
	{
		SetStyle(Translation() ? TriBlendMode::ShadedTranslated : TriBlendMode::Shaded, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_TranslucentStencil])
	{
		SetStyle(Translation() ? TriBlendMode::TranslucentStencilTranslated : TriBlendMode::TranslucentStencil, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_Subtract])
	{
		SetStyle(Translation() ? TriBlendMode::SubtractTranslated : TriBlendMode::Subtract, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_AddStencil])
	{
		SetStyle(Translation() ? TriBlendMode::AddStencilTranslated : TriBlendMode::AddStencil, alpha);
	}
	else if (renderstyle == LegacyRenderStyles[STYLE_AddShaded])
	{
		SetStyle(Translation() ? TriBlendMode::AddShadedTranslated : TriBlendMode::AddShaded, alpha);
	}
}
Exemple #17
0
Bomb::Bomb(const Vector2& vInitialPos) :
	Entity(vInitialPos),
	m_texture("Assets/Projectiles/Bomb.bmp")
{
	SetFrameTimer(2);
	SetTexture(&m_texture, 16);
}
Drawable::Drawable(Rect rect, SDL_Texture* texture, Color color)
	: _isActive(true)
{
	SetRect(rect);
	SetTexture(texture);
	_color = color;
}
Exemple #19
0
//==============================================================================
//
//------------------------------------------------------------------------------
void Sprite3D::draw(const  Renderer* renderer) {
  auto pDevice = renderer->getDevice();
  auto shader = renderer->getShader();

  shader->setVtxShader(_vtxShaderID);
  auto vtxShader = shader->getNowVtxShader();

  UINT nSamplerIndex = shader->getNowPixShader()->_constTable->GetSamplerIndex("TexSamp0");
  if(UINT_MAX != nSamplerIndex) {
    pDevice->SetTexture(nSamplerIndex,renderer->getTexture()->getTexture(_textureID));
  }

  // 色
  vtxShader->_constTable->SetFloatArray(pDevice,"gMaterial",_color,4);

  Matrix norMtx;
  D3DXMatrixInverse(&norMtx,nullptr,&getWorldMtx());
  D3DXMatrixTranspose(&norMtx,&norMtx);
  vtxShader->_constTable->SetMatrix(pDevice,"gNorWorld",&norMtx);

  Matrix wvp = getWorldMtx() * renderer->getCamera()->getViewMtx() * renderer->getProjMtx();
  vtxShader->_constTable->SetMatrix(pDevice,"gWorld",&getWorldMtx());
  vtxShader->_constTable->SetMatrix(pDevice,"gWVP",&wvp);

  // デクラレーション設定
  pDevice->SetVertexDeclaration(_p3DDec);

  // 頂点送信
  pDevice->SetStreamSource(0,_vtxBuff,0,sizeof(VERTEX_3D));

  // 描画
  pDevice->DrawPrimitive(D3DPT_TRIANGLESTRIP,0,2);
}
Exemple #20
0
//-----------------------------------------------------------------------------
// Name: CParticleSystem()
// Desc:
//-----------------------------------------------------------------------------
CParticleSystem::CParticleSystem()
{
    m_dwVBOffset       = 0;    // Gives the offset of the vertex buffer chunk that's currently being filled
    m_dwFlush          = 512;  // Number of point sprites to load before sending them to hardware(512 = 2048 divided into 4 chunks)
    m_dwDiscard        = 2048; // Max number of point sprites the vertex buffer can load until we are forced to discard and start over
    m_pActiveList      = NULL; // Head node of point sprites that are active
    m_pFreeList        = NULL; // Head node of point sprites that are inactive and waiting to be recycled.
    m_pPlanes          = NULL;
	m_dwActiveCount    = 0;
	m_fCurrentTime     = 0.0f;
	m_fLastUpdate      = 0.0f;
    m_pVB              = NULL; // The vertex buffer where point sprites are to be stored
    m_chTexFile        = NULL;
    m_ptexParticle     = NULL;
    m_dwMaxParticles   = 1;
    m_dwNumToRelease   = 1;
    m_fReleaseInterval = 1.0f;
    m_fLifeCycle       = 1.0f;
    m_fSize            = 1.0f;
    m_clrColor         = D3DXCOLOR(1.0f,1.0f,1.0f,1.0f);
    m_vPosition        = ArnVec3(0.0f,0.0f,0.0f);
    m_vVelocity        = ArnVec3(0.0f,0.0f,0.0f);
    m_vGravity         = ArnVec3(0.0f,0.0f,0.0f);
    m_vWind            = ArnVec3(0.0f,0.0f,0.0f);
    m_bAirResistence   = true;
    m_fVelocityVar     = 1.0f;	
    
    SetTexture("particle.bmp");
}
Sprite::Sprite(const char * sceneName, const char * path, float x, float y)
	: Component(sceneName)
	, x(x), y(y)
	, isVisible(true)
	, texture(nullptr)
	, srcRect(nullptr)
	, isFlippedH(false)
	, isFlippedV(false)
{
	srcRect = new Rekt();
	dstRect->x = x;
	dstRect->y = y;

	if (path != nullptr)
	{
		SetTexture(path);
		if (texture)
		{
			int* w = new int();
			int* h = new int();

			SDL_QueryTexture(texture, 0, 0, w, h);

			dstRect->w = (const float)*w;
			dstRect->h = (const float)*h;

			delete w;
			delete h;
		}
	}
}
Exemple #22
0
void Test22()
{
	int curgrp = 0; char tb[512];

	printf("Use LTTT? ");
	int uselt = atoi(fgets(tb, 511, stdin));

	LoadBCP("data.bcp");
	InitWindow();
	InitFont();

	if(uselt) LoadLTTT("Maps\\Map_Textures\\128_4Peaks.lttt");
	LoadMapTextures();

	//MessageBox(hWindow, "Terrain textures loaded.", appName, 64);
	printf("%u groups:\n", maptexgroup.len);
	for(int i = 0; i < maptexgroup.len; i++)
	{
		MapTextureGroup *g = maptexgroup.getpnt(i);
		printf(" * %s\n", g->name);
		printf("   %u textures:\n", g->tex->len);
		for(int j = 0; j < g->tex->len; j++)
			printf("    - %u\n", g->tex->getpnt(j)->id);
	}
	//texture t = GetTexture("Warrior Kings Game Set\\Textures\\Tavern.pcx");
	while(!appexit)
	{
		BeginDrawing();
		InitRectDrawing();

		//SetTexture(0, maptexgroup.getpnt(0)->tex->getpnt(0)->t);
		//SetTexture(0, t);
		//DrawRect(0, 0, 256, 256, -1);

		MapTextureGroup *g = maptexgroup.getpnt(curgrp);
		sprintf(tb, "%s (%u/%u)", g->name, curgrp, maptexgroup.len);
		DrawFont(0, 0, tb);
		for(int i = 0; i < g->tex->len; i++)
		{
			MapTexture *t = g->tex->getpnt(i);
			SetTexture(0, t->t);
			DrawRect(i * 65, 32, 64, 64, -1, t->x / 256.f, t->y / 256.f, t->w / 256.f, t->h / 256.f);
			sprintf(tb, "%u", t->id);
			DrawFont(i * 65, 96, tb);
		}

		if(keypressed[VK_LEFT])
		{
			if(curgrp > 0) curgrp--;
		}
		if(keypressed[VK_RIGHT])
		{
			if(curgrp < maptexgroup.len-1) curgrp++;
		}

		EndDrawing();
		HandleWindow();
	}
}
Pill::Pill(Field* field, Vector2 position, SDL_Color color) : Item(field, position)
{
	SDL_Texture* texture = FWApplication::GetInstance()->LoadTexture("pill.png");
	SDL_SetTextureColorMod(texture, color.r, color.g, color.b);

	SetTexture(texture);
	SetSize(50, 50);
}
Exemple #24
0
ScrollBarHorizontal::ScrollBarHorizontal(Window *parent)
  : ScrollBarBase(parent)
{
	_btnBox->SetTexture("ui/scroll_hor", true);
	_btnUpLeft->SetTexture("ui/scroll_left", true);
	_btnDownRight->SetTexture("ui/scroll_right", true);
	SetTexture("ui/scroll_back_hor", true);
}
Exemple #25
0
ScrollBarVertical::ScrollBarVertical(Window *parent)
  : ScrollBarBase(parent)
{
	_btnBox->SetTexture("ui/scroll_vert", true);
	_btnUpLeft->SetTexture("ui/scroll_up", true);
	_btnDownRight->SetTexture("ui/scroll_down", true);
	SetTexture("ui/scroll_back_vert", true);
}
Exemple #26
0
void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool resetRect)
{
    if (texture && texture->This)
    {
        CSFML_CALL(sprite, SetTexture(*texture->This, resetRect == sfTrue));
        sprite->Texture = texture;
    }
}
Exemple #27
0
void RendererCommon::ApplySamplerState(const uint SamplerStage,
                                       const SSamplerState& SamplerState) {
  SetTexture(SamplerStage, SamplerState.m_Texture);
  SetAddressing(SamplerStage, SamplerState.m_AddressU, SamplerState.m_AddressV);
  SetMinMipFilters(SamplerStage, SamplerState.m_MinFilter,
                   SamplerState.m_MipFilter);
  SetMagFilter(SamplerStage, SamplerState.m_MagFilter);
}
Exemple #28
0
TextButton::TextButton(Window *parent)
  : ButtonBase(parent)
  , _fontTexture((size_t) -1)
  , _drawShadow(true)
{
	SetTexture(NULL, false);
	OnChangeState(stateNormal);
}
Exemple #29
0
Button::Button(Window *parent)
  : ButtonBase(parent)
  , _font(GetManager()->GetTextureManager()->FindSprite("font_small"))
{
	SetTexture("ui/button", true);
	SetDrawBorder(false);
	OnChangeState(stateNormal);
}
void RenderSprite(uint textureId, svertex_t* verticesSprite, uint* indicesSprite, uint numIndices)
{
	SetTexture(textureId);
	glVertexAttribPointer(currentShader->vars[SHADER_ATT_VERTEX], 2, GL_SHORT, GL_FALSE,  sizeof(svertex_t), verticesSprite->pos);
	glVertexAttribPointer(currentShader->vars[SHADER_ATT_UV], 2, GL_FLOAT, GL_FALSE,  sizeof(svertex_t), verticesSprite->text);			
	//TODO CHANGE glDrawElements
	glDrawElements (GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT,indicesSprite); //numIndices==6
}