Esempio n. 1
0
void material3DS::loadTexture(std::string filename, int chunkType, bool stereoMode){

	std::transform(filename.begin(),filename.end(),filename.begin(),tolower);
	
	if((filename.find(".tga") == std::string::npos) && (filename.find(".bmp") == std::string::npos)){
		std::cout<<"[3DS] WARNING: Could not load map '"<<filename<<"'\n[3DS] WARNING: (texture must be TGA or BMP)"<<std::endl;
		return;        
	}

	GLuint newTextureId;
	glGenTextures(1, &newTextureId);

	if(filename.find(".tga") != std::string::npos){
		textureTGA newTexture(filename, newTextureId, stereoMode);
	}
	else if(filename.find(".bmp") != std::string::npos){
		textureBMP newTexture(filename, newTextureId, stereoMode);
	}
	else return;

	switch(chunkType){
		case CHUNK_TEXTURE_MAP:	
			m_textureMapId = newTextureId; 
			m_hasTextureMap = true; 
			break;
		case CHUNK_BUMP_MAP: 
			m_bumpMapId = newTextureId; 
			m_hasBumpMap = true; 
			break;
	}

}
Esempio n. 2
0
void Task::initializeGlobals(const char *savefile)
{
    running = true;

    screen = newTexture(SCREEN_WIDTH, SCREEN_HEIGHT);
    nglSetBuffer(screen->bitmap);

    has_touchpad = is_touchpad;
    keys_inverted = is_classic;

    background = newTexture(SCREEN_WIDTH, SCREEN_HEIGHT);
    background_saved = false;

    Task::savefile = savefile;
}
Esempio n. 3
0
void CBitmapFont::makeFont(){
	//gcon.printf("makeFont() : making font %s_%f\n", name.c_str(), getFontSize());
	file = CFTLibrary::getSingleton()->loadFontFace(name, &mFace);
	//size = 17;
	if(FT_Set_Char_Size(
              mFace,    /* handle to face object           */
              0,       /* char_width in 1/64th of points  */
              (S32)getFontSize()*64,   /* char_height in 1/64th of points */
              0,     /* horizontal device resolution    */
			  0 ))   /* vertical device resolution      */ {

		throw CException("Failed to set char size.");
	}

	if(FT_Select_Charmap( mFace, ft_encoding_unicode ))
		throw CException("Non unicode font");

	mGlyphs.resize(mFace->num_glyphs, 0);

	mTextureSize = 256;

	pen.x = pen.y = 0;

	curTex = newTexture();

	for(S32 i = 0 ; i < 130 ; ++i){
		generateGlyph(i);	
	}

	//CFTLibrary::getSingleton()->doneFontFace(&mFace);
}
	AbstractImage* GuillotineTextureAtlas::ResizeImage(AbstractImage* oldImage, const Vector2ui& size) const
	{
		std::unique_ptr<Texture> newTexture(new Texture);
		if (newTexture->Create(ImageType_2D, PixelFormatType_A8, size.x, size.y, 1))
		{
			if (oldImage)
			{
				Texture* oldTexture = static_cast<Texture*>(oldImage);

				// Copie des anciennes données
				///TODO: Copie de texture à texture
				Image image;
				if (!oldTexture->Download(&image))
				{
					NazaraError("Failed to download old texture");
					return nullptr;
				}

				if (!newTexture->Update(image, Rectui(0, 0, image.GetWidth(), image.GetHeight())))
				{
					NazaraError("Failed to update texture");
					return nullptr;
				}
			}

			return newTexture.release();
		}
		else
		{
			// Si on arrive ici c'est que la taille demandée est trop grande pour la carte graphique
			// ou que nous manquons de mémoire
			return nullptr;
		}
	}
Esempio n. 5
0
GLuint ObjectManager::obtainTexture( const void* key )
{
    const GLuint id = getTexture( key );
    if( id != INVALID )
        return id;
    return newTexture( key );
}
Esempio n. 6
0
std::shared_ptr<sf::Texture> TextureManager::getTexture(std::string fileName,
   int x, int y, int width, int height)
{
   // See if we already loaded this file
   if(images.count(fileName) == 0)
   {
      // Load it
      images[fileName] = std::unique_ptr<sf::Image>(new sf::Image);
      if(!images[fileName]->loadFromFile(fileName))
      {
         return nullptr;
      }
   }

   // See if we already loaded this texture
   std::vector<sf::IntRect> &textCuts = textureCuts[fileName];
   sf::IntRect desiredCut(x, y, width, height);
   for(unsigned int i = 0; i < textCuts.size(); i++)
   {
      if(textCuts[i] == desiredCut)
      {
         return textures[fileName][i];
      }
   }

   // Haven't loaded it yet, let's load it now
   textureCuts[fileName].push_back(desiredCut);
   std::shared_ptr<sf::Texture> newTexture(new sf::Texture);
   newTexture->loadFromImage(*images[fileName], desiredCut);
   textures[fileName].push_back(newTexture);
   return newTexture;
}
Esempio n. 7
0
void material3DS::loadTexture(std::string filename, int chunkType){

	string lowerCaseStr = filename;
	std::transform(lowerCaseStr.begin(),lowerCaseStr.end(),lowerCaseStr.begin(), ::tolower);

	if((lowerCaseStr.find(".jpg") == std::string::npos) && (lowerCaseStr.find(".png") == std::string::npos) && (lowerCaseStr.find(".tga") == std::string::npos) && (lowerCaseStr.find(".bmp") == std::string::npos)){
		std::cout<<"[3DS] WARNING: Could not load map '"<<filename<<"'\n[3DS] WARNING: (texture must be TGA, PNG, JPG or BMP)"<<std::endl;
		return;
	}

	GLuint newTextureId;
	glGenTextures(1, &newTextureId);

    texture3DS newTexture(filename, newTextureId);

	switch(chunkType){
		case CHUNK_TEXTURE_MAP:
			m_textureMapId = newTextureId;
			m_hasTextureMap = true;
			break;
		case CHUNK_BUMP_MAP:
			m_bumpMapId = newTextureId;
			m_hasBumpMap = true;
			break;
	}

}
GLuint importTexture(std::string filename) {
    std::transform(filename.begin(),filename.end(),filename.begin(),tolower);

    GLuint newTextureId;
    glGenTextures(1, &newTextureId);

    textureBMP newTexture(filename, newTextureId);

    return newTextureId;
}
Esempio n. 9
0
AS3_Val initializeTexture( void* self, AS3_Val args )
{
	char * name;

	Texture * texture;

	AS3_ArrayValue( args, "StrType", &name );

	texture = newTexture( name );

	return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType", texture, & texture->perspective_dist, &texture->perspectiveLP_dist, &texture->alphaTestRef, &texture->numMipLevels);
}
Esempio n. 10
0
/* TextureXPanel::handleAction
 * Handles the action [id]. Returns true if the action was handled,
 * false otherwise
 *******************************************************************/
bool TextureXPanel::handleAction(string id)
{
	// Don't handle if hidden
	if (!tx_editor->IsShown() || !IsShown())
		return false;

	// Only interested in "txed_" events
	if (!id.StartsWith("txed_"))
		return false;

	// Handle action
	if (id == "txed_new")
		newTexture();
	else if (id == "txed_delete")
		removeTexture();
	else if (id == "txed_new_patch")
		newTextureFromPatch();
	else if (id == "txed_new_file")
		newTextureFromFile();
	else if (id == "txed_up")
		moveUp();
	else if (id == "txed_down")
		moveDown();
	else if (id == "txed_sort")
		sort();
	else if (id == "txed_copy")
		copy();
	else if (id == "txed_cut")
	{
		copy();
		removeTexture();
	}
	else if (id == "txed_paste")
		paste();
	else if (id == "txed_export")
		exportTexture();
	else if (id == "txed_extract")
		extractTexture();
	else if (id == "txed_rename")
		renameTexture();
	else if (id == "txed_rename_each")
		renameTexture(true);
	else if (id == "txed_offsets")
		modifyOffsets();
	else
		return false;	// Not handled here

	return true;
}
Texture *newTextureFromFile(const char *texname,uintf flags)
{	// Search the current texture directory to locate a suitable texture file
	bitmap *bm;
	char flname[1024];
	if (!texname) return NULL;
	if (!texname[0]) return NULL;

	// Look for an already loaded texture with the same name
	fileNameInfo(texname);
	tprintf(flname,sizeof(flname),"%s.%s",fileactualname,fileextension);
	Texture *tex = usedTexture;
	while (tex)
	{	if (txticmp(flname,tex->name)==0)
		{	// Texture already loaded
			tex->refcount++;
			return tex;
		}
		tex = tex->next;
	}

	// Allocate a new texture cell
	tex = newTexture(flname, 0, 0);	// ### This forces the texture to be 2D!!!
	tex->flags &= texture_clearmask;
	tex->flags |= flags;

	if (fileExists(texname))										// Check to see if the path + filename is valid ...
		txtcpy(flname, sizeof(flname), texname);					// if so, load that
	else
		fileFindInPath(flname, sizeof(flname), tex->name, texpath);	// Find the texture with our texture path

	if (!flname[0])													// nothing found ... fail
	{	texturelog->log("*** %s *** Missing texture.  Looked in %s",tex->name,texpath);
		if (!bm_MissingTexture)
		{	bm_MissingTexture = newbitmap("Missing Texture Standin",1,1,bitmap_ARGB32);
			*(uint32 *)(bm_MissingTexture->pixel) = 0xFFFF00FF;		// Purple
		}
		textureFromBitmap(bm_MissingTexture, tex);
		estimatedtexmemused += 4;
	}	else
	{	bm = newbitmap(flname,0);
		textureFromBitmap(bm, tex);
		deleteBitmap(bm);
	}
	if (tex->oemdata)
		texturelog->log("Create %i: %s",tex->texmemused/1024,flname);
	return tex;
}
Esempio n. 12
0
void DevState::draw() {
	clock_t t = clock();
	float elapsed = static_cast<float>(t - timeT) / CLOCKS_PER_SEC;
	++frameCount;
	if (elapsed > OVERLAY_FPS_INTERVAL) {
		OverlayMsg om;
		om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
		om.omh.uiType = OVERLAY_MSGTYPE_FPS;
		om.omh.iLength = sizeof(OverlayMsgFps);
		om.omf.fps = frameCount / elapsed;

		sendMessage(om);

		frameCount = 0;
		timeT = t;
	}

	D3DVIEWPORT9 vp;
	dev->GetViewport(&vp);

	checkMessage(vp.Width, vp.Height);

	if (! a_ucTexture || (uiLeft == uiRight))
		return;

	if (! texTexture) {
		unsigned int l, r, t, b;
		l = uiLeft;
		r = uiRight;
		t = uiTop;
		b = uiBottom;
		newTexture(uiWidth, uiHeight);
		blit(0, 0, uiWidth, uiHeight);

		uiLeft = l;
		uiRight = r;
		uiTop = t;
		uiBottom = b;
		setRect();
	}

	dev->SetTexture(0, texTexture);
	dev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, vertices, sizeof(D3DTLVERTEX));
}
Esempio n. 13
0
bool TextureManager::CacheTexture( string inTextureName, const char* inFileName )
{
	SDL_Texture* texture = IMG_LoadTexture( GraphicsDriver::sInstance->GetRenderer(), inFileName );

	if( texture == nullptr )
	{
		SDL_LogError( SDL_LOG_CATEGORY_ERROR, "Failed to load texture: %s", inFileName );
		return false;
	}

	int w, h;
	SDL_QueryTexture( texture, nullptr, nullptr, &w, &h );

	// Set the blend mode up so we can apply our colors
	SDL_SetTextureBlendMode( texture, SDL_BLENDMODE_BLEND );
	
	TexturePtr newTexture( new Texture( w, h, texture ) );

	mNameToTextureMap[ inTextureName ] = newTexture;

	return true;

}
Texture *newNormalizeCubeMap(int size, float intensity, const char *name)
{	// Create a new Normalizing Cube Map (commonly used in Normal Mapping)
	// Size = Number of pixels in width, height, and depth
	// Intensity = Intensity of lighting.  Ranges from 0 (very little lighting) to 1 (heavy specular effect)
	// Name = the name you want to call this texture (optional)
	Texture *tex = newTexture("Unnamed Cubemap", size, texture_cubemap | texture_manualmip);
	if (name) txtcpy(tex->name,maxtexnamesize,name);

	float vector[3] = {0,0,0};
	intf side, x, y, mip;
	byte *pixels;
	intensity *= 127;

	bitmap *bm = newbitmap("Normalize CubeMap", size, size,bitmap_RGB_32bit);
	pixels = (byte *)bm->pixel;

	mip = 0;
	while (size>0)
	{	float oofsize = 1.0f / (float)size;
		bm->width = size;
		bm->height = size;
		for (side = 0; side < 6; side++)
		{	for (y = 0; y < size; y++)
			{	for (x = 0; x < size; x++)
				{	float s, t, sc, tc, mag;

					s = ((float)x + 0.5f) * oofsize; // / (float)size;
					t = ((float)y + 0.5f) * oofsize; // / (float)size;
					sc = s*2.0f - 1.0f;
					tc = t*2.0f - 1.0f;

					switch (side)
					{	case 0:
							vector[0] = 1.0;
							vector[1] = -tc;
							vector[2] = -sc;
							break;
						case 1:
							vector[0] = -1.0;
							vector[1] = -tc;
							vector[2] = sc;
							break;
						case 2:
							vector[0] = sc;
							vector[1] = 1.0;
							vector[2] = tc;
							break;
						case 3:
							vector[0] = sc;
							vector[1] = -1.0;
							vector[2] = -tc;
							break;
						case 4:
							vector[0] = sc;
							vector[1] = -tc;
							vector[2] = 1.0;
							break;
						case 5:
							vector[0] = -sc;
							vector[1] = -tc;
							vector[2] = -1.0;
							break;
					} // switch size

					mag = 1.0f/(float)sqrt(vector[0]*vector[0] + vector[1]*vector[1] + vector[2]*vector[2]);
					vector[0] *= mag;
					vector[1] *= mag;
					vector[2] *= mag;
					float alpha = intensity * vector[2] * 2;
					if (alpha<0) alpha = 0;
					pixels[4*(y*size+x) + 0] = (byte)alpha;//(128 + (byte)(intensity*vector[2]));	// A	(A taken from Z)
					pixels[4*(y*size+x) + 1] = (128 + (byte)(intensity*vector[0]));	// R
					pixels[4*(y*size+x) + 2] = (128 + (byte)(intensity*vector[1]));	// G
					pixels[4*(y*size+x) + 3] = (128 + (byte)(intensity*vector[2]));	// B
				} // for X
			}	// for Y
			downloadcubemapface(tex, side, bm, mip);
		}	// for side
		size >>= 1;
		mip++;
	}
	tex->mapping = texmapping_default | texmapping_clampUV;
	fcfree(bm);
	return tex;
}
// Internal function - Called to load up a texture map - file is known to exist
Texture *textureFromBitmap(bitmap *loadbm, Texture *tex)
{	bitmap *swizzleBm, *scaleBm, *resizeCanvasSrc;
	bool mustSwizzle = false;
	bool mustScale = false;

	// Step 1: Check for a need to swizzle (if the video card doesn't support this texture mode)
	uintf dataType = loadbm->flags & (bitmap_DataTypeMask | bitmap_DataInfoMask);
	// ### This code is not yet complete, must leave this block with 'swizzleBM' pointing to swizzled bitmap data

	// If Video card only handles 'Power-of-2' texture dimensions
	bool resizeCanvas=false;
	// if (GLESWarnings) //!(videoFeatures & videodriver_nonP2Tex))
	{	uintf newCanvasWidth = loadbm->width;
		uintf newCanvasHeight = loadbm->height;

		if (!isPow2(loadbm->width))
		{	resizeCanvas=true;
			newCanvasWidth=nextPow2(loadbm->width);
		}
		if (!isPow2(loadbm->height))
		{	resizeCanvas=true;
			newCanvasHeight=nextPow2(loadbm->height);
		}
		if (resizeCanvas)
		{	resizeCanvasSrc = loadbm;
			loadbm = newbitmap("resizeCanvasP2Tex",newCanvasWidth,newCanvasHeight,bitmap_ARGB32);
			uintf x,y;
			uint32 *src32 = (uint32 *)resizeCanvasSrc->pixel;
			uint32 *dst32 = (uint32 *)loadbm->pixel;
			for (y=0; y<resizeCanvasSrc->height; y++)
			{	uint32 *src = &src32[y*(resizeCanvasSrc->width)];
				uint32 *dst = &dst32[y*newCanvasWidth];
				for (x=0; x<resizeCanvasSrc->width; x++)
					*dst++ = *src++;
				for (;x<newCanvasWidth; x++)
					*dst++ = 0;
			}
			for (;y<newCanvasHeight; y++)
			{	uint32 *dst = &dst32[y*newCanvasWidth];
				for (x=0; x<newCanvasWidth; x++)
					*dst++=0;
			}
		}

/*		// Work out X scale
		uintf size = 1;
		while (size<=maxtexwidth)
		{	if (newx<=size) break;
			size <<=1;
		}
		if (size>maxtexwidth) size = maxtexwidth;
		newx = size;

		// Work out Y scale
		size = 1;
		while (size<=maxtexheight)
		{	if (newy<=size) break;
			size <<=1;
		}
		if (size>maxtexheight) size = maxtexheight;
		newy = size;
*/
	}

	// Step 2: Check if we need to resize - this may change swizzle mode
	uintf newx = loadbm->width;
	uintf newy = loadbm->height;
	if (newx>maxtexwidth)
		newx = maxtexwidth;
	if (newy>maxtexheight)
		newy = maxtexheight;

	if (newx!=loadbm->width || newy!=loadbm->height)
	{	dataType = bitmap_DataTypeRGB | bitmap_RGB_32bit;
		mustSwizzle = true;
		mustScale = true;
	}

	if (mustSwizzle)
	{	dataType |= loadbm->flags & bitmap_AlphaMask;
		swizzleBm = SwizzleBitmap(loadbm, dataType);
	}	else
		swizzleBm = loadbm;

	if (mustScale)
	{	// Bitmap needs to be resized before hardware will accept it
		scaleBm = scalebitmap(swizzleBm,newx,newy);
	}	else
		scaleBm = swizzleBm;

	// If we don't have a texture provided, create a new one
	if (!tex)
		tex = newTexture(NULL, 0, 0);
	downloadbitmaptex(tex, scaleBm, 0);
	estimatedtexmemused += tex->texmemused;
	if (mustScale)
		deleteBitmap(scaleBm);
	if (mustSwizzle)
		deleteBitmap(swizzleBm);
	if (resizeCanvas)
	{	deleteBitmap(loadbm);
		loadbm = resizeCanvasSrc;
		tex->flags |= texture_canvasSize;
		tex->UVscale.x = (float)loadbm->width / (float)tex->width;
		tex->UVscale.y = (float)loadbm->height/ (float)tex->height;
	}
	return tex;
}
Esempio n. 16
0
void Pipe::checkMessage(unsigned int width, unsigned int height) {
	if (!width || ! height)
		return;

	if (hSocket == INVALID_HANDLE_VALUE) {
		hSocket = CreateFileW(L"\\\\.\\pipe\\MumbleOverlayPipe", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
		if (hSocket == INVALID_HANDLE_VALUE) {
			ods("Pipe: Connection failed");
			return;
		}
		ods("Pipe: Connected");

		uiWidth = 0;
		uiHeight = 0;

		// initially, instantiate and send an OverlayMessage with the current process id
		OverlayMsg om;
		om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
		om.omh.uiType = OVERLAY_MSGTYPE_PID;
		om.omh.iLength = sizeof(OverlayMsgPid);
		om.omp.pid = GetCurrentProcessId();

		if (!sendMessage(om))
			return;

		ods("Pipe: Process ID sent");
	}

	// if the passed width and height do not match the current overlays uiWidth and uiHeight, re-initialize
	if ((uiWidth != width) || (uiHeight != height)) {
		release();

		uiWidth = width;
		uiHeight = height;

		// instantiate and send an initialization-OverlayMessage
		OverlayMsg om;
		om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
		om.omh.uiType = OVERLAY_MSGTYPE_INIT;
		om.omh.iLength = sizeof(OverlayMsgInit);
		om.omi.uiWidth = uiWidth;
		om.omi.uiHeight = uiHeight;

		if (!sendMessage(om))
			return;

		ods("Pipe: SentInitMsg with w h %d %d", uiWidth, uiHeight);
	}

	std::vector<RECT> blits;

	while (1) {
		DWORD dwBytesLeft;
		DWORD dwBytesRead;

		if (! PeekNamedPipe(hSocket, NULL, 0, NULL, &dwBytesLeft, NULL)) {
			ods("Pipe: Could not peek");
			disconnect();
			return;
		}

		if (! dwBytesLeft)
			break;

		if (omMsg.omh.iLength == -1) {
			if (! ReadFile(hSocket, reinterpret_cast<unsigned char *>(omMsg.headerbuffer) + dwAlreadyRead, sizeof(OverlayMsgHeader) - dwAlreadyRead, &dwBytesRead, NULL)) {
				ods("Pipe: Read header fail");
				disconnect();
				return;
			}

			dwBytesLeft -= dwBytesRead;
			dwAlreadyRead += dwBytesRead;

			if (dwAlreadyRead != sizeof(OverlayMsgHeader)) {
				break;
			}

			dwAlreadyRead = 0;

			if (omMsg.omh.uiMagic != OVERLAY_MAGIC_NUMBER) {
				ods("Pipe: Invalid magic number %x", omMsg.omh.uiMagic);
				disconnect();
				return;
			}

			if (static_cast<int>(dwBytesLeft) < omMsg.omh.iLength)
				continue;
		}

		if (! ReadFile(hSocket, reinterpret_cast<unsigned char *>(omMsg.msgbuffer) + dwAlreadyRead, omMsg.omh.iLength - dwAlreadyRead, &dwBytesRead, NULL)) {
			ods("Pipe: Read data fail");
			disconnect();
			return;
		}

		dwAlreadyRead += dwBytesRead;

		if (static_cast<int>(dwBytesLeft) < omMsg.omh.iLength)
			continue;

		dwAlreadyRead = 0;

		switch (omMsg.omh.uiType) {
			case OVERLAY_MSGTYPE_SHMEM: {
					wchar_t memname[2048];
					memname[0] = 0;

					MultiByteToWideChar(CP_UTF8, 0, omMsg.oms.a_cName, omMsg.omh.iLength, memname, 2048);

					release();

					hMemory = CreateFileMappingW(INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, uiWidth * uiHeight * 4, memname);

					if (GetLastError() != ERROR_ALREADY_EXISTS) {
						ods("Pipe: Memory %s(%d) => %ls doesn't exist", omMsg.oms.a_cName, omMsg.omh.iLength, memname);
						if (hMemory) {
							CloseHandle(hMemory);
							hMemory = NULL;
							break;
						}
					}

					if (! hMemory) {
						ods("Pipe: CreateFileMapping failed");
						break;
					}

					a_ucTexture = reinterpret_cast<unsigned char *>(MapViewOfFile(hMemory, FILE_MAP_ALL_ACCESS, 0, 0, 0));

					if (a_ucTexture == NULL) {
						ods("Pipe: Failed to map memory");
						CloseHandle(hMemory);
						hMemory = NULL;
						break;
					}

					MEMORY_BASIC_INFORMATION mbi;
					memset(&mbi, 0, sizeof(mbi));
					if ((VirtualQuery(a_ucTexture, &mbi, sizeof(mbi)) == 0) || (mbi.RegionSize < (uiHeight * uiWidth * 4))) {
						ods("Pipe: Memory too small");
						UnmapViewOfFile(a_ucTexture);
						CloseHandle(hMemory);
						a_ucTexture = NULL;
						hMemory = NULL;
						break;
					}

					OverlayMsg om;
					om.omh.uiMagic = OVERLAY_MAGIC_NUMBER;
					om.omh.uiType = OVERLAY_MSGTYPE_SHMEM;
					om.omh.iLength = 0;

					if (!sendMessage(om))
						return;

					newTexture(uiWidth, uiHeight);
				}
				break;
			case OVERLAY_MSGTYPE_BLIT: {
					RECT r = {
						static_cast<LONG>(omMsg.omb.x),
						static_cast<LONG>(omMsg.omb.y),
						static_cast<LONG>(omMsg.omb.x + omMsg.omb.w),
						static_cast<LONG>(omMsg.omb.y + omMsg.omb.h)
					};

					std::vector<RECT>::iterator i = blits.begin();
					while (i != blits.end()) {
						RECT is;
						if (::IntersectRect(&is, &r, & *i)) {
							::UnionRect(&is, &r, & *i);
							r = is;
							blits.erase(i);
							i = blits.begin();
						} else {
							++i;
						}
					}
					blits.push_back(r);
				}
				break;
			case OVERLAY_MSGTYPE_ACTIVE: {
					uiLeft = omMsg.oma.x;
					uiTop = omMsg.oma.y;
					uiRight = omMsg.oma.x + omMsg.oma.w;
					uiBottom = omMsg.oma.y + omMsg.oma.h;
					if (a_ucTexture) {
						setRect();
						blit(0, 0, uiWidth, uiHeight);
					}
				}
				break;
			default:
				break;
		}
		omMsg.omh.iLength = -1;
	}

	if (!a_ucTexture)
		return;

	for (std::vector<RECT>::iterator i = blits.begin(); i != blits.end(); ++i)
		blit((*i).left, (*i).top, (*i).right - (*i).left, (*i).bottom - (*i).top);
}
Esempio n. 17
0
int main(int argc, char *argv[]){
    FILE *arch;
    char line[100], *word[6];
    int count, x, y;
    //license
    license();
    
    if (argc < 3) { printf("I need the modelname too\n"); exit(1); }
    
    if (argc == 5) {
        printf("I did it\n");
        adjust = atof(argv[4]);
    }
    
    strcpy(modelname,argv[3]);
    
    //access obj file
    arch=fopen(argv[1],"r");
    if(arch==NULL){
        printf("Error: file not found or file unavailable\n\n");
        exit(1);
    }
    else{
        while(!feof(arch)){
            //read line
            fgets(line,100,arch);
            //parse tokens
            for(count=0; count<6; count++){
                word[count]=    count==0 ?    strtok(line," ") :    strtok(NULL," ");
                if(word[count]==NULL){
                    word[count-1]=strtok(word[count-1],"\n");
                    break;
                }
            }
            //process data
            if(word[0]!=NULL){
                if(strcmp(word[0],"v")==0){
                    newVertex(word);
                }
                else if(strcmp(word[0],"vt")==0){
                    newTexture(word);
                }
                else if(strcmp(word[0],"vn")==0){
                    newNormal(word);
                }
                else if(strcmp(word[0],"f")==0){
                    makeFace(word);
                }
                else{
                    //skip
                }
            }
        }
        fclose(arch);
        //save to file
        arch=fopen(argv[2],"w");
        if(arch==NULL){
            printf("Error: File creation unsuccessful\n\n");
        }
        else{
            fprintf(arch,"//Generated through PatchObj v.1.0 by Patricio Figueroa\n\n");
            dataDump(arch);
            fclose(arch);
        }
    }
    printf("Success!\n\n");
    return 0;
}
Esempio n. 18
0
VkeCubeTexture *VkeCubeTexture::List::newTexture(){
	VkeCubeTexture::ID id = nextID();
	return newTexture(id);
}
Esempio n. 19
0
// -----------------------------------------------------------------------------
// TextureXPanel class constructor
// -----------------------------------------------------------------------------
TextureXPanel::TextureXPanel(wxWindow* parent, TextureXEditor& tx_editor) :
	wxPanel{ parent, -1 },
	tx_editor_{ &tx_editor },
	undo_manager_{ tx_editor.getUndoManager() }
{
	// Setup sizer
	wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
	SetSizer(sizer);

	// Add textures list
	wxStaticBox*      frame      = new wxStaticBox(this, -1, "Textures");
	wxStaticBoxSizer* framesizer = new wxStaticBoxSizer(frame, wxVERTICAL);
	wxBoxSizer*       hbox       = new wxBoxSizer(wxHORIZONTAL);
	label_tx_format_             = new wxStaticText(this, -1, "Format:");
	hbox->Add(label_tx_format_, 0, wxALIGN_BOTTOM | wxRIGHT, UI::pad());
	btn_save_ = new SIconButton(this, "save", "Save");
	hbox->AddStretchSpacer();
	hbox->Add(btn_save_, 0, wxEXPAND);
	framesizer->Add(hbox, 0, wxEXPAND | wxLEFT | wxRIGHT, UI::pad());
	list_textures_ = new TextureXListView(this, &texturex_);
	framesizer->Add(list_textures_, 1, wxEXPAND | wxALL, UI::pad());
	sizer->Add(framesizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, UI::pad());

	// Texture list filter
	text_filter_      = new wxTextCtrl(this, -1);
	btn_clear_filter_ = new SIconButton(this, "close", "Clear Filter");
	WxUtils::layoutHorizontally(
		framesizer,
		vector<wxObject*>{ WxUtils::createLabelHBox(this, "Filter:", text_filter_), btn_clear_filter_ },
		wxSizerFlags(0).Expand().Border(wxLEFT | wxRIGHT | wxBOTTOM, UI::pad()),
		0);

	// Add texture operations buttons
	wxGridBagSizer* gbsizer = new wxGridBagSizer(UI::pad(), UI::pad());
	framesizer->Add(gbsizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, UI::pad());
	btn_move_up_        = new SIconButton(this, "up", "Move Up");
	btn_move_down_      = new SIconButton(this, "down", "Move Down");
	btn_new_texture_    = new SIconButton(this, "tex_new", "New");
	btn_remove_texture_ = new SIconButton(this, "tex_delete", "Remove");
	btn_new_from_patch_ = new SIconButton(this, "tex_newpatch", "New from Patch");
	btn_new_from_file_  = new SIconButton(this, "tex_newfile", "New from File");
	gbsizer->Add(btn_new_texture_, { 0, 0 }, { 1, 1 });
	gbsizer->Add(btn_new_from_patch_, { 0, 1 }, { 1, 1 });
	gbsizer->Add(btn_new_from_file_, { 0, 2 }, { 1, 1 });
	gbsizer->Add(btn_remove_texture_, { 0, 3 }, { 1, 1 });
	gbsizer->Add(btn_move_up_, { 0, 4 }, { 1, 1 });
	gbsizer->Add(btn_move_down_, { 0, 5 }, { 1, 1 });

	// Bind events
	list_textures_->Bind(wxEVT_LIST_ITEM_SELECTED, &TextureXPanel::onTextureListSelect, this);
	list_textures_->Bind(wxEVT_LIST_ITEM_RIGHT_CLICK, &TextureXPanel::onTextureListRightClick, this);
	list_textures_->Bind(wxEVT_KEY_DOWN, &TextureXPanel::onTextureListKeyDown, this);
	btn_new_texture_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { newTexture(); });
	btn_new_from_patch_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { newTextureFromPatch(); });
	btn_new_from_file_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { newTextureFromFile(); });
	btn_remove_texture_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { removeTexture(); });
	btn_move_up_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { moveUp(); });
	btn_move_down_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { moveDown(); });
	btn_save_->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { tx_editor_->saveChanges(); });
	Bind(wxEVT_SHOW, [&](wxShowEvent&) { tx_editor_->updateMenuStatus(); });
	text_filter_->Bind(wxEVT_TEXT, &TextureXPanel::onTextFilterChanged, this);
	btn_clear_filter_->Bind(wxEVT_BUTTON, &TextureXPanel::onBtnClearFitler, this);
}
Esempio n. 20
0
MenuTask::MenuTask()
{
     menu_with_selection = newTexture(menu.width, menu.height);
}
Esempio n. 21
0
/* TextureXPanel::onTextureListKeyDown
 * Called when a key is pressed in the texture list
 *******************************************************************/
void TextureXPanel::onTextureListKeyDown(wxKeyEvent& e)
{
	// Check if keypress matches any keybinds
	wxArrayString binds = KeyBind::getBinds(KeyBind::asKeyPress(e.GetKeyCode(), e.GetModifiers()));

	// Go through matching binds
	for (unsigned a = 0; a < binds.size(); a++)
	{
		string name = binds[a];

		// Copy
		if (name == "copy")
		{
			copy();
			return;
		}

		// Cut
		else if (name == "cut")
		{
			copy();
			removeTexture();
			return;
		}

		// Paste
		else if (name == "paste")
		{
			paste();
			return;
		}

		// Move texture up
		else if (name == "txed_tex_up")
		{
			moveUp();
			return;
		}

		// Move texture down
		else if (name == "txed_tex_down")
		{
			moveDown();
			return;
		}

		// New texture
		else if (name == "txed_tex_new")
		{
			newTexture();
			return;
		}

		// New texture from patch
		else if (name == "txed_tex_new_patch")
		{
			newTextureFromPatch();
			return;
		}

		// New texture from file
		else if (name == "txed_tex_new_file")
		{
			newTextureFromFile();
			return;
		}

		// Delete texture
		else if (name == "txed_tex_delete")
		{
			removeTexture();
			return;
		}
	}

	// Not handled here, send off to be handled by a parent window
	e.Skip();
}
Esempio n. 22
0
HelpTask::HelpTask()
{
    background = newTexture(background_width, background_height, 0, false);
}
	// ----------------------------------------------------------------------------------------------------------------
    // ----------------------------------------------------------------------------------------------------------------
	ProgrammaticTexture2DPtr createProgrammaticTexture2D(const std::string& name, unsigned int width, unsigned int height, TextureInMemoryColorspace fmt, Texture::buffer_type_ptr data)
	{
		ProgrammaticTexture2DPtr newTexture( new ProgrammaticTexture2D(name, width, height, fmt, data) );
		return newTexture;
	}
Esempio n. 24
0
void terrainInit(const char *texture_path)
{
    terrain_current = loadTextureFromFile(texture_path);
    if(!terrain_current)
        terrain_current = &terrain; //Use default, included texture
    else
        puts("External texture loaded!");

    int fields_x = 16;
    int fields_y = 16;
    int field_width = terrain_current->width / fields_x;
    int field_height = terrain_current->height / fields_y;

    //Give grass and leaves color
    const RGB green = { 0.5f, 0.8f, 0.3f };
    makeColor(green, *terrain_current, 0, 0, field_width, field_height);
    makeColor(green, *terrain_current, 5 * field_width, 3 * field_height, field_width, field_height);
    makeColor(green, *terrain_current, 4 * field_width, 3 * field_height, field_width, field_height);

    //Also redstone
    drawTexture(*terrain_current, *terrain_current, 4 * field_width, 10 * field_height, field_width, field_height, 4 * field_width, 11 * field_height, field_width, field_height);
    const RGB red = { 0.9f, 0.1f, 0.1f };
    makeColor(red, *terrain_current, 4 * field_width, 11 * field_height, field_width, field_height);

    //And redstone switches
    drawTexture(*terrain_current, *terrain_current, 0 * field_width, 6 * field_height, field_width, field_height, 0 * field_width, 7 * field_height, field_width, field_height);
    const RGB red_tint = { 1.0f, 0.8f, 0.8f };
    makeColor(red_tint, *terrain_current, 0 * field_width, 7 * field_height, field_width, field_height);

    if(terrain_current->width == 256 && terrain_current->height == 256)
        terrain_resized = terrain_current;
    else
        terrain_resized = resizeTexture(*terrain_current, 256, 256);

    for(int y = 0; y < fields_y; y++)
        for(int x = 0; x < fields_x; x++)
        {
            //+1 and -2 to work around GLFix inaccuracies resulting in rounding errors
            TerrainAtlasEntry tea = terrain_atlas[x][y] = {textureArea(x * field_width + 1, y * field_height + 1, field_width - 2, field_height - 2),
                                                            textureArea(x * 16, y * 16, 16, 16) };

            BLOCK_TEXTURE bt = texture_atlas[y][x];
            if(bt.sides == 0)
                continue;

            if(bt.sides & BLOCK_BOTTOM_BIT)
                block_textures[bt.block][BLOCK_BOTTOM] = tea;
            if(bt.sides & BLOCK_TOP_BIT)
                block_textures[bt.block][BLOCK_TOP] = tea;
            if(bt.sides & BLOCK_LEFT_BIT)
                block_textures[bt.block][BLOCK_LEFT] = tea;
            if(bt.sides & BLOCK_RIGHT_BIT)
                block_textures[bt.block][BLOCK_RIGHT] = tea;
            if(bt.sides & BLOCK_FRONT_BIT)
                block_textures[bt.block][BLOCK_FRONT] = tea;
            if(bt.sides & BLOCK_BACK_BIT)
                block_textures[bt.block][BLOCK_BACK] = tea;
        }

    //Slight hack, you can't assign a texture to multiple blocks
    block_textures[BLOCK_GRASS][BLOCK_BOTTOM] = block_textures[BLOCK_DIRT][BLOCK_BOTTOM];

    //Prerender four times the same texture to speed up drawing, see terrain.h
    const BLOCK_TEXTURE quad_textures[] = { ALL(BLOCK_DIRT), SID(BLOCK_GRASS), TOP(BLOCK_GRASS), ALL(BLOCK_STONE), ALL(BLOCK_SAND), SID(BLOCK_WOOD), ALL(BLOCK_PLANKS_NORMAL), ALL(BLOCK_LEAVES) };
    terrain_quad = newTexture(field_width * 2 * (sizeof(quad_textures)/sizeof(*quad_textures)), field_height * 2);

    for(BLOCK b = 0; b <= BLOCK_NORMAL_LAST; b++)
        for(uint8_t s = 0; s <= BLOCK_SIDE_LAST; s++)
            quad_block_textures[b][s].has_quad = false;

    unsigned int x = 0;
    for(BLOCK_TEXTURE bt : quad_textures)
    {
        TextureAtlasEntry *tae = nullptr;

        if(bt.sides & BLOCK_BOTTOM_BIT)
            tae = &block_textures[bt.block][BLOCK_BOTTOM].current;
        if(bt.sides & BLOCK_TOP_BIT)
            tae = &block_textures[bt.block][BLOCK_TOP].current;
        if(bt.sides & BLOCK_LEFT_BIT)
            tae = &block_textures[bt.block][BLOCK_LEFT].current;
        if(bt.sides & BLOCK_RIGHT_BIT)
            tae = &block_textures[bt.block][BLOCK_RIGHT].current;
        if(bt.sides & BLOCK_FRONT_BIT)
            tae = &block_textures[bt.block][BLOCK_FRONT].current;
        if(bt.sides & BLOCK_BACK_BIT)
            tae = &block_textures[bt.block][BLOCK_BACK].current;

        if(!tae)
        {
            printf("Block %d has no texture!\n", bt.block);
            continue;
        }

        //- 1 to reverse the workaround above. Yes, I hate myself for this.
        drawTexture(*terrain_current, *terrain_quad, tae->left - 1, tae->top - 1, field_width, field_height, x, 0, field_width, field_height);
        drawTexture(*terrain_current, *terrain_quad, tae->left - 1, tae->top - 1, field_width, field_height, x + field_width, 0, field_width, field_height);
        drawTexture(*terrain_current, *terrain_quad, tae->left - 1, tae->top - 1, field_width, field_height, x+ field_width, field_height, field_width, field_height);
        drawTexture(*terrain_current, *terrain_quad, tae->left - 1, tae->top - 1, field_width, field_height, x, field_height, field_width, field_height);

        //Get an average color of the block
        RGB sum;
        for(unsigned int tex_x = tae->left - 1; tex_x <= tae->right; ++tex_x)
            for(unsigned int tex_y = tae->top - 1; tex_y <= tae->bottom; ++tex_y)
            {
                RGB rgb = rgbColor(terrain_current->bitmap[tex_x + tex_y*terrain_current->width]);
                sum.r += rgb.r;
                sum.g += rgb.g;
                sum.b += rgb.b;
            }

        int pixels = field_width * field_height;
        sum.r /= pixels;
        sum.g /= pixels;
        sum.b /= pixels;

        const COLOR darker = colorRGB(sum.r / GLFix(1.5f), sum.g / GLFix(1.5f), sum.b / GLFix(1.5f));

        //And add the workaround here again..
        TerrainQuadEntry tqe = { true, textureArea(x + 1, 1, field_width * 2 - 2, field_height * 2 - 2), colorRGB(sum), darker };

        if(bt.sides & BLOCK_BOTTOM_BIT)
            quad_block_textures[bt.block][BLOCK_BOTTOM] = tqe;
        if(bt.sides & BLOCK_TOP_BIT)
            quad_block_textures[bt.block][BLOCK_TOP] = tqe;
        if(bt.sides & BLOCK_LEFT_BIT)
            quad_block_textures[bt.block][BLOCK_LEFT] = tqe;
        if(bt.sides & BLOCK_RIGHT_BIT)
            quad_block_textures[bt.block][BLOCK_RIGHT] = tqe;
        if(bt.sides & BLOCK_FRONT_BIT)
            quad_block_textures[bt.block][BLOCK_FRONT] = tqe;
        if(bt.sides & BLOCK_BACK_BIT)
            quad_block_textures[bt.block][BLOCK_BACK] = tqe;

        x += field_width * 2;
    }

    //Part 2 of the hack above
    quad_block_textures[BLOCK_GRASS][BLOCK_BOTTOM] = quad_block_textures[BLOCK_DIRT][BLOCK_BOTTOM];

    if(lcd_type() == SCR_320x240_4)
    {
        greyscaleTexture(*terrain_current);
        greyscaleTexture(*terrain_resized);
        greyscaleTexture(*terrain_quad);
    }

    //Resize the glass texture to 32x32
    const TextureAtlasEntry &glass_tex = block_textures[BLOCK_GLASS][BLOCK_FRONT].current;
    glass_big = newTexture(32, 32);
    drawTexture(*terrain_current, *glass_big, glass_tex.left - 1, glass_tex.top - 1, field_width, field_height, 0, 0, 32, 32);
}
Esempio n. 25
0
/* TextureXPanel::onBtnNewTexture
 * Called when the 'New Texture' button is clicked
 *******************************************************************/
void TextureXPanel::onBtnNewTexture(wxCommandEvent& e)
{
	newTexture();
}
Esempio n. 26
0
// Returns true when all done (sprites will still be placed when false is returned)
static bool PlaceSprites(
	ff::Vector<OptimizedSpriteInfo> &sprites,
	ff::Vector<OptimizedTextureInfo> &textureInfos,
	size_t nStartTexture)
{
	size_t nSpritesDone = 0;

	for (size_t i = 0; i < sprites.Size(); i++)
	{
		OptimizedSpriteInfo &sprite = sprites[i];
		bool bReusePrevious = (i > 0) && !CompareSpriteInfo(sprite, sprites[i - 1]);

		if (bReusePrevious)
		{
			sprite._destTexture = sprites[i - 1]._destTexture;
			sprite._destRect = sprites[i - 1]._destRect;
		}
		else
		{
			if (sprite._destTexture == ff::INVALID_SIZE)
			{
				if (sprite._srcRect.Width()  > s_textureSizeMax ||
					sprite._srcRect.Height() > s_textureSizeMax)
				{
					ff::PointInt size = sprite._srcRect.Size();

					// Oversized, so make a new unshared texture
					sprite._destTexture = textureInfos.Size();
					sprite._destRect.SetRect(ff::PointInt(0, 0), size);

					// texture sizes should be powers of 2 to support compression and mipmaps
					size.x = (int)ff::NearestPowerOfTwo((size_t)size.x);
					size.y = (int)ff::NearestPowerOfTwo((size_t)size.y);

					OptimizedTextureInfo newTexture(size);
					textureInfos.Push(newTexture);
				}
			}

			if (sprite._destTexture == ff::INVALID_SIZE)
			{
				// Look for empty space in an existing texture
				for (size_t h = nStartTexture; h < textureInfos.Size(); h++)
				{
					OptimizedTextureInfo &texture = textureInfos[h];

					if (texture._size.x <= s_textureSizeMax &&
						texture._size.y <= s_textureSizeMax)
					{
						sprite._destRect = texture.FindPlacement(sprite._srcRect.Size());

						if (!sprite._destRect.IsNull())
						{
							verify(texture.PlaceRect(sprite._destRect));
							sprite._destTexture = h;

							break;
						}
					}
				}
			}
		}

		if (sprite._destTexture != ff::INVALID_SIZE)
		{
			nSpritesDone++;
		}
	}

	return nSpritesDone == sprites.Size();
}