Ejemplo n.º 1
0
void GameModel::Init()
{
    Model::Init();

    MeshPlayer();
    ModelSwitch = 0;

    m_gameState = GAME_STATE::IDLE;

    tile = MeshBuilder::GenerateText("tiles", 32, 32);
    tile->textureID[0] = LoadTGA("Image//tile.tga");

    winMesh = MeshBuilder::GenerateText("tiles", 1, 1);
    winMesh->textureID[0] = LoadTGA("Image//win.tga");

    lose = MeshBuilder::GenerateText("tiles", 1, 1);
    lose->textureID[0] = LoadTGA("Image//lose.tga");

    commands = new bool[NUM_COMMANDS];
    for (int count = 0; count < NUM_COMMANDS; ++count)
        commands[count] = false;

    m_mapOffset_x = 0;
    m_mapOffset_y = 0;

    Text = MeshBuilder::GenerateText("text", 16, 16);
    Text->textureID[0] = LoadTGA("Image//ArialBlack.tga");

    floorTiles.push_back(112);
    floorTiles.push_back(309);
    floorTiles.push_back(402);
    floorTiles.push_back(405);

    shadow = MeshBuilder::GenerateQuad("shadow", Color());
    shadow->textureID[0] = LoadTGA("Image//shadow.tga");

    inventory.Init();
    InvenTime = 0;

    PlaceItemState = false;

    AIList.clear();

    win = false;
    touchdoor = false;
    numKey = 0;
    //getKeys();

    goNext = false;

    died = false;

    steps = 0;

    MeshSpeech();

    speech.Textfile("SpeechText//CharacterFile.txt", true);
    speech.Textfile("SpeechText//HowToPlayFile.txt", false);

}
Ejemplo n.º 2
0
void StateCredits::Init()
{
	// Menu in 2D
	theView->LoadOrthoCamera();

	// Create Meshes
	Mesh * newMesh;
	newMesh = MeshBuilder::GenerateText("Source Font", 16, 16);
	newMesh->textureID = LoadTGA("Fonts//source.tga");
	newMesh->alpha = 0.f;
	m_meshList.push_back(newMesh);

	newMesh = MeshBuilder::GenerateQuad("AGDev Menu BG", Color(1.f, 1.f, 1.f), 1.f);
	//newMesh->alpha = 0.f;
	m_meshList.push_back(newMesh);

	newMesh = MeshBuilder::GenerateQuad("Project", Color(0.f, 0.f, 0.f), 1.f);
	newMesh->textureArray[0] = LoadTGA("Images//Project.tga");
	//newMesh->alpha = 0.f;
	m_meshList.push_back(newMesh);

	m_bStartFadeIn = true;
	m_bStartFadeOut = false;
	m_dFadeDelay = 0.0;
}
Ejemplo n.º 3
0
int LoadGLTextures()											// Load Bitmaps And Convert To Textures
{
    int Status=FALSE;											// Status Indicator

    // Load The Bitmap, Check For Errors.
    if (LoadTGA(&texture[0], "Data/Uncompressed.tga") &&
            LoadTGA(&texture[1], "Data/Compressed.tga"))
    {
        Status=TRUE;											// Set The Status To TRUE

        for (int loop=0; loop<2; loop++)						// Loop Through Both Textures
        {
            // Typical Texture Generation Using Data From The TGA ( CHANGE )
            glGenTextures(1, &texture[loop].texID);				// Create The Texture ( CHANGE )
            glBindTexture(GL_TEXTURE_2D, texture[loop].texID);
            glTexImage2D(GL_TEXTURE_2D, 0, texture[loop].bpp / 8, texture[loop].width, texture[loop].height, 0, texture[loop].type, GL_UNSIGNED_BYTE, texture[loop].imageData);
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

            if (texture[loop].imageData)						// If Texture Image Exists ( CHANGE )
            {
                free(texture[loop].imageData);					// Free The Texture Image Memory ( CHANGE )
            }
        }
    }
    return Status;												// Return The Status
}
Ejemplo n.º 4
0
//-------------------------------------------------------------
//- Load
//- Loads an image of any supported image type
//-------------------------------------------------------------
bool CImage::Load(char * szFilename, bool bMipMap)
{
    m_bMipMap = bMipMap;
    m_szFilename = szFilename;
    FILE * f;

    if(!(f = fopen(szFilename, "rb")))
    {
        APP->Log(COLOR_RED, "Could not open %s", szFilename);
        return false;
    }

    fseek(f, 0, SEEK_END);
    int iEnd = ftell(f);
    fseek(f, 0, SEEK_SET);
    int iStart = ftell(f);
    m_uiFileLen = iEnd - iStart;

    m_ucpBuffer = new unsigned char[m_uiFileLen];

    if(!m_ucpBuffer)
    {
        APP->Log(COLOR_RED, "Could not alloc memory for %s", szFilename);
        return false;
    }

    //get data
    if(fread(m_ucpBuffer, 1, m_uiFileLen, f) != m_uiFileLen)
    {
        APP->Log(COLOR_RED, "Could not read from %s", szFilename);
        if(m_ucpBuffer)
            delete [] m_ucpBuffer;
        return false;
    }

    //Check for a valid filetype
    //Windows Bitmap
    if(memcmp(m_ucpBuffer, BMP_HEADER, 2) == 0)
    {
        return LoadBMP();
    }
    //Uncompressed TGA
    if(memcmp(m_ucpBuffer, TGA_UHEADER, 12) == 0)
    {
        return LoadTGA(false);
    }
    //Compressed TGA
    if(memcmp(m_ucpBuffer, TGA_CHEADER, 12) == 0)
    {
        return LoadTGA(true);
    }
    //PCX
    if(m_ucpBuffer[0] == 10)
    {
        return LoadPCX();
    }
    APP->Log(COLOR_RED, "Could not load %s, Invalid filetype", szFilename);
    return false;
}
Ejemplo n.º 5
0
int land_create_texture(land_t *land,land_config_t *config) {
    int i,j,k,l,m,width,height,imagewidth,imageheight,offset;
    unsigned char *data,*image;
    land->material = glGenLists(1); // create material
    glNewList(land->material,GL_COMPILE);
    glMaterialfv(GL_FRONT,GL_AMBIENT,config->ambient);
    glMaterialfv(GL_FRONT,GL_DIFFUSE,config->diffuse);
    glMaterialfv(GL_FRONT,GL_SPECULAR,config->specular);
    glEndList();
    land->texture = (int*)malloc(sizeof(int) * config->num_base * config->num_base + 1);
    if(!land->texture) return 0;
    memset(land->texture,0,sizeof(int) * config->num_base * config->num_base + 1);    
    land->num_texture = config->num_base * config->num_base + 1;
    data = NULL;
    if(strstr(config->detail,".jpg")) data = LoadJPEG(config->detail,&width,&height);
    else if(strstr(config->detail,".tga")) data = LoadTGA(config->detail,&width,&height);
    if(data) {  // create detail texture
        glGenTextures(1,&land->texture[0]);
        glBindTexture(GL_TEXTURE_2D,land->texture[0]);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,config->texture_mode);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,config->texture_mode);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
        glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
        gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,width,height,GL_RGBA,GL_UNSIGNED_BYTE,data);
        free(data);
    }    
    data = NULL;
    if(strstr(config->base,".jpg")) data = LoadJPEG(config->base,&width,&height);
    else if(strstr(config->base,".tga")) data = LoadTGA(config->base,&width,&height);
    if(data) {
        imagewidth = width / config->num_base;
        imageheight = height / config->num_base;
        image = (unsigned char*)malloc(imagewidth * imageheight * 4);
        if(!image) return 0;
        for(j = 0; j < config->num_base; j++)   // create base textures
            for(i = 0; i < config->num_base; i++) {
                for(l = 0, m = 0; l < imageheight; l++) {
                    offset = (width * (imageheight * j + l) + imagewidth * i) * 4;
                    for(k = 0; k < imagewidth * 4; k += 4, m += 4) {
                        image[m + 0] = data[offset + k + 0];
                        image[m + 1] = data[offset + k + 1];
                        image[m + 2] = data[offset + k + 2];
                        image[m + 3] = data[offset + k + 3];
                    }
                }
                glGenTextures(1,&land->texture[config->num_base * j + i + 1]);
                glBindTexture(GL_TEXTURE_2D,land->texture[config->num_base * j + i + 1]);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,config->texture_mode);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,config->texture_mode);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP);
                glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);
                gluBuild2DMipmaps(GL_TEXTURE_2D,GL_RGBA,imagewidth,imageheight,GL_RGBA,GL_UNSIGNED_BYTE,image);
            }
        free(image);
        free(data);
    }
    return 1;
}
Ejemplo n.º 6
0
/************************************************
 *	CCharacterImage Constructor.
 ************************************************/
CCharacterImage::CCharacterImage(void)
{
	FBString		szFullFilePath( mSystem.ApplicationPath, CHARACTER_CTRL_IMAGE );
	FBString		szRegionDropPath( mSystem.ApplicationPath, FINGER_CTRL_IMAGE );
	FBString		szRegionSelPath( mSystem.ApplicationPath, SELECTED_CTRL_IMAGE );

	mCharacterId = LoadTGA( szFullFilePath );
	mRegionDropId = LoadTGA( szRegionDropPath );
	mRegionSelectedId = LoadTGA( szRegionSelPath );
}
Ejemplo n.º 7
0
void SceneWin::Init()
{
	sound.playMusic("Music//Win.mp3");

	// Set background color to dark blue
	glClearColor(0.0f, 0.0f, 0.4f, 0.0f);

	//Enable depth buffer and depth testing
	glEnable(GL_DEPTH_TEST);

	//Default to fill mode
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

	// Generate a default VAO for now
	glGenVertexArrays(1, &m_vertexArrayID);
	glBindVertexArray(m_vertexArrayID);

	m_programID = LoadShaders("Shader//Texture.vertexshader", "Shader//Text.fragmentshader");

	m_parameters[U_MVP] = glGetUniformLocation(m_programID, "MVP");
	m_parameters[U_MODELVIEW] = glGetUniformLocation(m_programID, "MV");
	m_parameters[U_MODELVIEW_INVERSE_TRANSPOSE] = glGetUniformLocation(m_programID, "MV_inverse_transpose");
	m_parameters[U_MATERIAL_AMBIENT] = glGetUniformLocation(m_programID, "material.kAmbient");
	m_parameters[U_MATERIAL_DIFFUSE] = glGetUniformLocation(m_programID, "material.kDiffuse");
	m_parameters[U_MATERIAL_SPECULAR] = glGetUniformLocation(m_programID, "material.kSpecular");
	m_parameters[U_MATERIAL_SHININESS] = glGetUniformLocation(m_programID, "material.kShininess");

	// Get a handle for our "colorTexture" uniform
	m_parameters[U_COLOR_TEXTURE_ENABLED] = glGetUniformLocation(m_programID, "colorTextureEnabled");
	m_parameters[U_COLOR_TEXTURE] = glGetUniformLocation(m_programID, "colorTexture");
	// Get a handle for our "textColor" uniform
	m_parameters[U_TEXT_ENABLED] = glGetUniformLocation(m_programID, "textEnabled");
	m_parameters[U_TEXT_COLOR] = glGetUniformLocation(m_programID, "textColor");

	//Enable blending
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glUseProgram(m_programID);

	//Initialize camera settings
	camera.Init(Vector3(-300, -10, 0), Vector3(0, 0, 0), Vector3(0, 1, 0));

	meshList[GEO_PATH] = MeshBuilder::GenerateQuad("land", Color(1, 1, 1), 14, 13);
	meshList[GEO_PATH]->textureID = LoadTGA("Image//Win_Escape.tga");

	meshList[GEO_TEXT] = MeshBuilder::GenerateText("text", 16, 16);
	meshList[GEO_TEXT]->textureID = LoadTGA("Image//_Font.tga");

	Mtx44 projection;
	projection.SetToPerspective(45.0f, 16.0f / 9.0f, 0.1f, 10000.0f);
	projectionStack.LoadMatrix(projection);
}
Ejemplo n.º 8
0
void SceneCredits::InitMesh()
{
	m_meshList[MESH_TEXT] = MeshBuilder::GenerateText("Calibri font", 16, 16);
	m_meshList[MESH_TEXT]->textureID[0] = LoadTGA("Image\\calibri.tga");

	// Menu
	m_meshList[MESH_RETURN_TO_MAIN_MENU_ON] = MeshBuilder::Generate2DMesh("New game on", Color(1, 1, 1), 0, 0, 1, 1);
	m_meshList[MESH_RETURN_TO_MAIN_MENU_ON]->textureID[0] = LoadTGA("Image\\Menu\\BackToMainMenu_On.tga");

	m_meshList[MESH_RETURN_TO_MAIN_MENU_OFF] = MeshBuilder::Generate2DMesh("New game off", Color(1,1,1), 0, 0, 1, 1);
	m_meshList[MESH_RETURN_TO_MAIN_MENU_OFF]->textureID[0] = LoadTGA("Image\\Menu\\BackToMainMenu_Off.tga");
}
Ejemplo n.º 9
0
//Constructor
GameScene::GameScene() {

	mesh[FONT_CONSOLAS] = MeshBuilder::GenerateText("Text", 16, 16);
	mesh[FONT_CONSOLAS]->textureID = LoadTGA("Image//Fonts//Consolas.tga");

	for (GEOMETRY_TYPE i = SKYBOX_TOP; i < SKYBOX_RIGHT; i = static_cast<GEOMETRY_TYPE>(i + 1)) {
	
		mesh[i] = MeshBuilder::GenerateQuad("Skybox", Colour(1, 1, 1), 1.0f);
		mesh[i]->textureID = LoadTGA("Image//PlaceHolder//PlaceHolder.tga");

	}

}
Ejemplo n.º 10
0
void StateAGDevMenu::Init()
{
	// Menu in 2D
	theView->LoadOrthoCamera();

	// Enable Mouse
	theView->getInputHandler()->setMouseEnabled(true);

	// Create Meshes
	Mesh * newMesh;
	newMesh = MeshBuilder::GenerateText("Source Font", 16, 16);
	newMesh->textureID = LoadTGA("Fonts//source.tga");
	newMesh->alpha = 0.f;
	m_meshList.push_back(newMesh);

	newMesh = MeshBuilder::GenerateQuad("AGDev Menu BG", Color(1.f, 1.f, 1.f), 1.f);
	newMesh->textureArray[0] = LoadTGA("Images//GameMenubg.tga");
	//newMesh->alpha = 0.f;
	m_meshList.push_back(newMesh);

	newMesh = MeshBuilder::GenerateQuad("Project", Color(0.f, 0.f, 0.f), 1.f);
	newMesh->textureArray[0] = LoadTGA("Images//Project.tga");
	//newMesh->alpha = 0.f;
	m_meshList.push_back(newMesh);

	// Create Gui Buttons
	Gui * newGui;
	newGui = new GuiButton("Start Button", "Start", 0.5f, 0.5f, 48.f);
	newGui->setMesh(MeshBuilder::GenerateBoundingBox("StartBB", newGui->getBoundingBox().Max, newGui->getBoundingBox().Min, Color(0.f, 0.f, 1.f)));
	m_guiList.push_back(newGui);

	newGui = new GuiButton("Instructions Button", "Instructions", 0.5f, 0.6f, 48.f);
	newGui->setMesh(MeshBuilder::GenerateBoundingBox("InstructionsBB", newGui->getBoundingBox().Max, newGui->getBoundingBox().Min, Color(0.f, 0.f, 1.f)));
	m_guiList.push_back(newGui);

	newGui = new GuiButton("Highscores Button", "Highscores", 0.5f, 0.7f, 48.f);
	newGui->setMesh(MeshBuilder::GenerateBoundingBox("HighscoreBB", newGui->getBoundingBox().Max, newGui->getBoundingBox().Min, Color(0.f, 0.f, 1.f)));
	m_guiList.push_back(newGui);

	newGui = new GuiButton("Options Button", "Options", 0.5f, 0.8f, 48.f);
	newGui->setMesh(MeshBuilder::GenerateBoundingBox("OptionsBB", newGui->getBoundingBox().Max, newGui->getBoundingBox().Min, Color(0.f, 0.f, 1.f)));
	m_guiList.push_back(newGui);

	newGui = new GuiButton("Credits Button", "Credits", 0.5f, 0.9f, 48.f);
	newGui->setMesh(MeshBuilder::GenerateBoundingBox("CreditsBB", newGui->getBoundingBox().Max, newGui->getBoundingBox().Min, Color(0.f, 0.f, 1.f)));
	m_guiList.push_back(newGui);

	m_bStartFadeIn = true;
	m_bStartFadeOut = false;
	m_dFadeDelay = 0.0;
}
Ejemplo n.º 11
0
// structure pour gérer la texture
bool chargerTextures(int it, char* nom)
{
    // Charger le fichier image tga et mettre les infos dans la structure
    // Hauteur, Largeur, bits par pixel.
    if (LoadTGA(&aTexture[it], nom)) {
        // Créer la texture
        glGenTextures(1, &aTexture[it].texID);

        // Définir comme texture par défaut
        glBindTexture(GL_TEXTURE_2D, aTexture[it].texID);

        // Charger les données de l'image dans OpenGL et dans la mémoire de la carte vidéo
        glTexImage2D(GL_TEXTURE_2D, 0, aTexture[it].bpp / 8, aTexture[it].width, aTexture[it].height, 0, aTexture[it].type, GL_UNSIGNED_BYTE, aTexture[it].imageData);

        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
        glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

        if (aTexture[it].imageData) {
            // libérer la mémoire alloué par le chargeur
            free(aTexture[it].imageData);
        }
        return true;
    }
    else return false;
}
Ejemplo n.º 12
0
void EntityGridObject::addChildren(int y, int x, OBJECT_TYPE childType, GridMap * currMap)
{
	EntityGridObject * newChild = new EntityGridObject(childType);
	newChild->m_iIndexX = x;
	newChild->m_iIndexY = y;

	auto childGC = new GraphicsComponent();
	switch (childType)
	{
		case OBJECT_UNDEFINED:
			currMap->getGridMap()[y][x]->setremoveDoor(true);
			currMap->getGridMap()[y][x]->replaceTile(Grid::TILE_FLOOR, BACKGROUND_TILE);
		break;
		
		case OBJECT_BOX:
			break;
		
		case OBJECT_KEY:
			break;
		
		case OBJECT_SWITCH:
			break;
		
		case OBJECT_DOOR:
			newChild->setToggleable(true);
			childGC->addMesh(MeshBuilder::GenerateQuad("Door", Color(1.f, 0.f, 0.f), 32.f));
			childGC->getMesh()->textureArray[0] = LoadTGA("Images//Tiles//tile109.tga");
			newChild->addComponent(childGC);
			currMap->getGridMap()[y][x]->addGridEntity(newChild);
		break;
	}
	this->m_cChildren.push_back(newChild);
}
Ejemplo n.º 13
0
void EntityGridObject::toggleObject(GridMap * currMap)
{
	if (!m_bToggled)
	{
		m_bToggled = true;
	}
	else
	{
		m_bToggled = false;
	}

	auto graphicsComponent = this->getComponent<GraphicsComponent>();
	Mesh * newMesh;

	switch (this->m_eObjectType)
	{
	case OBJECT_BOX:
		break;
	case OBJECT_KEY:
		break;
	case OBJECT_SWITCH:
		delete graphicsComponent->getMesh();
		graphicsComponent->setMesh(MeshBuilder::GenerateQuad("Activated", Color(0.f, 0.f, 0.f), 16.f));
		graphicsComponent->getMesh()->textureArray[0] = LoadTGA("Images//Tiles//tile_switch_activate.tga");
		graphicsComponent->getMesh()->alpha = 1.f;
		break;
	case OBJECT_DOOR:
		SoundManager::playSound("Sounds//lever.wav", false);
		SoundManager::playSound("Sounds//opendoor.wav", false);
		currMap->getGridMap()[this->m_iIndexY][this->m_iIndexX]->setremoveDoor(true);
		currMap->getGridMap()[this->m_iIndexY][this->m_iIndexX]->replaceTile(Grid::TILE_FLOOR,BACKGROUND_TILE);
		currMap->getGridMap()[this->m_iIndexY][this->m_iIndexX]->deleteEntity();
		break;
	}
}
Ejemplo n.º 14
0
bool CBomsSet::LoadBoms(int BomsNum)
{
	Texture LoadBomTexture;
	char BomsFileName[64]={0};
	sprintf(BomsFileName,"Data/Boms/Bom%d.tga",BomsNum);
	FILE	*m_Filefighter;
	if ((m_Filefighter=fopen(BomsFileName,"rb"))==NULL)
		return false;
	if (LoadTGA(&LoadBomTexture, BomsFileName))
	{
		glGenTextures(1, &LoadBomTexture.texID);
		glBindTexture(GL_TEXTURE_2D, LoadBomTexture.texID);
		glTexImage2D(GL_TEXTURE_2D, 0, LoadBomTexture.bpp / 8, LoadBomTexture.width, LoadBomTexture.height, 0, LoadBomTexture.type, GL_UNSIGNED_BYTE, LoadBomTexture.imageData);
		Pnum=LoadBomTexture.texID;
		if(m_IsSupportFBO)
		{
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
		}
		else
		{
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
			glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
		}
		if (LoadBomTexture.imageData)						// If Texture Image Exists ( CHANGE )
		{
			free(LoadBomTexture.imageData);					// Free The Texture Image Memory ( CHANGE )
		}
		return true;

	}
	return false;
}
Ejemplo n.º 15
0
RawImage* ImageFactory::loadTGA(const char* filename)
{
	TextureInfo tex;
	LoadTGA(&tex, filename);
	
	return new RawImage(tex.width, tex.height, tex.type == GL_RGBA, tex.imageData);
}
Ejemplo n.º 16
0
 /**
  * ファイルロード[拡張子自動判別]
  * @param filepath  ファイルフルパス 
  * @retval true 成功
  * @retval false 失敗
  */
 bool Load(const char* filename)
 {
     bool result = false;
     m_image.Clear();
     std::string path(filename);
     std::string::size_type pos = path.rfind('.');
     if (pos != std::string::npos)
     {
         const std::string ext = make_lowercase(path.substr(pos+1));
         if (ext == "png")
         {
             result = LoadPNG(path);
         }
         else if (ext == "jpg" || ext == "jpeg")
         {
             result = LoadJPG(path);
         }
         else if (ext == "tga")
         {
             result = LoadTGA(path);
         }
         else if (ext == "hdr")
         {
             result = LoadHDR(path);
         }
         else if (ext == "exr" || ext == "EXR")
         {
             result = LoadEXR(path);
         }
     }
     return result;
 }
Ejemplo n.º 17
0
//Load - load a texture from a file
bool IMAGE::Load(char * filename)
{
	//Clear the data if already used
	if(data)
		delete [] data;
	data=NULL;
	bpp=0;
	width=0;
	height=0;
	format=0;

	int filenameLength=strlen(filename);

	if(	strncmp((filename+filenameLength-3), "BMP", 3)==0 ||
		strncmp((filename+filenameLength-3), "bmp", 3)==0)
		return LoadBMP(filename);
	
	if(	strncmp((filename+filenameLength-3), "PCX", 3)==0 ||
		strncmp((filename+filenameLength-3), "pcx", 3)==0)
		return LoadPCX(filename);
	
	if(	strncmp((filename+filenameLength-3), "TGA", 3)==0 ||
		strncmp((filename+filenameLength-3), "tga", 3)==0)
		return LoadTGA(filename);

	errorLog.OutputError("%s does not end in \".tga\", \".bmp\" or \"pcx\"", filename);
	return false;
}
Ejemplo n.º 18
0
//Load an image from a file
bool IMAGE::Load(char * filename)
{
	//Clear the member variables if already used
	bpp=0;
	width=height=0;
	stride=0;
	format=0;

	if(data)
		delete []  data;
	data=NULL;

	paletted=false;
	paletteBpp=0;
	paletteFormat=0;
	if(palette)
		delete [] palette;
	palette=NULL;

	//Call the correct loading function based on the filename
	int filenameLength=strlen(filename);

	if(	strncmp(filename+filenameLength-3, "BMP", 3)==0 ||
		strncmp(filename+filenameLength-3, "bmp", 3)==0)
		return LoadBMP(filename);

	if(	strncmp(filename+filenameLength-3, "TGA", 3)==0 ||
		strncmp(filename+filenameLength-3, "tga", 3)==0)
		return LoadTGA(filename);

	LOG::Instance()->OutputError("%s does not end with \"bmp\" or \"tga\"", filename);
	return false;
}
Ejemplo n.º 19
0
void R_LoadSkys (void)
{
    int     i;
    FILE    *f;
    char    name[64];

    for (i=0 ; i<6 ; i++)
    {
        GL_Bind (SKY_TEX + i);
        sprintf (name, "gfx/env/bkgtst%s.tga", suf[i]);
        COM_FOpenFile (name, &f);
        if (!f)
        {
            Con_Printf ("Couldn't load %s\n", name);
            continue;
        }
        LoadTGA (f);
//      LoadPCX (f);

        glTexImage2DHelper (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, targa_rgba);
//      glTexImage2DHelper (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pcx_rgb);

        free (targa_rgba);
//      free (pcx_rgb);

        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    }
}
Ejemplo n.º 20
0
SpriteAnimation* GameObject::generateSpriteMesh()
{
	SpriteAnimation *sa;
	sa = dynamic_cast<SpriteAnimation*>(MeshBuilder::GenerateSpriteAnimation(SpriteName, SpriteRow, SpriteCol, 1.f));
	sa->textureID[0] = LoadTGA(Sprite_texture_file_path);
	return sa;
}
Ejemplo n.º 21
0
Renderer::ITexture2D *loadTGATexture(Renderer::IRenderer &renderer, const char *filename)
{
	Texture texture;
	Renderer::ITexture2D *texture2D = nullptr;
	if (LoadTGA(&texture, (char*)filename))
	{
		if (24 == texture.bpp)
		{
			// Create the texture instance
			unsigned char *temp = new unsigned char[texture.width * texture.height * 4];
			unsigned char *imageCurrent = texture.imageData;
			unsigned char *tempCurrent = temp;
			for (unsigned int i = 0; i < texture.width * texture.height; ++i)
			{
				tempCurrent[0] = imageCurrent[0];
				tempCurrent[1] = imageCurrent[1];
				tempCurrent[2] = imageCurrent[2];
				tempCurrent[3] = 255;
				imageCurrent += 3;
				tempCurrent += 4;
			}
			texture2D = renderer.createTexture2D(texture.width, texture.height, Renderer::TextureFormat::R8G8B8A8, temp, Renderer::TextureFlag::MIPMAPS);
			delete [] temp;
		}
		else
		{
			// Create the texture instance
			texture2D = renderer.createTexture2D(texture.width, texture.height, Renderer::TextureFormat::R8G8B8A8, texture.imageData, Renderer::TextureFlag::MIPMAPS);
		}
		delete [] texture.imageData;
	}
	return texture2D;
}
Ejemplo n.º 22
0
void Font::LoadFontTexture(const char *fileName)
{
  TGAImageRec *tempTexture;
  GLuint type;

  //Load Image
  tempTexture = LoadTGA(fileName);
  //Is it valid?
  if(tempTexture) {
    //Alpha channel?
    if(tempTexture->bpp == 24)
      type = GL_RGB;
    else
      type = GL_RGBA;

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glGenTextures(1, &FontTexture);
    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

    glBindTexture(GL_TEXTURE_2D, FontTexture);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

    gluBuild2DMipmaps(GL_TEXTURE_2D, type, tempTexture->sizeX,
                      tempTexture->sizeY, type, GL_UNSIGNED_BYTE,
                      tempTexture->data);
    free(tempTexture->data);
    free(tempTexture);
  }
}
Ejemplo n.º 23
0
void R_LoadSkys (void)
{
	int	i, mark;
	FILE	*f;
	char	name[64], texname[20];

	for (i = 0; i < 6; i++)
	{
		q_snprintf (name, sizeof(name), "gfx/env/bkgtst%s.tga", suf[i]);
		FS_OpenFile (name, &f, false);
		if (!f)
		{
			Con_Printf ("Couldn't load %s\n", name);
			continue;
		}

		mark = Hunk_LowMark();
		LoadTGA (f);
	//	LoadPCX (f);

		q_snprintf (texname, sizeof(texname), "skybox%i", i);
		sky_tex[i] = GL_LoadTexture(texname, 256, 256, targa_rgba, false, false, 0, true);
		Hunk_FreeToLowMark(mark);

		glTexParameterf_fp(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, gl_filter_max);
		glTexParameterf_fp(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, gl_filter_max);
	}
}
Ejemplo n.º 24
0
Surface::Surface( const IDataStream& Stream, ESurfaceFileType FileType )
    :	m_Width( 0 )
    ,	m_Height( 0 )
    ,	m_Stride( 0 )
    ,	m_Padding( 0 )
#if BUILD_WINDOWS_NO_SDL
    ,	m_hDC( NULL )
    ,	m_BMP( NULL )
    ,	m_OldBMP( NULL )
#endif
    ,	m_pPixels( NULL )
    ,	m_BitmapInfo()
    ,	m_ViewportLeft( 0 )
    ,	m_ViewportTop( 0 )
    ,	m_ViewportRight( 0 )
    ,	m_ViewportBottom( 0 )
{
    // Load depending on extension
    if( FileType == ESFT_BMP )
    {
        LoadBMP( Stream );
    }
    else if( FileType == ESFT_TGA )
    {
        LoadTGA( Stream );
    }
    else
    {
        WARNDESC( "Unknown file type constructing Surface." );
    }
}
BOOL ReadImage(CImage* pcImage, char* szFilename, EImageType eType)
{
	if (eType == IT_Unknown)
	{
		eType = GuessImageType(szFilename);
	}

	//Oi! Check to make sure none of the below expect an initialised image.
	switch (eType)
	{
		case IT_BMP:
		case IT_EMF:
		case IT_GIF:
		case IT_ICO:
		case IT_JPG:
		case IT_WMF:
			// uses OLE and IPicture to load these image formats.
			return (LoadPictureIPicture(pcImage, szFilename));
		case IT_TGA:
			return (LoadTGA(pcImage, szFilename)); // uses NeHe TGA routines.
		case IT_PNG:
			return (LoadPNG(pcImage, szFilename));
		case IT_RAD:
			return (LoadRAD(pcImage, szFilename)); // uses a text-format RAW descriptor (RAD) file to load a raw file.
		case IT_RAW:
			return (LoadRAW(pcImage, szFilename)); // special case assuming an initialised image.
	}
	return FALSE;
}
Ejemplo n.º 26
0
/** 载入TGA文件并创建纹理 */
bool TGALoad::Load(const char* fileName)
{
	if(!LoadTGA(fileName))
	{
		MessageBox(NULL,TEXT("载入TGA文件失败!"),TEXT("错误"),MB_OK);
		exit(0);
	}
	/** 生成纹理对象名称 */
	glGenTextures(1, &ID);
   
    /** 创建纹理对象 */
    glBindTexture(GL_TEXTURE_2D, ID);
	
	/** 控制滤波 */
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
   
	/** 创建纹理 */
   	gluBuild2DMipmaps(GL_TEXTURE_2D, type, imageWidth,
	                  imageHeight, type, GL_UNSIGNED_BYTE,
	                  image);
   return true;
}
Ejemplo n.º 27
0
static void Load() {
  screen[0] = NewBitmap(WIDTH * 2, HEIGHT * 2, DEPTH, FALSE);
  screen[1] = NewBitmap(WIDTH * 2, HEIGHT * 2, DEPTH, FALSE);

  texture = LoadTGA("data/texture-16-1.tga", PM_CMAP, MEMF_PUBLIC);
  uvmap = ReadFile("data/uvmap.bin", MEMF_PUBLIC);
}
Ejemplo n.º 28
0
bool CreateGLTexture(const char *name, GLuint & TexID )
{
	LoadTGA(name);


	// Typical Texture Generation Using Data From The TGA ( CHANGE )
	glGenTextures(1, &TexID);				// Create The Texture ( CHANGE )
	glBindTexture(GL_TEXTURE_2D, TexID);


	//  My replacement, need to allocate enough storage to create mipmaps
	glTexStorage2D(GL_TEXTURE_2D, 8, texture_bpp/8, texture_width, texture_height);
	glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texture_width, texture_height, texture_type, GL_UNSIGNED_BYTE, texture_imageData);

	//glTexImage2D(GL_TEXTURE_2D, 0, texture_bpp / 8, texture_width, texture_height, 0, texture_type, GL_UNSIGNED_BYTE, texture_imageData);
	glGenerateMipmap(GL_TEXTURE_2D);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

	GLenum errors = glGetError();

	if(errors != GL_NO_ERROR) {
		return false;
	}

	if (texture_imageData)						// If Texture Image Exists ( CHANGE )
	{
		free(texture_imageData);					// Free The Texture Image Memory ( CHANGE )
	}



	return false;
}
Ejemplo n.º 29
0
/*
==============
Load32BitImage

Any of the return pointers can be NULL if you don't want them.
==============
*/
void Load32BitImage(const char *name, unsigned **pixels, int *width, int *height)
{
	char            ext[128];
	byte           *palette;
	byte           *pixels8;
	byte           *pixels32;
	int             size;
	int             i;
	int             v;

	ExtractFileExtension(name, ext);
	if(!Q_stricmp(ext, "tga"))
	{
		LoadTGA(name, (byte **) pixels, width, height);
	}
	else
	{
		Load256Image(name, &pixels8, &palette, width, height);
		if(!pixels)
		{
			return;
		}
		size = *width * *height;
		pixels32 = safe_malloc(size * 4);
		*pixels = (unsigned *)pixels32;
		for(i = 0; i < size; i++)
		{
			v = pixels8[i];
			pixels32[i * 4 + 0] = palette[v * 3 + 0];
			pixels32[i * 4 + 1] = palette[v * 3 + 1];
			pixels32[i * 4 + 2] = palette[v * 3 + 2];
			pixels32[i * 4 + 3] = 0xff;
		}
	}
}
Ejemplo n.º 30
0
void
R_LoadSkys ( void )
{
	int	i;
	QFile	*f;
	byte	*skyimage = NULL;
	char	name[64];

	if (!r_sky->value)
		return;

	for (i=0 ; i<6 ; i++) {
		GL_Bind (SKY_TEX + i);
		snprintf(name, sizeof(name), "env/%s%s.tga",
//		snprintf(name, sizeof(name), "env/%s%s.pcx",
				r_skyname->string, suf[i]);
		COM_FOpenFile (name, &f);
		if (!f)
		{
			Con_DPrintf ("R_LoadSkys: Couldn't load %s\n", name);
			continue;
		}
		LoadTGA (f, &skyimage);
//		LoadPCX (f, &skyimage);

		glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, skyimage);
//		glTexImage2D (GL_TEXTURE_2D, 0, gl_solid_format, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, pcx_rgb);

//		free (targa_rgba);
		free (skyimage);

		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	}
}