void QtInterface::initializeGL() 
{
    qDebug("GL Init");

	if ( ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
		 iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION ||
		 ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION) {
			printf("DevIL version is different...exiting!\n");
			Engine()->Stop();
	} 

	ilInit();
	iluInit();
	ilutInit();
	ilutRenderer( ILUT_OPENGL );

	// Enable alpha
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);	
	glEnable(GL_BLEND);		
	glAlphaFunc(GL_GREATER,0.1);
	glDisable(GL_ALPHA_TEST);

	glDisable( GL_DEPTH_TEST );

    /*
	// By checking this, we can enable some more efficient ways of rendering sprites
	if ( glh_extension_supported("GL_NV_texture_rectangle") )
	{
		qDebug("NV texture rectangle supported!");
		//glEnable( GL_TEXTURE_RECTANGLE_NV );
	}
	else if ( glh_extension_supported("GL_EXT_texture_rectangle") )
	{
		qDebug("EXT texture rectangle supported!");
		//glEnable( GL_TEXTURE_RECTANGLE_EXT );
	}
	else
	{
		qDebug("No texture rectangle support");
	}
    */

	//TODO: Engine()->Precache();

    /*
    int width=1020, height=768;
    glViewport(0,0, (GLsizei)width, (GLsizei)height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(60, (GLfloat)width / (GLfloat)height, 1.0f, 100.0f);
    glMatrixMode(GL_MODELVIEW);
    */
    glClearColor(0,0,0,0);
	//glClearColor(1.0f, 0.0f, 0.0f, 1.0f);
    setFocusPolicy(Qt::StrongFocus);
    m_flFPS = 0.0f;
    m_flLastTime = 0.0f;
}
Пример #2
0
int main(int argc, char **argv)
{
	ILuint	ImgId;
	ILenum	Error;
	char	*Data;
	long	Size;

	// We use the filename specified in the first argument of the command-line.
	if (argc < 3) {
		printf("Please specify a .rar file and file inside to open.\n");
		return 1;
	}

	// Check if the shared lib's version matches the executable's version.
	if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
		iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
		printf("DevIL version is different...exiting!\n");
		return 2;
	}

	// Initialize DevIL.
	ilInit();
	// Generate the main image name to use.
	ilGenImages(1, &ImgId);
	// Bind this image name.
	ilBindImage(ImgId);

	if (!urarlib_get(&Data, &Size, argv[2], argv[1], "none")) {
		printf("Error loading .rar file.\n");
		return 3;
	} 

	// Loads the image specified by File into the image named by ImgId.
	ilLoadL(IL_TGA, Data, Size);

	// Display the image's dimensions to the end user.
	printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n", ilGetInteger(IL_IMAGE_WIDTH),
		ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_DEPTH), ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL));

	// Enable this to let us overwrite the destination file if it already exists.
	ilEnable(IL_FILE_OVERWRITE);

	// If argv[2] is present, we save to this filename, else we save to test.tga.
	if (argc > 2)
		ilSaveImage(argv[3]);
	else
		ilSaveImage("test.tga");

	// We're done with the image, so let's delete it.
	ilDeleteImages(1, &ImgId);

	// Simple Error detection loop that displays the Error to the user in a human-readable form.
	while ((Error = ilGetError())) {
		printf("Error: %s\n", iluErrorString(Error));
	}

	return 0;
}
Пример #3
0
int main(int argc, char** argv)
{
	// No filename is specified on the command-line.
	if (argc < 2) {
		printf ("Please run as:\n\nDevIL_testGL image_filename\n");
		return 1;
	}
	FileName = argv[1];  // Set filename equal to the first argument.

	//
	// Check if the shared lib's version matches the executable's version.
	//



//
// fixed to get the right numbers from the right library call...
//
	if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
		iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION ||
		ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION) {
		printf ("DevIL library is out of date! Please upgrade\n");
		return 2;
	}

	// Needed to initialize DevIL.
	ilInit ();
	iluInit();

	// GL cannot use palettes anyway, so convert early.
	ilEnable (IL_CONV_PAL);

	// Gets rid of dithering on some nVidia-based cards.
	ilutEnable (ILUT_OPENGL_CONV);

	// Generate the main image name to use.
	ilGenImages (1, &ImgId);
	
	// Bind this image name.
	ilBindImage (ImgId);

	// Loads the image specified by File into the ImgId image.
	if (!ilLoadImage(FileName)) {
		HandleDevILErrors ();
	}

	// Make sure the window is in the same proportions as the image.
	//  Generate the appropriate width x height less than or equal to MAX_X x MAX_Y.
	//	Instead of just clipping Width x Height to MAX_X x MAX_Y, we scale to
	//	an appropriate size, so the image isn't stretched/squished.
	Width  = ilGetInteger (IL_IMAGE_WIDTH);
	Height = ilGetInteger (IL_IMAGE_HEIGHT);
	
	if (Width > 0) {  // Don't want a divide by 0...
		if (Width > MAX_X) {
			Width = MAX_X;
			Height = (ILuint)(MAX_X / (ILfloat)ilGetInteger(IL_IMAGE_WIDTH) * Height);
		}
	}
	if (Height > 0) {  // Don't want a divide by 0...
		if (Height > MAX_Y) {
			Height = MAX_Y;
			Width = (ILuint)(MAX_Y / (ILfloat)ilGetInteger(IL_IMAGE_HEIGHT) * Width);
		}
	}

	HandleDevILErrors ();

	// Standard glut initializations.
	glutInit               (&argc, argv);  // Standard glut initialization.
	glutInitDisplayMode    (GLUT_RGB | GLUT_DOUBLE);
	glutInitWindowPosition (100, 100);
	glutInitWindowSize     (Width, Height);
	
	window = glutCreateWindow("Developer's Image Library (DevIL) Test");

	ilutInit();

	glutDisplayFunc  (DisplayFunc);
	glutKeyboardFunc (KeyboardFunc);

	// Goes into our setup function.
	if (Setup() == IL_FALSE)
		return 1;

	// Enter the main (Free)GLUT processing loop
	glutMainLoop();

	// Clean up any loose ends.
	CleanUp();

	return 0;
}
Пример #4
0
int main(int argc, char **argv)
{
	ILuint	ImgId;
	ILenum	Error;

	// We use the filename specified in the first argument of the command-line.
	if (argc < 2) {
		fprintf(stderr, "DevIL_test : DevIL simple command line application.\n");
		fprintf(stderr, "Usage : DevIL_test <file> [output]\n");
		fprintf(stderr, "Default output is test.tga\n");
		return 1;
	}

	// Check if the shared lib's version matches the executable's version.
	if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
		iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
		printf("DevIL version is different...exiting!\n");
		return 2;
	}

	// Initialize DevIL.
	ilInit();

	// Generate the main image name to use.
	ilGenImages(1, &ImgId);

	// Bind this image name.
	ilBindImage(ImgId);

	// Loads the image specified by File into the image named by ImgId.
	if (!ilLoadImage(argv[1])) {
		printf("Could not open file...exiting.\n");
		return 3;
	}

	// Display the image's dimensions to the end user.
	printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n",
	       ilGetInteger(IL_IMAGE_WIDTH),
	       ilGetInteger(IL_IMAGE_HEIGHT),
	       ilGetInteger(IL_IMAGE_DEPTH),
	       ilGetInteger(IL_IMAGE_BITS_PER_PIXEL));

	// Enable this to let us overwrite the destination file if it already exists.
	ilEnable(IL_FILE_OVERWRITE);

	// If argv[2] is present, we save to this filename, else we save to test.tga.
	if (argc > 2)
		ilSaveImage(argv[2]);
	else
		ilSaveImage("test.tga");

	// We're done with the image, so let's delete it.
	ilDeleteImages(1, &ImgId);

	// Simple Error detection loop that displays the Error to the user in a human-readable form.
	while ((Error = ilGetError())) {
		printf("Error: %s\n", iluErrorString(Error));
	}

	return 0;

}
Пример #5
0
/* inicjuje 
 * -oswietlenie
 * -cieniowanie
 * -biblioteke glut
 * -wspolprace z systemem okienkowym
 */
void init()
{   
   GLenum err = glewInit();
	if (GLEW_OK != err)
	{
		std::cout << "GLEW initialisation error: " << glewGetErrorString(err) << std::endl;
		exit(-1);
	}
	std::cout << "GLEW intialised successfully. Using GLEW version: " << glewGetString(GLEW_VERSION) << std::endl;
 


    GLfloat mat_ambient[]    = { 1.0, 1.0,  1.0, 1.0 };
	GLfloat mat_diffuse[]    = { 0.5, 0.5,  0.5, 1.0 };
    GLfloat mat_specular[]   = { 1.0, 1.0,  1.0, 1.0 };
    GLfloat light1_position[] = { 10.0,		5.0,	10.0,	1.0 };
	GLfloat light2_position[] = { -10.0,	10.0,	-10.0,	1.0 };
	GLfloat light3_position[] = { 10.0,		10.0,	-10.0,	1.0 };
	GLfloat light4_position[] = { -10.0,	10.0,	10.0,	1.0 };
    GLfloat lm_ambient[]     = { 0.2, 0.2,  0.2, 1.0 };

    glMaterialfv( GL_FRONT, GL_AMBIENT, mat_ambient );
    glMaterialfv( GL_FRONT, GL_SPECULAR, mat_specular );
    glMaterialf( GL_FRONT, GL_SHININESS, 50.0 );
    glLightfv( GL_LIGHT0, GL_POSITION, light1_position );
		glLightfv( GL_LIGHT1, GL_POSITION, light2_position );
		glLightfv(GL_LIGHT1, GL_DIFFUSE, mat_diffuse);
		glLightfv( GL_LIGHT2, GL_POSITION, light3_position );
		glLightfv(GL_LIGHT2, GL_DIFFUSE, mat_diffuse);
		glLightfv( GL_LIGHT3, GL_POSITION, light4_position );
		glLightfv(GL_LIGHT3, GL_DIFFUSE, mat_diffuse);
    glLightModelfv( GL_LIGHT_MODEL_AMBIENT, lm_ambient );
    
	glEnable(GL_NORMALIZE);

    glShadeModel( GL_SMOOTH );													// obliczanie swiatla 
	
    glEnable( GL_LIGHTING );
    glEnable( GL_LIGHT0 );
	glEnable( GL_LIGHT1 );
	glEnable( GL_LIGHT2 );
	glEnable( GL_LIGHT3 );

    glDepthFunc( GL_LESS );
    glEnable( GL_DEPTH_TEST );
	//glBlendFunc (GL_SRC_ALPHA, GL_ONE);


	// DevIL sanity check
	if ( (iluGetInteger(IL_VERSION_NUM) < IL_VERSION) || (iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) || (ilutGetInteger(ILUT_VERSION_NUM) < ILUT_VERSION) )
	{
		std::cout << "DevIL versions are different... Exiting." << std::endl;
		exit(-1);
	}
	

	// Initialise all DevIL functionality
	ilInit();
	iluInit();
	ilutInit();
	ilutRenderer(ILUT_OPENGL);	// Tell DevIL that we're using OpenGL for our rendering

}
//Load----------------------------------------------------------------------
bool TextureItem::Load( GLuint minFilter, GLuint maxFilter, bool forceMipmap, bool resizeIfNeeded )
{
    /** NOTE: This is a test of using an archive file.  This will need to
        be modified to allow direct file access, or archived file access.
    */
    ArchiveFile* file = ArchiveManager::GetSingleton().CreateArchiveFile( mImageFileName );
    if ( file )
    {
        UInt32 fileSize = file->Length();
        unsigned char* buf = new unsigned char [ fileSize ];
        if ( !buf )
        {
            delete file;
            return false;
        }
        file->Read( buf, fileSize );

        // Load the texture:

        //****
        ilInit();
        iluInit();

        // Make sure the DevIL version is valid:
        if ( ilGetInteger( IL_VERSION_NUM ) < IL_VERSION || iluGetInteger( ILU_VERSION_NUM ) < ILU_VERSION )
        {
            // Invalid version...
            delete file;
            delete buf;
            return false;
        }


        // Get the decompressed data
        ILuint imageID;
        ilGenImages( 1, &imageID );
        ilBindImage( imageID );
        //if ( ilLoadImage( const_cast< char* >( mImageFileName.c_str() ) ) )
        if ( ilLoadL( IL_TYPE_UNKNOWN, buf, fileSize ) )
        {
            // Convert the image to unsigned bytes:
            ilConvertImage( IL_RGBA, IL_UNSIGNED_BYTE );

            // Generate the GL texture
            glGenTextures( 1, &mTextureID );
            glBindTexture( GL_TEXTURE_2D, mTextureID );
            mWidth  = ilGetInteger( IL_IMAGE_WIDTH );
            mHeight = ilGetInteger( IL_IMAGE_HEIGHT );
            mOriginalWidth  = mWidth;
            mOriginalHeight = mHeight;

            // OpenGL will work better with textures that have dimensions
            // that are a power of 2.  If doing a scrolling tile map, then
            // this is pretty much a necessity.  However, there are times
            // when using a mipmap instead is perfectly fine (ie, when NOT
            // doing tiles, or in cases where we might be running out of
            // video memory...
            if ( resizeIfNeeded && !forceMipmap )
            {
                UInt32 newWidth = mWidth, newHeight = mHeight;
                if ( !Math::IsPowerOf2( mWidth ) )
                {
                    // Find the next power of 2:
                    newWidth = Math::FindNextPowerOf2( mWidth );
                }

                if ( !Math::IsPowerOf2( mHeight ) )
                {
                    // Find the next power of 2:
                    newHeight = Math::FindNextPowerOf2( mHeight );
                }

                if ( newWidth != mWidth || newHeight != mHeight )
                {
                    // Resize the canvas:
                    ilClearColor( 0, 0, 0, 0 );
                    iluImageParameter( ILU_PLACEMENT, ILU_UPPER_LEFT );
                    iluEnlargeCanvas( newWidth, newHeight, ilGetInteger( IL_IMAGE_DEPTH ) );
                    mWidth  = ilGetInteger( IL_IMAGE_WIDTH );
                    mHeight = ilGetInteger( IL_IMAGE_HEIGHT );
                }
            }

            // If forcing mipmap generation, or if the size is not a power of 2,
            // generate as mipmaps
            if ( forceMipmap || !Math::IsPowerOf2( mWidth ) || !Math::IsPowerOf2( mHeight ) )
            {
                gluBuild2DMipmaps( GL_TEXTURE_2D,
                                   ilGetInteger( IL_IMAGE_BPP ),
                                   mWidth,
                                   mHeight,
                                   ilGetInteger( IL_IMAGE_FORMAT ),
                                   GL_UNSIGNED_BYTE,
                                   ilGetData() );
            }
            else
            {
                glTexImage2D(   GL_TEXTURE_2D,
                                0,
                                ilGetInteger( IL_IMAGE_BPP ),
                                mWidth,
                                mHeight,
                                0,
                                ilGetInteger( IL_IMAGE_FORMAT ),
                                GL_UNSIGNED_BYTE,
                                ilGetData() );
            }

            // Set the minification and magnification filters
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, minFilter );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, maxFilter );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP );
            glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP );

            mIsLoaded = true;
        }
        else
        {
            ILenum error;
            error = ilGetError();
            //std::string errString = iluErrorString( error );
        }

        ilDeleteImages( 1, &imageID );

        //***

        // Free memory:
        delete buf;
        delete file;
    }
    else
        return false;

    return true;
}
Пример #7
0
int main(int argc, char **argv)
{
    ILuint	ImgId;
    ILenum	Error;

    // We use the filename specified in the first argument of the command-line.
    if (argc < 2) {
        printf("Please specify a file to open.\n");
        return 1;
    }

    // Check if the shared lib's version matches the executable's version.
    if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
            iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
        printf("DevIL version is different...exiting!\n");
        return 2;
    }

    // Initialize DevIL.
    ilInit();


    // Set the loading function here.
    ilRegisterLoad("xxx", LoadFunction);


    // Generate the main image name to use.
    ilGenImages(1, &ImgId);
    // Bind this image name.
    ilBindImage(ImgId);
    // Loads the image specified by File into the image named by ImgId.
    if (!ilLoadImage(argv[1])) {
        printf("Could not open file...exiting.\n");
        return 3;
    }

    // Display the image's dimensions to the end user.
    printf("Width: %d  Height: %d  Depth: %d  Bpp: %d\n", ilGetInteger(IL_IMAGE_WIDTH),
           ilGetInteger(IL_IMAGE_HEIGHT), ilGetInteger(IL_IMAGE_DEPTH), ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL));

    // Enable this to let us overwrite the destination file if it already exists.
    ilEnable(IL_FILE_OVERWRITE);

    // If argv[2] is present, we save to this filename, else we save to test.tga.
    if (argc > 2)
        ilSaveImage(argv[2]);
    else
        ilSaveImage("test.tga");


    // Remove the loading function when we're done using it or want to change it.
    //  This isn't required here, since we're exiting, but here's how it's done:
    ilRemoveLoad("xxx");


    // We're done with the image, so let's delete it.
    ilDeleteImages(1, &ImgId);

    // Simple Error detection loop that displays the Error to the user in a human-readable form.
    while ((Error = ilGetError())) {
        printf("Error: %s\n", iluErrorString(Error));
    }

    return 0;
}