示例#1
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoad(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	ilResetRead();
	ILenum sourceType = ilDetermineType(sourceFN);
	if (!ilLoad(sourceType, sourceFN)) {
		printf("test_ilLoad: Failed to load %S\n", sourceFN);
		++errors;
		return;
	}
	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (!ilSaveImage(targetFN)) {
		printf("test_ilLoad: Failed to save " PathCharMod "\n", targetFN);
		++errors;
	}
	testHeap();
	ilDeleteImage(handle);
}
示例#2
0
void TextField::updateTexture()
{
	glDeleteTextures(1, &m_texture_id);
	
	glGenTextures(1, &m_texture_id);
	glBindTexture(GL_TEXTURE_2D, m_texture_id);

	ilBindImage(m_font_id);

	int bpp = ilGetInteger(IL_IMAGE_BPP);

	m_image_id = ilGenImage();
	ilBindImage(m_image_id);

	m_texture_width = (int)ceil(m_char_width) * m_text.length();
	m_texture_height = (int)ceil(m_char_height);

	ilTexImage(m_texture_width, m_texture_height, 1, bpp, IL_RGBA, IL_UNSIGNED_BYTE, NULL);

	for(unsigned int i = 0; i < m_text.length(); i++)
	{
		blit(m_text[i], i, 0);
	}

	ilBindImage(m_image_id);

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

	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_texture_width, m_texture_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, ilGetData());

	ilDeleteImage(m_image_id);
	
	m_dirty = false;
}
示例#3
0
void ofxTexture::DrawString(string text, ofxBitmapFont* font, ofRectangle dest_rect, unsigned char font_size)
{
    if(m_Locked) return;
    // TODO: implement draw text with boundary
    float scale;
    if(font_size == 0)
    {
        scale = 1.0f;
    }
    else
    {
        scale = (float)font_size/font->GetFontSize();
    }
    ofVec2f cursor(dest_rect.x, dest_rect.y);
    ilDisable(IL_BLIT_BLEND);
    for (int i = 0; i < text.size(); i++)
    {
        ofVec2f draw_region = scale*font->GetRect(text[i]);
        ILuint character_image = font->GetImageId(text[i]);
        ILuint dummy = ilGenImage();
        ilBindImage(dummy);
        ilCopyImage(character_image);
        iluScale(draw_region.x, draw_region.y, 1);
        ilBindImage(m_ImageId);
        ilBlit(dummy, cursor.x, cursor.y, 0, 0, 0, 0, draw_region.x, draw_region.y, 1);
        ilDeleteImage(dummy);
        cursor.x += draw_region.x;
    }
    ilEnable(IL_BLIT_BLEND);

}
示例#4
0
TextureLoader::TextureLoader(const char* filename)
{
	data = NULL;

	textureID = ilGenImage();
	ilBindImage(textureID);

	ilLoadImage(filename);


	isSRGB = false;

	width = ilGetInteger(IL_IMAGE_WIDTH);
	height = ilGetInteger(IL_IMAGE_HEIGHT);
	totalSize = ilGetInteger(IL_IMAGE_SIZE_OF_DATA);
	bpp = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL);
	format = ilGetInteger(IL_IMAGE_FORMAT);
	type = ilGetInteger(IL_IMAGE_TYPE);

	if (format == IL_RGBA || format == IL_BGRA || format == IL_LUMINANCE_ALPHA)
		hasAlpha = true;
	else hasAlpha = false;

	LoadData(format, type);
}
示例#5
0
void Skybox::LoadTextures()
{
    glGenTextures(1, &texture_);
    glBindTexture(GL_TEXTURE_CUBE_MAP, texture_);
    std::string names[] = { "./Textures/Skybox/x_pos.png",
                            "./Textures/Skybox/y_pos.png",
                            "./Textures/Skybox/z_pos.png",
                            "./Textures/Skybox/x_neg.png",
                            "./Textures/Skybox/y_neg.png",
                            "./Textures/Skybox/z_neg.png" };
    GLenum target[] = { GL_TEXTURE_CUBE_MAP_POSITIVE_X,
                        GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
                        GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
                        GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
                        GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
                        GL_TEXTURE_CUBE_MAP_NEGATIVE_Z };
    for (int i = 0; i < 6; i++)
    {
        ILuint imageId = ilGenImage();

        ilBindImage(imageId);
        std::wstring temp = std::wstring(names[i].begin(), names[i].end());
        ILboolean success = ilLoadImage(temp.c_str());
        if (!success)
        {
            std::cerr << "Error while loading the texture file: " << names[i] << std::endl;
        }

        int width, height, bytePerPixel;
        width = ilGetInteger(IL_IMAGE_WIDTH);
        height = ilGetInteger(IL_IMAGE_HEIGHT);
        bytePerPixel = ilGetInteger(IL_IMAGE_BPP);
        GLuint format;
        switch (bytePerPixel)
        {
        case 1:
            format = GL_R;
            break;
        case 2:
            format = GL_RG;
            break;
        case 3:
            format = GL_RGB;
            break;
        case 4:
            format = GL_RGBA;
            break;
        default:
            format = GL_RGBA;
            break;
        }
        glTexImage2D(target[i], 0, format, width, height, 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
        ilDeleteImage(imageId);
    }
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
}
示例#6
0
void QTWindow::saveImage(const char * outputFilename, BYTE * imgData, int width, int height)
{
	ILuint imageID = ilGenImage();
	ilBindImage(imageID);
	ilTexImage(width, height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, imgData);
  	ilEnable(IL_FILE_OVERWRITE);
	ilSave(IL_JPG, outputFilename);
}
void TileStorage::CompressTile(uint64_t uid)
{
  uint8_t * m0;
  uint8_t * m1;
  uint8_t * m2;
  uint8_t * m3;
  uint8_t * dataptr = m_tiles[uid];
  uint8_t * compressedmipmaps = new uint8_t[680];
  if ( !dataptr )
  {
    delete [] compressedmipmaps;
    throw InvalidTileDataPointerException();
    
  }
  uint32_t s;
  uint32_t s2 = 0;
  ILuint mip1 = ilGenImage();
  ilBindImage(mip1);
  ilTexImage(32,32,1,4,IL_RGBA,IL_UNSIGNED_BYTE,dataptr);
  /*std::stringstream ss;
  ss << "Tile" << uid << ".png";
  ilSaveImage(ss.str().c_str());*/
  m0 = ilCompressDXT(ilGetData(),32,32,1,IL_DXT1,&s);
  memcpy(&compressedmipmaps[s2],m0,s);
  s2 += s;
  iluScale(16,16,1);
  m1 = ilCompressDXT(ilGetData(),16,16,1,IL_DXT1,&s);
  memcpy(&compressedmipmaps[s2],m1,s);
  s2 += s;
  iluScale(8,8,1);
  m2 = ilCompressDXT(ilGetData(),8,8,1,IL_DXT1,&s);
  memcpy(&compressedmipmaps[s2],m2,s);
  s2 += s;
  iluScale(4,4,1);
  m3 = ilCompressDXT(ilGetData(),4,4,1,IL_DXT1,&s);
  memcpy(&compressedmipmaps[s2],m3,s);
  s2 += s;
  ilDeleteImage(mip1);
  
  /*squish::CompressImage(dataptr,32,32,m0,squish::kDxt1);
  squish::CompressImage(dataptr,16,16,m1,squish::kDxt1);
  squish::CompressImage(dataptr,8,8,m2,squish::kDxt1);
  squish::CompressImage(dataptr,4,4,m3,squish::kDxt1);*/
  
  
  
  
  free(m0);
  free(m1);
  free(m2);
  free(m3);
  
  m_tiles_compressed[uid] = compressedmipmaps;
  //std::cout << "Tile " << uid << " compressed!" << std::endl;
  
}
示例#8
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoadFuncs(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	FILE* f = _wfopen(sourceFN, L"rb");
	bool loaded = false;

	if (f != NULL) {
		fseek(f, 0, SEEK_END);
		myDataSize = ftell(f);
		if (myDataSize > 0) {
			fseek(f, 0, SEEK_SET);
			myData = new BYTE[myDataSize];
			size_t read = fread(myData, 1, myDataSize, f);
			myReadPos = 0;
			if (read == myDataSize) {
				//loaded = ilLoadL(IL_TYPE_UNKNOWN, lump, read);
				ilSetRead(myOpenProc, myCloseProc, myEofProc, myGetcProc, myReadProc, mySeekProc, myTellProc);
				loaded = ilLoadFuncs(IL_TYPE_UNKNOWN);
				if (!loaded) {
					printf("test_ilLoadFuncs: Failed to load " PathCharMod "\n", sourceFN);
					++errors;
				}
			} else {
				printf("test_ilLoadFuncs: Failed to read " PathCharMod "\n", sourceFN);
				++errors;
			}
			delete myData;
		}
		fclose(f);
	} else {
		printf("test_ilLoadFuncs: Failed to open %S\n", sourceFN);
		++errors;
	}

	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (loaded)
		if(!ilSaveImage(targetFN)) {
			printf("Failed to save " PathCharMod " after ilLoadFuncs\n", targetFN);
			++errors;
		}
	testHeap();
	ilDeleteImage(handle);
}
void FractureBox::LoadFractureMap(const char *filename, bool bolden)
{
    if(mFracTexID)
        ilDeleteImage(mFracTexID);
    if(mFracTexScaleID)
        ilDeleteImage(mFracTexScaleID);
    mFracTexID = ilGenImage();
    ilBindImage(mFracTexID);

    if(!ilLoadImage(filename))
    {
        std::cout << "Error loading " << filename << std::endl;
        return;
    }
    if(!ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE))
    {
        std::cout << "Error converting image " << filename << std::endl;
        return;
    }

    ILinfo imgInfo;
    iluGetImageInfo(&imgInfo);
    //if(imgInfo.Origin == IL_ORIGIN_UPPER_LEFT)
    if(imgInfo.Origin == IL_ORIGIN_LOWER_LEFT)
        iluFlipImage();
    if(bolden)
        boldenLines();

    //Now create the scaled version of the image
    mFracTexScaleID = ilGenImage();
    ilBindImage(mFracTexScaleID);
    ilCopyImage(mFracTexID);
    //Scale the image to fit our box
    const int wid = w() - 2;
    const int hei = h() - 2;
    iluImageParameter(ILU_FILTER, ILU_SCALE_MITCHELL);
    iluScale(wid, hei, imgInfo.Depth);

    mFracImage = RGBImagePtr(new Fl_RGB_Image(ilGetData(), wid, hei));
    image(mFracImage.get());
    redraw();
    ilBindImage(0);
}
示例#10
0
ofxTexture::ofxTexture()
    :ofxResource()
{
    glGenTextures(1, &m_TextureId);
    m_ImageId = ilGenImage();
    m_Width = 0;
    m_Height = 0;
    m_BytePerPixel = 0;
    m_Compressed = m_CompressedByDefault;
    m_Locked = false;
}
示例#11
0
void Texture::SaveAs(std::string pszFileName, size_t piWidth, size_t piHeight, size_t pType, size_t pFmt, void * pData)
{
    ILuint  _iImageId   = 0;

    _iImageId = ilGenImage();
    ilBindImage(_iImageId);

    ASSERT(  ilTexImage(piWidth,    piHeight, 0, 3, pType, pFmt, pData) == IL_TRUE  , "Texture: Unable to set data!");
    VERIFY(  ilSaveImage(pszFileName.c_str()) == IL_TRUE  , "Texture: Unable to save Image!");

    ilDeleteImage(_iImageId);
}
示例#12
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoadL(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	FILE* f = _wfopen(sourceFN, L"rb");
	bool loaded = false;

	if (f != NULL) {
		fseek(f, 0, SEEK_END);
		INT64 size = ftell(f);
		if (size > 0) {
			fseek(f, 0, SEEK_SET);
			char* lump = new char[size];
			size_t read = fread(lump, 1, size, f);
			if (read == size) {
				loaded = ilLoadL(IL_TYPE_UNKNOWN, lump, read);
				if (!loaded) {
					printf("test_ilLoadL: Failed to load " PathCharMod "\n", sourceFN);
					++errors;
				}
			} else {
				printf("test_ilLoadL: Failed to read " PathCharMod "\n", sourceFN);
				++errors;
			}
			delete lump;
		}
		fclose(f);
	} else {
		printf("test_ilLoadL: Failed to load %S\n", sourceFN);
		++errors;
	}

	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);
	if (loaded)
		if (!ilSaveImage(targetFN)) {
			printf("test_ilLoadL: Failed to save " PathCharMod "\n", targetFN);
			++errors;
		}
	testHeap();
	ilDeleteImage(handle);
}
示例#13
0
FileTexture::FileTexture(const string &path)
{
	ilInit();
	imageHandle = ilGenImage();
	ilBindImage(imageHandle);
	ILboolean result = ilLoadImage(path.c_str());

	if (result) {
		width = ilGetInteger(IL_IMAGE_WIDTH);
		height = ilGetInteger(IL_IMAGE_HEIGHT);
		channels = ilGetInteger(IL_IMAGE_CHANNELS);
	}
}
示例#14
0
文件: test.cpp 项目: wg-lesta/ResIL
ILboolean testDetermineTypeFromContent(TCHAR* fn)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	FILE* f = _wfopen(fn, L"rb");
	bool loaded = false;
	ILenum type = IL_TYPE_UNKNOWN;

	if (f != NULL) {
		fseek(f, 0, SEEK_END);
		myDataSize = ftell(f);
		if (myDataSize > 0) {
			fseek(f, 0, SEEK_SET);
			myData = new BYTE[myDataSize];
			size_t read = fread(myData, 1, myDataSize, f);
			myReadPos = 0;
			if (read == myDataSize) {
				//loaded = ilLoadL(IL_TYPE_UNKNOWN, lump, read);
				ilSetRead(myOpenProc, myCloseProc, myEofProc, myGetcProc, myReadProc, mySeekProc, myTellProc);
				type = ilDetermineTypeFuncs();
				if (type == IL_TYPE_UNKNOWN) {
					printf("testDetermineTypeFromContent: Failed to determine type of " PathCharMod "\n", fn);
					++errors;
				}
			} else {
				printf("testDetermineTypeFromContent: Failed to read " PathCharMod "\n", fn);
				++errors;
			}
			delete myData;
		}
		fclose(f);
	} else {
		printf("testDetermineTypeFromContent: Failed to open %S\n", fn);
		++errors;
	}

	testHeap();
	ilDeleteImage(handle);

	if (type == IL_TYPE_UNKNOWN) {
		++errors;
		return IL_FALSE;
	} else
		return IL_TRUE;
}
示例#15
0
void ofxTexture::Fill(ofFloatColor color, ofRectangle dest_rect)
{
    if(m_Locked) return;
    ILuint dummy = ilGenImage();
    ilBindImage(dummy);
    ilTexImage(dest_rect.width, dest_rect.height, 0, 4, IL_RGBA , IL_UNSIGNED_BYTE, NULL);
    ilClearColour(color.r, color.g, color.b, color.a);
    ilClearImage();
    ilBindImage(m_ImageId);
    ilDisable(IL_BLIT_BLEND);
    ilBlit(dummy, dest_rect.x, dest_rect.y, 0, 0, 0, 0, dest_rect.width, dest_rect.height, 1);
    ilEnable(IL_BLIT_BLEND);
    ilDeleteImage(dummy);
}
示例#16
0
void ofxTexture::StretchTransfer(ofxTexture* source, ofRectangle source_rect, ofRectangle dest_rect, int alpha)
{
    if(m_Locked || source->IsLocked()) return;
    ILuint dummy = ilGenImage();
    ilBindImage(dummy);
    ilCopyImage(source->GetDevilId());
    iluScale(dest_rect.width, dest_rect.height, 1);
    ilBindImage(m_ImageId);
    ilDisable(IL_BLIT_BLEND);
    ilBlit(dummy, dest_rect.x, dest_rect.y, 0,
           source_rect.x, source_rect.y, 0, source_rect.width, source_rect.height, 1);
    ilEnable(IL_BLIT_BLEND);
    ilDeleteImage(dummy);
}
示例#17
0
void Renderer::saveScreenshot(const std::string& filename, int width, int height)
{
    ILuint tex;
    tex = IL_CHECK(ilGenImage());
    IL_CHECK(ilBindImage(tex));

    void* data = malloc(width * height * 3);
    glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, data);
    ilTexImage(width, height, 1, 3, IL_RGB, IL_UNSIGNED_BYTE, data);
    free(data);

    IL_CHECK(ilSaveImage(filename.c_str()));
    IL_CHECK(ilDeleteImage(tex));
}
示例#18
0
文件: test.cpp 项目: wg-lesta/ResIL
void test_ilLoadF(wchar_t* sourceFN, wchar_t* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	//printf("Loading " PathCharMod "\n", sourceFN);
	bool loaded = false;

	//FILE* f = _wfopen(sourceFN, L"rb");
	FILE * f;
	char buf[10];
	_wfopen_s(&f, sourceFN, L"rb");
	fread(buf, 1, 10, f);
	fseek(f, 0, IL_SEEK_SET);
	if (f != NULL) {
		loaded = ilLoadF(IL_TYPE_UNKNOWN, f);
		if(!loaded) {
			printf("test_ilLoadF: Failed to load %S\n", sourceFN);
			++errors;
		}
	} else {
		printf("test_ilLoadF: Failed to open %S\n", sourceFN);
		++errors;
	}

	fclose(f);
	testHeap();
	//ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	//ilConvertImage(IL_LUMINANCE, IL_UNSIGNED_BYTE);
	//iluScale(150, 150, 1);
	testHeap();
	DeleteFile(targetFN);
	//printf("Saving " PathCharMod "\n", targetFN);

	if (loaded)
		if (!ilSaveImage(targetFN)) {
			printf ("test_ilLoadF: Failed to save %S\n", targetFN);
			++errors;
		}

	testHeap();
	ilDeleteImage(handle);
}
示例#19
0
	//Texture* TextureManager::LoadFromFile(const string& szTexturePath, const string& uniName)
	//{
	//	return LoadFromFile(TypeCast::stringToString(const_cast<string&>(szTexturePath))
	//		,TypeCast::stringToString(const_cast<string&>(uniName)));
	//}
	Texture* TextureManager::LoadFromFile(const String& szTexturePath, const String& uniName)
	{
		REQUIRES(m_currentRenderer);
		REQUIRES( !szTexturePath.empty() );

		//TODO check if the texture is loaded before : return the old tex

		//ilInit();

		ilEnable( IL_ORIGIN_SET );
		ilOriginFunc( IL_ORIGIN_LOWER_LEFT );

		ILuint idImage = ilGenImage();
		ilBindImage( idImage );
		ilLoadImage( szTexturePath.c_str() );


		if(IL_NO_ERROR != ilGetError())
		{
			NLOG("IL Load From File Error:\n",0);
			return getDefaultTex();
			//throw NException(TextureDevilError, String(TEXT("IL Load From File Error:\n")) + szTexturePath);
		}

		Texture* newTex = new Texture(szTexturePath,uniName);

		ilConvertImage(IL_RGBA,IL_UNSIGNED_BYTE);
		//convert to this type

		newTex->width = ilGetInteger( IL_IMAGE_WIDTH );
		newTex->height = ilGetInteger( IL_IMAGE_HEIGHT );
		newTex->format = NBE_COLOR_RGBA;
		newTex->type = NBE_UNSIGNED_BYTE;

		newTex->textureIdx = m_currentRenderer->createTexture(szTexturePath.c_str(),
			ilGetData(),newTex->width, newTex->height, newTex->format, newTex->type, true);
																						
		m_loadedTextures.push_back(newTex);
		
		// Delete the DevIL image.

		ilDeleteImage( idImage );
		return newTex;

	}
示例#20
0
bool ILContainer::Initialize(const char * file_name)
{
	assert(this->il_handle == BAD_IL_VALUE);
	if ((this->il_handle = ilGenImage()) == BAD_IL_VALUE)
		return false;
	ilBindImage(this->il_handle);
	if (!ilLoadImage(file_name))
		return false;

	glGenTextures(1, &this->il_texture_handle);
	glBindTexture(GL_TEXTURE_2D, this->il_texture_handle);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), this->width = ilGetInteger(IL_IMAGE_WIDTH), this->height = ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
	return true;
}
	bool TextureHandler::load_texture(std::wstring file_name) {
		m_devil_image_id = ilGenImage();
		ilBindImage(m_devil_image_id);
		ilLoadImage(file_name.c_str());
		get_DevIL_error();
		m_width = ilGetInteger(IL_IMAGE_WIDTH);
		m_height= ilGetInteger(IL_IMAGE_HEIGHT);
		ILint format = ilGetInteger(IL_IMAGE_FORMAT);
		ILint type = ilGetInteger(IL_IMAGE_TYPE);
		ilLoadImage(file_name.c_str());
		get_DevIL_error();
		//we want to load unsigned char RGBA images
		m_data = new unsigned char[m_width * m_height * 4];
		ilCopyPixels(0, 0, 0, m_width, m_height, 1, format, type, m_data);
		get_DevIL_error();
		ilDeleteImage(m_devil_image_id);
		send_to_gpu();
		return true;
	}
示例#22
0
void FractureBox::resizeFractureTexture()
{
    ASSERT(mFracTexID);
    if(mFracTexScaleID)
        ilDeleteImage(mFracTexScaleID);
    mFracTexScaleID = ilGenImage();
    ilBindImage(mFracTexScaleID);
    ilCopyImage(mFracTexID);

    ILinfo imgInfo;
    iluGetImageInfo(&imgInfo);
    //Scale the image to fit our box
    const int wid = w() - 2;
    const int hei = h() - 2;
    iluScale(wid, hei, imgInfo.Depth);

    mFracImage = RGBImagePtr(new Fl_RGB_Image(ilGetData(), wid, hei));
    image(mFracImage.get());
    redraw();
    ilBindImage(0);
}
示例#23
0
Texture::Texture(std::string pszFileName)
{
    ILuint  _iImageId   = 0;
    size_t  _iImageSize = 0;

    _iImageId = ilGenImage();
    ilBindImage(_iImageId);
    WriteCommandLine("\nLoading Image %s", pszFileName.c_str());
    VERIFY( ilLoadImage(pszFileName.c_str() ) == IL_TRUE, "Texture: Unable to load file!");

    switch(ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL))
    {
    case 3:
        ASSERT(  ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE) == IL_TRUE  , "Texture: Unable to load file!");
        m_Type = IL_RGB;
        break;

    case 4:
        ASSERT(  ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE) == IL_TRUE  , "Texture: Unable to load file!");
        m_Type = IL_RGBA;
        break;

    default:
        ASSERT(0, "Texture: Unable to load file!");
        break;
    }
    m_iHeight   = ilGetInteger(IL_IMAGE_HEIGHT);
    m_iWidth    = ilGetInteger(IL_IMAGE_WIDTH);

    _iImageSize = ilGetInteger(IL_IMAGE_SIZE_OF_DATA);

    m_pData     =   new unsigned char[_iImageSize];
    m_pfData    =   new float[_iImageSize];
    memcpy(m_pData, ilGetData(), _iImageSize);

    for(size_t i = 0; i < _iImageSize; i++)
        m_pfData[i] = ((float)m_pData[i]) / 255.0f;

    ilDeleteImage(_iImageId);
}
GLuint TextureUtils::createTexture(const GLchar *path){
   ilInit();
   ILuint image = ilGenImage();

   ilBindImage(image);

   ILboolean loadSuccess = ilLoadImage(path);
   if(!loadSuccess){
      std::cerr<<"Failed to load image: "<<path<<std::endl;
      ilBindImage(NULL);
      ilDeleteImage(image);
      return NULL;
   }

   ILboolean convertSuccess = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
   if(!convertSuccess){
      std::cerr<<"Failed to convert image: "<<path<<std::endl;
      ilBindImage(NULL);
      ilDeleteImage(image);
      return NULL;
   }

   GLuint texture;
   glGenTextures(1, &texture);
   glBindTexture(GL_TEXTURE_2D, texture);

   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


   glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_FORMAT), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), ilGetInteger(IL_IMAGE_TYPE), ilGetData());
   glBindTexture(GL_TEXTURE_2D, NULL);

   ilBindImage(NULL);
   ilDeleteImage(image);

   return texture;
}
示例#25
0
Texture2D Texture2D::createFromImageByPath(const std::string &path)
{
//    SDL_Surface *pSurface(IMG_Load(path.c_str()));

//    Texture2D ret(createFromSDLSurface(*pSurface));
//    SDL_FreeSurface(pSurface);
//    return ret;
    unsigned imageId = ilGenImage();
    ilBindImage(imageId);
    int success = ilLoadImage(path.c_str());
    if (success) {
        success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
    }

    if (!success) {
        ilDeleteImage(imageId);

        {
            SDL_Surface *pSurface(IMG_Load(path.c_str()));
            if (!pSurface)
                throw std::runtime_error("Cannot load texture " + path);
            unsigned id = createFromSDLSurface(*pSurface);
            SDL_FreeSurface(pSurface);
            if (id == 0)
                throw std::runtime_error("Cannot load texture: SDL_image not "
                                         "expected this format" + path);
            {
                Texture2D ret;
                ret.m_id = id;
                return ret;
            }
        }
    }
    Texture2D ret(createFromDevILBinded());
    ilDeleteImage(imageId);
    return ret;
}
示例#26
0
文件: test.cpp 项目: wg-lesta/ResIL
void testSavers(const TCHAR* sourceFN, const TCHAR* targetFN)
{
	testHeap();
	ilInit();
	testHeap();
	ILuint handle = ilGenImage();
	testHeap();
	ilBindImage(handle);
	testHeap();
	if (!ilLoadImage(sourceFN)) {
		printf("Failed to load %S using ilLoadImage\n", sourceFN);
		++errors;
		return;
	}
	testHeap();

	// gif, ico: no save support...
	// todo: psd, pcx, tga, tif
	testSavers2(IL_BMP, targetFN, L"bmp");
	testSavers2(IL_JPG, targetFN, L"jpg");
	testSavers2(IL_PNG, targetFN, L"png");
	testSavers2(IL_PSD, targetFN, L"psd");
	testSavers2(IL_PCX, targetFN, L"pcx");
	testSavers2(IL_TGA, targetFN, L"tga");
	testSavers2(IL_TIF, targetFN, L"tif");
	testSavers2(IL_TGA, targetFN, L"tga");
	testSavers2(IL_PCX, targetFN, L"pcx");
	testSavers2(IL_PNM, targetFN, L"pnm");
	testSavers2(IL_SGI, targetFN, L"sgi");
	testSavers2(IL_WBMP, targetFN, L"wbmp");
	testSavers2(IL_MNG, targetFN, L"mng");
	testSavers2(IL_VTF, targetFN, L"vtf");

	testHeap();
	ilDeleteImage(handle);
}
示例#27
0
Bitmap *loadFromData(void const *data, size_t size, std::string const &fmt)
{
    ilGetError();
    ILenum ilFormat = IL_RAW;
    ilFormat = get_bitmap_ext_fmt(fmt);
    bitmap_init();
    int img = ilGenImage();
    ilBindImage(img);
    ilEnable(IL_ORIGIN_SET);
    ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
    ilEnable(IL_CONV_PAL);
    ilLoadL(ilFormat, data, size);
    int err = ilGetError();
    if (err != IL_NO_ERROR)
    {
        ilDeleteImage(img);
        char errStr[256];
        _snprintf_s(errStr, 256, "Error 0x%x", err);
        errStr[255] = 0;
        throw std::runtime_error(std::string("Error loading image format: ") + fmt
            + "\n" + errStr);
    }
    return new ILBitmap(img);
}
std::tr1::shared_ptr<ATexture> ATextureLoader::LoadFile(const std::string& path)
{
	// try to retrieve the texture from the cache, if it exists
	std::tr1::shared_ptr<ATexture> texture_sp = ATextureCache::GetInstance()->Get(path);
	if(texture_sp != nullptr){
		return texture_sp;
	}

	unsigned int width, contentWidth, height, contentHeight;

	ILuint imageID = ilGenImage();
	ilBindImage(imageID);

	if(!ilLoadImage(path.c_str())){
		std::string error = "Fail to load file: " + path;
		throw std::exception(error.c_str());
		return nullptr;
	}

	// The content in
	width = contentWidth = ilGetInteger(IL_IMAGE_WIDTH);
	height = contentHeight = ilGetInteger(IL_IMAGE_HEIGHT);
	ILint bpp = ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);

	// Actual texture  size padded with extra pixels, ensure width and height are power of two.
	if(!isPowerOfTwo(contentWidth))
		width = nextPowerOfTwo(contentWidth);
	if(!isPowerOfTwo(contentHeight))
		height = nextPowerOfTwo(contentHeight);

	// default background colour will be solid black
	ilClearColour(0.0f, 0.0f, 0.0f, 1.0f);

	// TODO: there is still some confusion here.......
	// flip texture problem is mentioned here: http://www.gamedev.net/topic/308200-devil-textures-upside-down/

	// Together with the ilOriginFunc in the graphics_engine.h initialize function, and followed by iLuFlipImage(). 
	// They ensure the image data will be correctly loaded and place on top left corner. And the data will be always stored from top left corner.
	iluImageParameter(ILU_PLACEMENT, ILU_UPPER_LEFT);
	// bitmap image seems like storing data upside down, its origin is on the lower left.
	// jpg, png data seems like using upper left as the origin.
	if (ilGetInteger(IL_IMAGE_ORIGIN) == IL_ORIGIN_UPPER_LEFT){
		// This is for fixing the loaded image upside down in OpenGL...
		iluFlipImage();
	}

	// set the canvas size.
	iluEnlargeCanvas(width, height, bpp);

	// Allocate the memory for the image data.
	GLubyte* buffer = new GLubyte[width * height * bpp];
	// Copy the loaded image data into the texture data depending on how many bytes per pixel
	if(bpp == 4){
		ilCopyPixels(0, 0, 0, width, height, 1, IL_RGBA, GL_UNSIGNED_BYTE, buffer);
	}
	else if(bpp == 3){
		ilCopyPixels(0, 0, 0, width, height, 1, IL_RGB, GL_UNSIGNED_BYTE, buffer);
	}
	else{
		std::string error = "Loading process, byte per pixel error, bpp: "+bpp;
		throw std::exception(error.c_str());	
	}

	// Delete the devIL image data
	ilDeleteImage(imageID);

	// create a brand new texture to use
	// put the texture into the texture cache.
	texture_sp = ATextureCache::GetInstance()->Cache(path, new ATexture(buffer, contentWidth, contentHeight, width, height, GL_RGBA, bpp));

	// after texture is created, the buffer data will be uploaded to OpenGL, so no long needed.
	delete[] buffer;

	// This is a pointer to the loaded image data
	return texture_sp;
}
示例#29
0
文件: main.cpp 项目: astrellon/GPP
void init()
{
	// Initialize the DevIL framework.
	ilInit();

	// Initialize OpenGL
	glInit();

	// Give the scene a starting number of spheres.
	changeSphereCount(INITIAL_SPHERE_COUNT);
	
	// Create an image ID for our font texture.
	ILubyte fontId = ilGenImage();
	ilBindImage(fontId);

	if(!ilLoad(IL_PNG, "data/font.png"))
	{
		MessageBox(NULL, "Unable to load font texture.\nThere will be no interface.", "Could not load font.", MB_OK);
	}
	else
	{
		// Tell all existing TextFields the image ID to use.
		txtNumSpheres.setFontId(fontId);
		txtRenderFrames.setFontId(fontId);
		txtPhysicsFrames.setFontId(fontId);
		txtNumThreads.setFontId(fontId);

		txtInstructions.setFontId(fontId);
		txtInstructions.setColour(0xFFFFAA);
		txtInstructions.setText("Press +/- to add or remove spheres. 1 - 9 to set sphere size.");

		txtInstructions2.setFontId(fontId);
		txtInstructions2.setColour(0xFFFFAA);
		txtInstructions2.setText("Use the arrow keys and page up/down to control the sphere.");
	}

	int iCPUVals[4];
	cpuid(1, iCPUVals);

	bool sse4Support = false;
	if(iCPUVals[2] & (1 << 19))
	{
		sse4Support = true;
	}

#ifdef _SSE4
	if(!sse4Support && _SSE4)
	{
		txtInstructions.setColour(0xFF0000);
		txtInstructions.setText("Your computer does not support SSE4, please use a different version of this program.");
		displayError = true;

		numPhysicsThreads = 1;
	}
	else
#endif
	{
		// Setup performance checking, used to determine time difference
		// between physics thread runs.
		QueryPerformanceFrequency( &frequency );
		freq = (double)frequency.QuadPart / 1000.0;
		LARGE_INTEGER firstTime;
		QueryPerformanceCounter(&firstTime);

	#if _USE_MT
		// Get the number of physics threads to use from boost.
		numPhysicsThreads = boost::thread::hardware_concurrency();
	#else
		// Set that we're only using one thread, mostly for the purpose that
		// the physics function uses the number of threads for striding.
		numPhysicsThreads = 1;
	#endif

		updateTimes = new LARGE_INTEGER[numPhysicsThreads];
		physicsFrames = new int[numPhysicsThreads];

		for(int i = 0; i < numPhysicsThreads; i++)
		{
			updateTimes[i] = firstTime;
			physicsFrames[i] = 0;
	#if _USE_MT
			threads.create_thread(boost::bind(physicsThread, i));
	#endif
		}

		char buff[32];

		sprintf(buff, "Num threads: %d", numPhysicsThreads);
		txtNumThreads.setText(buff);
	}
}
示例#30
0
SMFMap::SMFMap(std::string smfname)
{
  std::vector<ILuint> tiles_images;
  std::vector<std::string> tile_files;
  metalmap = NULL;
  heightmap = NULL;
  typemap = NULL;
  minimap = NULL;
  vegetationmap = NULL;
  m_tiles = NULL;
  FILE * smffile = fopen(smfname.c_str(),"rb");
  if ( !smffile )
  {
    throw CannotLoadSmfFileException();
    
  }
  SMFHeader hdr;
  fread(&hdr,sizeof(hdr),1,smffile);
  if ( strncmp(hdr.magic,"spring map file",15) > 0 )
  {
    fclose(smffile);
    throw InvalidSmfFileException();
  }
  mapx = hdr.mapx;
  mapy = hdr.mapy;
  m_minh = hdr.minHeight;
  m_maxh = hdr.maxHeight;
  m_smfname = smfname;
  m_doclamp = true;
  m_th = 0;
  m_comptype = COMPRESS_REASONABLE;
  m_smooth = false;
  texture = new Image();
  texture->AllocateRGBA((mapx/128)*1024,(mapy/128)*1024);
  std::cout << "Loading metal map..." << std::endl;
  metalmap = new Image();
  metalmap->AllocateLUM(mapx/2,mapy/2);
  fseek(smffile,hdr.metalmapPtr,SEEK_SET);
  fread(metalmap->datapointer,mapx/2*mapy/2,1,smffile);
  
  
  std::cout << "Loading heightmap..." << std::endl;
  heightmap = new Image();
  heightmap->AllocateLUM(mapx+1,mapy+1);
  heightmap->ConvertToLUMHDR();//TODO: Allocate directly HDR
  fseek(smffile,hdr.heightmapPtr,SEEK_SET);
  fread(heightmap->datapointer,(mapx+1)*(mapy+1)*2,1,smffile);
  heightmap->FlipVertical();
  
  std::cout << "Loading type map..." << std::endl;
  typemap = new Image();
  typemap->AllocateLUM(mapx/2,mapy/2);
  fseek(smffile,hdr.typeMapPtr,SEEK_SET);
  fread(typemap->datapointer,mapx/2*mapy/2,1,smffile);
  typemap->FlipVertical();
  
  std::cout << "Loading minimap..." << std::endl;
  minimap = new Image();
  uint8_t * dxt1data = new uint8_t[699064];
  fseek(smffile,hdr.minimapPtr,SEEK_SET);
  fread(dxt1data,699064,1,smffile);
  ilBindImage(minimap->image);
  ilTexImageDxtc(1024,1024,1,IL_DXT1,dxt1data);
  ilDxtcDataToImage();
  std::cout << "Extracting main texture..." << std::endl;
  int *tilematrix = new int[mapx/4 * mapy/4];
  
  fseek(smffile,hdr.tilesPtr,SEEK_SET);
  MapTileHeader thdr;
  fread(&thdr,sizeof(thdr),1,smffile);
  while ( tile_files.size() < thdr.numTileFiles )
  {
    tile_files.push_back("");
    char byte;
    int numtiles;
    fread(&numtiles,4,1,smffile);
    fread(&byte,1,1,smffile);
    while ( byte != 0 )
    {
      tile_files[tile_files.size()-1].append(1,byte);
      fread(&byte,1,1,smffile);
    }
  }
  for ( std::vector<std::string>::iterator it = tile_files.begin(); it != tile_files.end(); it++ )
  {
    std::cout << "Opening " << *it << std::endl;
    FILE* smtfile = fopen((*it).c_str(),"rb");
    if ( !smtfile )
    {
      fclose(smffile);
      delete [] tilematrix;
      throw CannotOpenSmtFileException();
    }
    TileFileHeader smthdr;
    fread(&smthdr,sizeof(smthdr),1,smtfile);
    if ( strncmp(smthdr.magic,"spring tilefile",14) )
    {
      fclose(smffile);
      fclose(smtfile);
      delete [] tilematrix;
      throw InvalidSmtFileException();
    }
    for ( int i = 0; i < smthdr.numTiles; i++ )
    {
      ILuint tile = ilGenImage();
      fread(dxt1data,680,1,smtfile);
      ilBindImage(tile);
      ilTexImageDxtc(32,32,1,IL_DXT1,dxt1data);
      ilDxtcDataToImage();
      tiles_images.push_back(tile);
    }
    fclose(smtfile);
    
    
  }
  std::cout << "Tiles @ " << ftell(smffile) << std::endl;
  fread(tilematrix,mapx/4 * mapy/4 * 4,1,smffile);
  ilBindImage(texture->image);
  unsigned int * texdata = (unsigned int *)ilGetData();
  std::cout << "Blitting tiles..." << std::endl;
  for ( int y = 0; y < mapy/4; y++ )
  {
    std::cout << "Row " << y << " of " << mapy/4 << std::endl;
    for ( int x = 0; x < mapx/4; x++ )
    {
      if ( tilematrix[y*(mapx/4)+x] >= tiles_images.size() )
      {
	std::cerr << "Warning: tile " << tilematrix[y*(mapx/4)+x] << " out of range" << std::endl;
	continue;
      }
      //ilBlit(tiles_images[tilematrix[y*(mapx/4)+x]],x*32,y*32,0,0,0,0,32,32,1);
      ilBindImage(tiles_images[tilematrix[y*(mapx/4)+x]]);
      unsigned int * data = (unsigned int *)ilGetData();
      int r2 = 0;
      for ( int y2 = y*32; y2 < y*32+32; y2++ )//FAST blitting
      {
	/*for ( int x2 = y*32; x2 < y*32+32; x2++ )
	{
	  
	  
	}*/
	memcpy(&texdata[y2*texture->w+x*32],&data[r2*32],32*4);
	r2++;
      }
    }
    
  }
  texture->FlipVertical();
  
  
  std::cout << "Loading features..." << std::endl;
  
  fseek(smffile,hdr.featurePtr,SEEK_SET);
  MapFeatureHeader mfhdr;
  fread(&mfhdr,sizeof(mfhdr),1,smffile);
  //-32767.0f+f->rotation/65535.0f*360
  
  std::vector<std::string> feature_types;
  while ( feature_types.size() < mfhdr.numFeatureType )
  {
    feature_types.push_back("");
    char byte;
    fread(&byte,1,1,smffile);
    while ( byte != 0 )
    {
      feature_types[feature_types.size()-1].append(1,byte);
      fread(&byte,1,1,smffile);
    }
  }
  for ( int i = 0; i < mfhdr.numFeatures; i++ )
  {
    MapFeatureStruct f;
    fread(&f,sizeof(f),1,smffile);
    if ( f.featureType >= feature_types.size() )
    {
      std::cerr << "Warning: invalid feature type " << f.featureType << std::endl;
      continue;
    }
    AddFeature(feature_types[f.featureType],f.xpos,f.ypos,f.zpos,-32767.0f+f.rotation/65535.0f*360);
    
  }
  fclose(smffile);
  delete [] dxt1data;
  delete [] tilematrix;
}