示例#1
0
文件: AnimTest.cpp 项目: AMDmi3/DevIL
void LoadImages(char *FileName)
{
	ILuint Image, i;

	hDC = GetDC(HWnd);
	hMemDC = CreateCompatibleDC(hDC);

	ilGenImages(1, &Image);
	ilBindImage(Image);
	if (!ilLoadImage(FileName)) {
		ilDeleteImages(1, &Image);
		return;
	}

	ilEnable(IL_ORIGIN_SET);
	ilEnable(IL_FORMAT_SET);
	ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
	//ilFormatFunc(IL_BGRA);
	ilConvertImage(IL_BGR, IL_UNSIGNED_BYTE);
	ilutRenderer(ILUT_WIN32);

	CurImage = 0;
	NumImages = ilGetInteger(IL_NUM_IMAGES) + 1;
	Bitmaps = new HBITMAP[NumImages];
	BmpInfo = new BITMAPINFOHEADER[NumImages];
	Durations = new ILuint[NumImages];
	if (Bitmaps == NULL || BmpInfo == NULL || Durations == NULL) {
		ilDeleteImages(1, &Image);
		return;
	}

	for (i = 0; i < NumImages; i++) {
		ilActiveImage(0);
		ilActiveImage(i);
		Durations[i] = ilGetInteger(IL_IMAGE_DURATION);
		*(Bitmaps + i) = ilutConvertToHBitmap(hDC);
		ilutGetBmpInfo((BITMAPINFO*)(BmpInfo + i));
	}

	SelectObject(hMemDC, Bitmaps[0]);

	ilDeleteImages(1, &Image);

	sprintf(NewTitle, "%s - %s", TITLE, FileName);
	SetWindowText(HWnd, NewTitle);

	QueryPerformanceFrequency((LARGE_INTEGER*)&TimerFreq);
	TimerRes = 1.0 / TimerFreq;
	QueryPerformanceCounter((LARGE_INTEGER*)&StartTime);

	return;
}
示例#2
0
SDL_Surface* ILAPIENTRY ilutSDLSurfaceLoadImage(ILstring FileName)
{
	SDL_Surface *Surface;

	iBindImageTemp();
	if (!ilLoadImage(FileName)) {
		return NULL;
	}

	Surface = ilutConvertToSDLSurface(SDL_SWSURFACE);

	return Surface;
}
示例#3
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);
	}
}
	void Texture::loadFromFile(std::string fileName) {
		ilGenImages(1, &imageId);
		ilBindImage(imageId);
		glGenTextures(1, &glTextureId);

		if (!ilLoadImage(charToWChar(fileName.c_str()))) {
			std::cout << "Couldn't load the image: " << fileName << " ";
			cout << ilGetError() << endl;
		}

		width = ilGetInteger(IL_IMAGE_WIDTH);
		height = ilGetInteger(IL_IMAGE_HEIGHT);
	}
bool CSprite::LoadTexture(char* filename)
{
	Engine()->PushContext();

	// TODO: Move this into a separate class

	if ( !glIsEnabled( GL_TEXTURE_RECTANGLE_NV ) ) 
	{
		m_iTexture = ilutGLLoadImage( filename );

		if (ilGetError() != IL_NO_ERROR)
			return false;

		m_iWidth = ilGetInteger( IL_IMAGE_WIDTH );
		m_iHeight = ilGetInteger( IL_IMAGE_HEIGHT );

	}
	else
	{
		ILuint texid;

		ilGenImages(1, &texid);
		ilBindImage(texid);
		ilLoadImage( filename );

		ILenum Error = ilGetError();

		if ( Error != IL_NO_ERROR )
		{
			sqstd_printcallstack( Sqrat::DefaultVM::Get() );
			std::stringstream st; st << "DevIL Error: " << iluErrorString(Error) << std::endl;
			Engine()->Debug( st.str() );
			return false;
		}

		m_iWidth = ilGetInteger( IL_IMAGE_WIDTH );
		m_iHeight = ilGetInteger( IL_IMAGE_HEIGHT );

		ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
		glGenTextures(1, &m_iTexture);
		glBindTexture(GL_TEXTURE_RECTANGLE_NV, m_iTexture);
		glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_RECTANGLE_NV, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_RECTANGLE_NV, 0, ilGetInteger(IL_IMAGE_BPP), m_iWidth,
		 m_iHeight, 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
		 ilGetData());
	}

	//Engine()->PopContext();
	return true;
}
示例#6
0
文件: main.cpp 项目: csorkin09/CS-480
//Load Textures
bool loadTexture(const char * fileName, GLuint &image)
{
  ILuint texid;
  
  // initialize devIL
  ilInit(); 

  // generate and bind image
  ilGenImages(1, &texid); 
  ilBindImage(texid);

  // load image
  bool success = ilLoadImage((const ILstring)fileName); 
  std::cout<<(const ILstring)fileName<<std::endl;

  if(success) 
  {
    // convert image to uchar
    success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE); 

    if(!success)
    {
      printf("Error parsing '%s'\n", fileName);
      return false;
    }

    // name and bind textures
    glGenTextures(1, &image); 
    glBindTexture(GL_TEXTURE_2D, image); 

    // specify linear interpolation for scaling filters
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 

    // set texture information
    glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH),
      ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
      ilGetData()); 
  }
  else
  {
    // couldn't open file
    printf("Error parsing '%s'\n", fileName); 
    return false;
  }

  // delete the image held by devIL
  ilDeleteImages(1, &texid);

  return true;
}
示例#7
0
	Image::Image(string filename)
	{
		Image::init();

		ilGenImages(1, &_image);

		ilBindImage(_image);
		ilLoadImage(filename.c_str());

		ILenum Error;
		while ((Error = ilGetError()) != IL_NO_ERROR) {
			std::cerr << iluErrorString(Error) << std::endl;
		}
	}
示例#8
0
ImageID sys_loadImage(const char *name)
{
  bool success;
  if(_nextImage >= IMAGE_MAX)
  {
    LOG("Ran out of image slots.");
    _shouldClose = true;
    return 0;
  }
  
  ILuint iluint;
  
  LOG("Loading %s.", name);
  ilGenImages(1, &iluint);
  ilBindImage(iluint);
  success = ilLoadImage(name);
  if(!success)
  {
    LOG("Failed to load spritesheet.");
    _shouldClose = true;
    return 0;
  }
  
  success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
  if(!success)
  {
    LOG("Failed to convert image.");
    _shouldClose = true;
    return 0;
  }
  
  // Bind image to opengl
  glBindTexture(GL_TEXTURE_2D, _images[_nextImage].gluint);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 

  _images[_nextImage].size.x = ilGetInteger(IL_IMAGE_WIDTH);
  _images[_nextImage].size.y = ilGetInteger(IL_IMAGE_HEIGHT);
    
  glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP),
               _images[_nextImage].size.x, _images[_nextImage].size.y,
               0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());  
 
  // Image now in graphics memory, can ditch il copy
  ilDeleteImages(1, &iluint);
  
  LOG("Bound to %d (%d)", _nextImage, _images[_nextImage]);
  _nextImage++;
  return _nextImage-1;
}
示例#9
0
bool ofxTexture::Load(string texture_file)
{
    ilBindImage(m_ImageId);
    ILboolean loaded = ilLoadImage(texture_file.c_str());
    if (loaded == IL_FALSE)
    {
        ILenum error = ilGetError();
        ofLogError() <<"DevIL failed to load image "<<texture_file.c_str()<<endl<<"error code "<<error;
        return false;
    }
    m_Locked = false;
    SubmitChanges();
    return true;
}
示例#10
0
文件: OpenIL.cpp 项目: gan74/nGine2
nTexture::TextureInternal *nTextureLoadInstance::operator()() {
	nIL::lock();
	#ifndef NO_IL
	ILuint img;
	ilGenImages(1, &img);
	ilBindImage(img);
	if(!ilLoadImage(name.toChar()) || !ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE)) {
		ilDeleteImage(img);
		std::cout<<"Unable to load "<<name<<std::endl;
		nIL::unlock();
		return 0;
	}
	int bpp = ilGetInteger(IL_IMAGE_BPP);
	nTexturePrecision p = nTexturePrecision::Simple;
	switch(bpp) {
		case 4:
			p = nTexturePrecision::Simple;
		break;
		case 8:
			p = nTexturePrecision::Double;
		break;
		default:
			ilDeleteImage(img);
			std::cout<<"Unable to load "<<name<<", invalid bpp"<<std::endl;
			nIL::unlock();
			return 0;
	}
	nVec2ui size(ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT));
	void *data = ilGetData();
	#else
	QImage img = QImage(name.toChar()).convertToFormat(QImage::Format_RGBA8888);
	nVec2ui size(img.width(), img.height());
	nTexturePrecision p = nTexturePrecision::Simple;
	void *data = img.bits();
	#endif

	nTexture::TextureInternal *tex = new nTexture::TextureInternal();
	tex->setPrecision(p);
	tex->setData(size, (nColor *)data);
	#ifndef NO_IL
	ilDeleteImage(img);
	#endif
	nIL::unlock();

	#ifdef N_DEBUG
	tex->name = name;
	#endif
	std::cout<<"Texture loaded : "<<name<<std::endl;
	return tex;
}
示例#11
0
ILuint LoadImageMipmaps(const std::string& filename)
{
    ILuint newImageID;

    ilGenImages(1, &newImageID);
    ilBindImage(newImageID);

    if (!ilLoadImage(strdup(filename.c_str())))
       return 0;

    ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

    return ilutGLBindMipmaps();
}
示例#12
0
GLuint loadTextureFile(const char *fn_in, GLuint tex_in, 
  GLenum target_texture, GLenum target_image,
  int HDR) {
  ILuint img=0;
  GLuint tex=tex_in;
  char *fn=0;
  
  
  if (!(fn=vfs_locate(fn_in,REPOSITORY_MASK_TEXTURE))) {
    LOG_WARNING(
      "WARNING: unable to find texture file '%s'\n",
      fn_in);
    goto finalize;
  }
  
  ilEnable(IL_ORIGIN_SET);
  ilOriginFunc(IL_ORIGIN_LOWER_LEFT);
  ilGenImages(1,&img);
  ilBindImage(img);
  
  if (ilLoadImage(fn)!=1) {
    LOG_WARNING(
      "WARNING: unable to load texture file '%s'\n",
      fn);
    goto finalize;
  }
  
  #if DIYYMA_FILE_LIST>=2
  file_list_append(fn);
  #endif
  
  ilConvertImage(HDR?IL_RGB:IL_RGBA,HDR?IL_FLOAT:IL_UNSIGNED_BYTE);
  
  if (!tex) glGenTextures(1,&tex);
  glBindTexture(target_texture,tex);
  glTexImage2D(
    target_image,0,HDR?GL_R11F_G11F_B10F:GL_RGBA,
    ilGetInteger(IL_IMAGE_WIDTH),ilGetInteger(IL_IMAGE_HEIGHT),
    0,HDR?GL_RGB:GL_RGBA,HDR?GL_FLOAT:GL_UNSIGNED_BYTE,
    ilGetData());
  glTexParameteri(target_texture,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
  glTexParameteri(target_texture,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  finalize:
  
  if (fn) free((void*)fn);
  if (img) ilDeleteImages(1,&img);
  
  return tex;
}
示例#13
0
ILuint ImageManager::loadImage(char* filepath, bool ColorKey)
{
    ILuint ImageID;
    ilGenImages(1, &ImageID);
    ilBindImage(ImageID);

	char buffer[64];

    if (!ilLoadImage(filepath))
    {
		sprintf(buffer, "Failed to load Image file: %s", filepath);
		Ogre::LogManager::getSingleton().getLog("Khazad.log")->logMessage(buffer);

         return -1;
    } else {
		sprintf(buffer, "Loading Image file: %s", filepath);
		Ogre::LogManager::getSingleton().getLog("Khazad.log")->logMessage(buffer);
    }

    /*
    IL_RGB
    IL_RGBA
    IL_BGR
    IL_BGRA
    IL_LUMINANCE
    IL_COLOUR_INDEX

    IL_BYTE
    IL_UNSIGNED_BYTE
    IL_SHORT
    IL_UNSIGNED_SHORT
    IL_INT
    IL_UNSIGNED_INT
    IL_FLOAT
    IL_DOUBLE
    */

    ilConvertImage(IL_BGRA, IL_UNSIGNED_BYTE);

    if(ColorKey)
    {
        //convert color key
    }

    ReportDevILErrors();

    return ImageID;
}
示例#14
0
文件: anim.cpp 项目: kaczla/KCK
bool Anim::LoadFile(){
	for( this->for_int_i=0; this->for_int_i<this->Size; this->for_int_i++){
		ilGenImages( 1, &this->ImageID[for_int_i] );
		ilBindImage( this->ImageID[for_int_i] );
		this->Success = ilLoadImage( this->File_Name[for_int_i].c_str() );
		if( this->Success == IL_TRUE ){
			this->Width = ilGetInteger(IL_IMAGE_WIDTH);
			this->Height = ilGetInteger(IL_IMAGE_HEIGHT);
			this->Success = ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE );
			if( this->Success == IL_TRUE ){
				glGenTextures( 1, &this->ImageID[for_int_i] );
				glBindTexture( GL_TEXTURE_2D, this->ImageID[for_int_i] );
				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, this->Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLuint*)ilGetData() );
				GLenum error = glGetError();
				if( error != GL_NO_ERROR ){
					LogGame::Write( "[ERR] " );
					LogGame::Write( SDL_GetTicks() );
					LogGame::Write( ": Nie przetworzono grafiki: " );
					LogGame::Write( this->File_Name[for_int_i] );
					LogGame::Write( " Błąd: " );
					LogGame::Write( error );
					LogGame::NewLine();
					return false;
				}
			}
			else{
				LogGame::Write( "[ERR] " );
				LogGame::Write( SDL_GetTicks() );
				LogGame::Write( ": Nie przekształcono grafiki: " );
				LogGame::Write( this->File_Name[for_int_i] );
				LogGame::NewLine();
				return false;
			}
		}
		else{
			LogGame::Write( "[ERR] " );
			LogGame::Write( SDL_GetTicks() );
			LogGame::Write( ": Nie załadowano grafiki: " );
			LogGame::Write( this->File_Name[for_int_i] );
			LogGame::Write( " (PLIK NIE ISTNIEJE)\n" );
			return false;
		}
	}
	return true;

}
示例#15
0
    Texture::Texture(const std::string &texture_name) :
        m_name(texture_name),
        m_id()
    {
        Category& root = Category::getRoot();
        unsigned int    devil_id;

        glGenTextures(1, &this->m_id);
        ilGenImages(1, &devil_id);

        ilBindImage(devil_id);
        /* If no error occured: */
        if (ilLoadImage((RESOURCES_PATH "/textures/" + texture_name).c_str()))
        {
            // Convert every colour component into unsigned byte.If your image contains
            // alpha channel you can replace IL_RGB with IL_RGBA
            //success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);
            if (!ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE))
            {
                // Error occured
                root << Priority::ERROR << "Couldn't convert image " << m_name;
                return;
            }
            // Binding of texture name
            glBindTexture(GL_TEXTURE_2D, this->m_id);
            root << Priority::DEBUG << "Texture " << m_name << " " << m_id << " created";

            // redefine standard texture values
            // use linear interpolation for magnification filter
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            // Texture specification
            glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_FORMAT), ilGetInteger(IL_IMAGE_WIDTH),
                    ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE,
                    ilGetData());
            // we also want to be able to deal with odd texture dimensions
            glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
            glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
            glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
            glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
        }
        else
        {
            /* Error occured */
            root << Priority::ERROR << "Couldn't load image: " << m_name;
        }
        ilDeleteImages(1, &devil_id);
    }
示例#16
0
文件: angTest.cpp 项目: KuroObi/3DCAD
int main(int argc, char** argv){

	printf("START\n");

	int w,h,id;
	unsigned char* data;

	printf("STAGE LoadImage\n");
	// load image first so that window opens with image size
	id = ilLoadImage("textures.jpg");
	// image not loaded
	if (id == 0)
		return(2);
	
	printf("STAGE BindImage\n");

	ilBindImage(id);
	w = ilGetInteger(IL_IMAGE_WIDTH);
	h = ilGetInteger(IL_IMAGE_HEIGHT);
	data = ilGetData();
	
	printf("STAGE GLUT 1/2\n");
    GLUTBackendInit(argc, argv);

	bool fullScreen = true;
	printf("STAGE GLUT 2/2\n");
	if (!GLUTBackendCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 60, fullScreen, "AngTest")){
        return 0x11;
    }
	printf("STAGE AngTest\n");
	AngTest* aTest = new AngTest();

	printf("STAGE Init\n");
	if (!aTest->Init()){
        return 0x12;
    }

	prepareTexture(w,h,data);
	//showAtt(); //just for showing off some pic data
	printf("STAGE Run\n");
	aTest->Run();

	printf("STAGE delete\n");
    delete aTest;
 
	printf("STOP\n");
    return 0;
}
示例#17
0
文件: ilut_allegro.c 项目: jitrc/p3d
BITMAP* ILAPIENTRY ilutAllegLoadImage(ILstring FileName)
{
	ILuint	ImgId;
	PALETTE	Pal;

	ilGenImages(1, &ImgId);
	ilBindImage(ImgId);
	if (!ilLoadImage(FileName)) {
		ilDeleteImages(1, &ImgId);
		return 0;
	}

	ilDeleteImages(1, &ImgId);

	return ilutConvertToAlleg(Pal);
}
示例#18
0
int GLText::LoadFont(char* fname, int Width, int Height)
{
	ScreenWidth = Width;
	ScreenHeight = Height;
	
	unsigned img;
	ilGenImages(1, &img);
	ilBindImage(img);
	if (ilLoadImage(fname) == false)
	{
		printf("Cannot load image file %s - %d\n", fname, ilGetError());
		return 1;
	}
	
	glGenTextures(1, &fontTexture);
	glBindTexture(GL_TEXTURE_2D, fontTexture);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
	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);
	
	ilDeleteImages(1, &img);
	
	char data[256];
	memset(data, 0, 256);
	strcpy(data, fname);
	int len = strlen(data);
	
	data[len] = 0;
	data[len - 1] = 't';
	data[len - 2] = 'a';
	data[len - 3] = 'd';
	
	FILE* f = 0;
	f = fopen(data, "rb");
	if (!f)
	{
		printf("Cannot load character spacing file %s", data);
		return 1;
	}

	fread(charSpace, 1, 256, f);
	fclose(f);
	
	return 0;
}
示例#19
0
GLubyte* OpenImageDevIL(const std::string& filename, unsigned int& w, unsigned int& h, unsigned int& d)
{
	static bool first = true;
	if(first) {
		first = false;

		// Init DevIL
		ilInit();

		// Set origin of image to upper left corner
		ilOriginFunc(IL_ORIGIN_UPPER_LEFT);
		ilEnable(IL_ORIGIN_SET);

		ilEnable(IL_TYPE_SET);
		ilTypeFunc(IL_UNSIGNED_BYTE);
	}

    // Generating a new texture
    ILuint ilTexture;
    ilGenImages(1, &ilTexture);
    ilBindImage(ilTexture);

    // Loading image
	if (!ilLoadImage(filename.c_str()))
		return false;

	w = ilGetInteger(IL_IMAGE_WIDTH);
	h = ilGetInteger(IL_IMAGE_HEIGHT);
	d = ilGetInteger(IL_IMAGE_BPP);
	
	if(d==4)
		ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);

    // Get the size of image
    const unsigned char* Pixels = ilGetData();

	GLubyte* img = new GLubyte[(size_t)(w) * (size_t)(h) * (size_t)(d)];
	memcpy(img, Pixels, (size_t)(w) * (size_t)(h) * (size_t)(d));
	
    // Remove the texture
    ilBindImage(0);
    ilDeleteImages(1, &ilTexture);
	
	return img;
	//return NULL;
}
示例#20
0
文件: image.c 项目: ryd/info-beamer
int image_load(lua_State *L, const char *path, const char *name) {
    ILuint imageID;
    ilGenImages(1, &imageID);
    ilBindImage(imageID);
 
    if (!ilLoadImage(path)) {
        ilDeleteImages(1, &imageID);
        return luaL_error(L, "loading %s failed: %s",
            path, iluErrorString(ilGetError()));
    }
 
    ILinfo ImageInfo;
    iluGetImageInfo(&ImageInfo);

    if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT)
        iluFlipImage();
 
    if (!ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE)) {
        ilDeleteImages(1, &imageID);
        return luaL_error(L, "converting %s failed: %s",
            path, iluErrorString(ilGetError()));
    }

    int width = ilGetInteger(IL_IMAGE_WIDTH);
    int height = ilGetInteger(IL_IMAGE_HEIGHT);

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

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

    glTexImage2D(GL_TEXTURE_2D, 0, ilGetInteger(IL_IMAGE_BPP), width, height, 0,
                 ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
    glGenerateMipmap(GL_TEXTURE_2D);
 
    ilDeleteImages(1, &imageID);
 
    image_t *image = push_image(L);
    image->tex = tex;
    image->fbo = 0;
    image->width = width;
    image->height = height;
    return 1;
}
示例#21
0
GLuint CGLTexture::LoadGL(string f) {
    glBmap=0;
    filename=f;
	ILuint imageID;
	ILboolean success;
	ILenum error;
	ilGenImages(1, &imageID);
	ilBindImage(imageID);
	success = ilLoadImage(filename.c_str());
	if (success) {
		ILinfo ImageInfo;
		iluGetImageInfo(&ImageInfo);
		if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT) iluFlipImage();
		success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
		if (!success){
			error = ilGetError();
			pLog->_Add("  CGLTexture::LoadGL() Image conversion failed - IL reports error: %d %s",error,iluErrorString(error));
			return 0;
        }
        width=ilGetInteger(IL_IMAGE_WIDTH);
        height=ilGetInteger(IL_IMAGE_HEIGHT);
        format=ilGetInteger(IL_IMAGE_FORMAT);
        bpp=ilGetInteger(IL_IMAGE_BPP)*8;
        glEnable(GL_TEXTURE_2D);
		glGenTextures(1, &glBmap);
		glBindTexture(GL_TEXTURE_2D, glBmap);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		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),
                        ilGetInteger(IL_IMAGE_WIDTH),
                        ilGetInteger(IL_IMAGE_HEIGHT),	 0,
                        ilGetInteger(IL_IMAGE_FORMAT),
                        GL_UNSIGNED_BYTE,
                        ilGetData());
 	}
  	else {
		error = ilGetError();
		pLog->_Add("  CGLTexture::LoadGL() Image load failed - IL reports error: %d %s",error,iluErrorString(error));
		return 0;
  	}
 	ilDeleteImages(1, &imageID);
    return glBmap;
}
示例#22
0
   bool Image32::load_texture_from_file_32(const char *path)
   {
       // generate image
       ILuint image_id = 0;
       ilGenImages(1, &image_id);
       ilBindImage(image_id);
       
       //Load image
       bool got = ilLoadImage( path );
 
       
       if (got == IL_TRUE) 
       {
           // convert image
           bool converted = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
           
           if (converted == IL_TRUE)
           {
               // init dimensions
               GLuint image_width  = (GLuint)ilGetInteger(IL_IMAGE_WIDTH);
               GLuint image_height = (GLuint)ilGetInteger(IL_IMAGE_HEIGHT);
               
               GLuint texture_width = power_of_two(image_width);
               GLuint texture_height = power_of_two(image_height);
               
               if (image_width != texture_width || image_height != texture_height)
               {
                   // place image in upper left
                   iluImageParameter(ILU_PLACEMENT, ILU_UPPER_LEFT);
                   
                   // resize image
                   iluEnlargeCanvas((int)texture_width, (int)texture_height, 1);
               }
               
               bool loaded = load_texture_from_pixels_32((GLuint*)ilGetData(), image_width, image_height, texture_width, texture_height);
               
               if (!loaded) {
                   std::cout << "unable to load image: " << path << std::endl;
                   return false;
               }
           }
           ilDeleteImages(1,&image_id);
       }
       _pixel_format = GL_RGBA;
       return true;
   }
示例#23
0
		ILuint ImagePrivate::DevilLoadImage(std::string name)
		{
			ILuint ImageName;
			ilGenImages(1, &ImageName);
			ilBindImage(ImageName);
			if(!ilLoadImage((char*)name.c_str()))
			{
				string str = "Failed to load image: " + name + "!\n";
				gLog.OutPut(str);
				return 0;
			}
			textureMem += (ilGetInteger(IL_IMAGE_WIDTH)*ilGetInteger(IL_IMAGE_HEIGHT)*4);
			string str = "Image Loaded: " + name + "\n";
			gLog.OutPut(str);
	
			return ImageName;
		}
示例#24
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;

	}
示例#25
0
文件: ilur.c 项目: 123woodman/minko
int do_stuff(const Params * parameters)
{
	if (parameters->Flags & FLAG_HELP || ((parameters->Flags | FLAG_LOAD |  FLAG_SAVE) != parameters->Flags) )
	{/* We wanted HELP or we did not get SAVE or LOAD */
		print_help(); /* tell the loser what to do, then :-) */
		return 0;
	}
	int verbose = parameters->Flags & FLAG_VERBOSE;

	int image_handle;
	int w, h;
	ILboolean result;

	/* Quite obvious stuff, just load an image */
	ilGenImages(1, & image_handle);
	ilBindImage(image_handle);
	result = ilLoadImage(parameters->Load_filename);
	if (result == IL_FALSE)
	{
		int error = ilGetError();
		fprintf(stderr, "Error: Something went wrong when loading file '%s' (%s)\n", parameters->Load_filename, iluErrorString(error));
		return error;
	}
	/* If we get image's dimensions, people will believe that we have actually loaded something :-) */
	w = ilGetInteger(IL_IMAGE_WIDTH);
	h = ilGetInteger(IL_IMAGE_HEIGHT);
	if (verbose)
		printf("Loaded '%s', size %dx%d\n", parameters->Load_filename, w, h);
	/* Now let's do our stuff!!! */
	int i;
	for (i = 0; i < parameters->Calls_count; i++)
		perform_operation(parameters->Calls_strings[i], verbose);
	/* our stuff has been done... */

	result = ilSaveImage(parameters->Save_filename);
	if (result == IL_FALSE)
	{
		int error = ilGetError();
		fprintf(stderr, "Error: Something went wrong when saving file '%s' (%s)\n", parameters->Save_filename, iluErrorString(error));
		ilDeleteImages(1, & image_handle);
		return error;
	}
	ilDeleteImages(1, & image_handle);
	return 0;
}
示例#26
0
void readTextures(scene_data* scene, const boost::property_tree::ptree& pt)
{
	boost::property_tree::ptree::const_iterator iter = pt.begin();
	for (; iter != pt.end(); ++iter)
	{
		std::string name = iter->first;
		std::string filename = iter->second.get_value<std::string>();
		ILuint texid;
		ilGenImages(1, &texid);
		ilBindImage(texid);
		ILboolean success = ilLoadImage((wchar_t*)filename.c_str());
		if (success)
		{
			success = ilConvertImage(IL_RGBA, IL_UNSIGNED_BYTE);
			if (!success)
			{
				printf("Error converting %s to RGBA\n", filename);
				ilDeleteImages(1, &texid);
				return;
			}
			GLuint image;
			glGenTextures(1, &image);
			glBindTexture(GL_TEXTURE_2D, image);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
			float maxAnistropy;
			glGetFloatv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &maxAnistropy);
			glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, maxAnistropy);
			glTexImage2D(GL_TEXTURE_2D, 
						 0, 
						 ilGetInteger(IL_IMAGE_BPP),
						 ilGetInteger(IL_IMAGE_WIDTH),
						 ilGetInteger(IL_IMAGE_HEIGHT),
						 0,
						 ilGetInteger(IL_IMAGE_FORMAT),
						 GL_UNSIGNED_BYTE,
						 ilGetData());
			glGenerateMipmap(GL_TEXTURE_2D);
			scene->textures[name] = image;
			ilDeleteImages(1, &texid);
		}
		else
			printf("Error loading file %s\n", filename);
	}
}
void initGraphics() {
		ilGenImages( 1, &ImageName );

		ilBindImage( ImageName );
		glEnable( GL_TEXTURE_2D );
		glEnable( GL_BLEND );
		glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
	
		if (!ilLoadImage( "gamedata/bg-art.png" )) {
			printf("Loading image bg-art failed\n");
		}

		
		gl_tex_id = ilutGLBindTexImage();
		//ilutGLTexImage( gl_tex_id );

		initGamepadDiagram();				
}
示例#28
0
void QTWindow::setupWindow(QTWindow * window, const char * title, const char * imagePath)
{
	ilInit();
	ilLoadImage((const ILstring)imagePath); 

	imageInputWidth  = (int) ilGetInteger(IL_IMAGE_WIDTH);
	imageInputHeight = (int) ilGetInteger(IL_IMAGE_HEIGHT);

	pixmapInput = new BYTE[3 * imageInputWidth * imageInputHeight];

	ilCopyPixels(0, 0, 0, imageInputWidth, imageInputWidth, 1, IL_RGB, IL_UNSIGNED_BYTE, pixmapInput);

	window->setWindowTitle(QString::fromUtf8(title));
    window->resize(imageInputWidth, imageInputHeight);
	QPixmap pm(imagePath);
	window->setPixmap(pm);
	window->show();
}
示例#29
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;
}
示例#30
0
文件: renderer.cpp 项目: adasm/vxc
GLuint Renderer::loadTexture(const std::string &fname)
{
	ILuint imageID;
	GLuint textureID;
	ILboolean success;
	ILenum error;
	ilGenImages(1, &imageID); 
	ilBindImage(imageID); 
	success = ilLoadImage(fname.c_str());
	if (success)
	{
		ILinfo ImageInfo;
		iluGetImageInfo(&ImageInfo);
		if (ImageInfo.Origin == IL_ORIGIN_UPPER_LEFT)
		{
			iluFlipImage();
		}
	
		success = ilConvertImage(IL_RGB, IL_UNSIGNED_BYTE);

		if (!success)
		{
			error = ilGetError();
			return 0;
		}

		glGenTextures(1, &textureID);
		glBindTexture(GL_TEXTURE_2D, textureID);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
		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_FORMAT), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());
	}
	else
	{
		error = ilGetError();
		return 0;
	}

	ilDeleteImages(1, &imageID);
	return textureID;
}