コード例 #1
0
ファイル: navi_heightmap.cpp プロジェクト: nadult/FreeFT
void NaviHeightmap::saveLevels() const {
	for(int n = 0; n < m_level_count; n++) {
		Texture tex = toTexture(n);
		char name[100];
		sprintf(name, "level%d.tga", n);
		Saver(name) << tex;
	}
}
コード例 #2
0
ファイル: Image.cpp プロジェクト: LudoSapiens/Dev
//------------------------------------------------------------------------------
//!
void
Image::createTexture()
{
   if( _bitmap.isNull() ) return;

   RCP<Bitmap> bmp = _bitmap;
   // No support for 3 channels.
   if( bmp->numChannels() == 3 )
   {
      bmp = BitmapManipulator::addAlpha( *bmp, 1.0f );
   }

   uint width  = bmp->dimension().x;
   uint height = bmp->dimension().y;
   uint depth  = bmp->dimension().z;

   // Currently force power-of-2 size.
   uint p2_width  = CGM::nextPow2( width );
   uint p2_height = CGM::nextPow2( height );

   // Convert to texture format.
   Gfx::TextureFormat fmt;
   Gfx::TextureChannels ch;
   toTexture( bmp, fmt, ch );

   // Create texture.
   if( _texture.isNull() || !suitable( *_texture, *bmp, p2_width, p2_height, depth, fmt, ch ) )
   {
      switch( bmp->dimType() )
      {
         case Bitmap::DIM_2D:
            _texture = Core::gfx()->create2DTexture( p2_width, p2_height, fmt, ch, Gfx::TEX_FLAGS_MIPMAPPED );
            break;
         case Bitmap::DIM_CUBEMAP:
            _texture = Core::gfx()->createCubeTexture( p2_width, fmt, ch, Gfx::TEX_FLAGS_MIPMAPPED );
            break;
         case Bitmap::DIM_2D_ARRAY:
            //_texture = Core::gfx()->create2DArrayTexture( p2_width, p2_height, depth, fmt, ch, Gfx::TEX_FLAGS_MIPMAPPED );
            break;
         case Bitmap::DIM_3D:
            _texture = Core::gfx()->create3DTexture( p2_width, p2_height, depth, fmt, ch, Gfx::TEX_FLAGS_MIPMAPPED );
            break;
      }
   }

   // Temporary code to clear around texture.
   if( width < p2_width || height < p2_height )
   {
      size_t tmpSize = CGM::max( width, height ) * bmp->pixelSize();
      Vector<uchar> tmpBuffer( tmpSize, 0 );

      if( height < p2_height && height != _texture->definedWidth() )
         Core::gfx()->setData( _texture, 0, 0, height, width, 1, tmpBuffer.data() );
      if( width < p2_width  && width != _texture->definedHeight() )
         Core::gfx()->setData( _texture, 0, width, 0, 1, height, tmpBuffer.data() );
   }

   _texture->definedRegionX().reset();
   _texture->definedRegionY().reset();

   switch( bmp->dimType() )
   {
      case Bitmap::DIM_2D:
         Core::gfx()->setData( _texture, 0, 0, 0, width, height, bmp->pixels() );
         break;
      case Bitmap::DIM_CUBEMAP:
         Core::gfx()->setData( _texture, 0, Gfx::TEX_SLICE_NEG_X, bmp->pixels(0) );
         Core::gfx()->setData( _texture, 0, Gfx::TEX_SLICE_POS_X, bmp->pixels(1) );
         Core::gfx()->setData( _texture, 0, Gfx::TEX_SLICE_NEG_Y, bmp->pixels(2) );
         Core::gfx()->setData( _texture, 0, Gfx::TEX_SLICE_POS_Y, bmp->pixels(3) );
         Core::gfx()->setData( _texture, 0, Gfx::TEX_SLICE_NEG_Z, bmp->pixels(4) );
         Core::gfx()->setData( _texture, 0, Gfx::TEX_SLICE_POS_Z, bmp->pixels(5) );
         break;
      case Bitmap::DIM_2D_ARRAY:
         for( uint s = 0; s < depth; ++s )
         {
            Core::gfx()->setData( _texture, 0, s, 0, 0, width, height, bmp->pixels(s) );
         }
         break;
      case Bitmap::DIM_3D:
         Core::gfx()->setData( _texture, 0, 0, 0, 0, width, height, depth, bmp->pixels() );
         break;
   }
   Core::gfx()->generateMipmaps( _texture );

   // Should we delete the image?
   _needUpdate = false;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: myst6re/vincent-tim
int main(int argc, char *argv[])
{
	QCoreApplication a(argc, argv);
	QCoreApplication::setApplicationName("Vincent Tim");
	QCoreApplication::setApplicationVersion("1.2");
#ifdef Q_OS_WIN
	QTextCodec::setCodecForLocale(QTextCodec::codecForName("IBM 850"));
#endif
	
#ifdef TESTS_ENABLED
	qDebug() << "Running tests...";
	
	Collect c("tests/tim/files");
	c.textureData("tim");
#endif

	Arguments args;

	if (args.help() || args.paths().isEmpty()) {
		args.showHelp();
	} else {
		foreach (const QString &path, args.paths()) {
			TextureFile *texture;

			if (args.inputFormat(path) == args.outputFormat()) {
				qWarning() << "Error: input and output formats are not different";
				a.exit(1);
			}

			QFile f(path);
			if (f.open(QIODevice::ReadOnly)) {

				if (!args.analysis()) {
					texture = TextureFile::factory(args.inputFormat(path));

					if (texture->open(f.readAll())) {
						if (TextureFile::supportedTextureFormats().contains(args.outputFormat(), Qt::CaseInsensitive)) {
							if (!toTexture(texture, path, args)) {
								break;
							}
						} else if (TextureFile::supportedTextureFormats().contains(args.inputFormat(path), Qt::CaseInsensitive)) {
							fromTexture(texture, path, args);
						} else {
							qWarning() << "Error: input format or output format must be a supported texture format" << TextureFile::supportedTextureFormats();
							a.exit(1);
						}
					} else {
						qWarning() << "Error: Cannot open Texture file";
						a.exit(1);
					}

					f.close();

					delete texture;
				} else { // Search tim files
					QList<PosSize> positions = TimFile::findTims(&f);

					int num = 0;
					foreach (const PosSize &pos, positions) {
						texture = new TimFile();
						f.seek(pos.first);
						if (texture->open(f.read(pos.second))) {
							if (args.outputFormat().compare("tim", Qt::CaseInsensitive) == 0) {
								if (!texture->saveToFile(args.destination(path, num))) {
									qWarning() << "Error: Cannot save Texture file from" << QDir::toNativeSeparators(path) << "to" << args.destination(path, num);
									continue;
								} else {
									printf("%s\n", qPrintable(QDir::toNativeSeparators(args.destination(path, num))));
								}
							} else {
								fromTexture(texture, path, args, num);
							}
							num++;
						} else {
							qWarning() << "Error: Cannot open Texture file from" << QDir::toNativeSeparators(path);
							a.exit(1);
						}
						delete texture;
					}
				}
			} else {
				qWarning() << "Error: cannot open file" << QDir::toNativeSeparators(path) << f.errorString();
				a.exit(1);
			}
		}
コード例 #4
0
void drawText(const std::string &s,double x,double y,double z,const float *modelview,const float *projection) {
    // init textures and shader (shaders are made the first time only; texture is built each time)
    int width,height;
    GLuint texId=toTexture(s,&width,&height);

    initTextShader();

    // compute the square vertices
    GLint viewport[4];
    glGetIntegerv(GL_VIEWPORT,viewport);


    float fwidth=2.0*width/viewport[2]; // width in NDC
    float fheight=2.0*height/viewport[3]; // height in NDC
    float posx=x;
    float posy=y;
    float posz=z;
    if (modelview) { // transform by modelview
        float posw=modelview[3]*x+modelview[7]*y+modelview[11]*z+modelview[15];
        posx=(modelview[0]*x+modelview[4]*y+modelview[8]*z+modelview[12])/posw;
        posy=(modelview[1]*x+modelview[5]*y+modelview[9]*z+modelview[13])/posw;
        posz=(modelview[2]*x+modelview[6]*y+modelview[10]*z+modelview[14])/posw;
    }
    vector<float> vertex= {posx,posy+fheight,posz,0,0,
                           posx,posy,posz,0,1,
                           posx+fwidth,posy+fheight,posz,1,0,
                           posx+fwidth,posy,posz,1,1
                          };
    // vertex to gl : TODO : generate once (then SubBufferData)


    GLuint vbuffer;
    glGenVertexArrays(1,&_textVAO);
    glBindVertexArray(_textVAO);
    glGenBuffers(1,&vbuffer);
    glBindBuffer(GL_ARRAY_BUFFER,vbuffer);
    glBufferData(GL_ARRAY_BUFFER,vertex.size()*sizeof(float),vertex.data(),GL_STREAM_DRAW);


    // draw (uniform setup)
    glUseProgram(_textShaderP);
    glUniform1i(glGetUniformLocation(_textShaderP,"texture0"),0);
    if (projection) {
        glUniformMatrix4fv(glGetUniformLocation(_textShaderP,"projection"),1,GL_FALSE,projection);
    }
    else {
        float identity[]= {1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1};
        glUniformMatrix4fv(glGetUniformLocation(_textShaderP,"projection"),1,GL_FALSE,identity);
    }

    // draw (attribute setup)
    glEnableVertexAttribArray(0);
    glEnableVertexAttribArray(1);
    glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,5*sizeof(GLfloat),NULL);
    glVertexAttribPointer(1,2,GL_FLOAT,GL_FALSE,5*sizeof(GLfloat),(GLvoid *)(3*sizeof(GLfloat)));
    // draw
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
    glDrawArrays(GL_TRIANGLE_STRIP,0,4);


    glDisable(GL_BLEND);
    glDisableVertexAttribArray(0);
    glDisableVertexAttribArray(1);

    glDeleteBuffers(1,&vbuffer);
    glUseProgram(0);
    glBindVertexArray(0);
    glDeleteTextures(1,&texId);
    glDeleteVertexArrays(1,&_textVAO);
}