Skip to main content
GameDev.net gamedev.net
🔒 Locked

DevIL without GLUT = bad?

Started by McZ Mar 30, 2006 at 7:53 AM 4 replies 1.5k views
Original Post
McZ
McZ
I'm trying to write my own 3D engine without using GLUT... But it failes when I try to load an image with DevIL Top image is a screenshot with Win32 code and no glut lower image is from my GLUT engine.. the texture files are the same and is in JPG format. this is how I do in the non GLUT engine

ILuint	ilImage;

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

const bool loaded = ilLoadImage( (const ILstring)FileName.c_str() ) == 1;

if( !loaded )
{
	CLog::errorMessage( "Failed to load texture %s", FileName.c_str() );
	return NULL;
}

ILenum ilFormat = IL_RGB;

if( ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) == 32 )
	ilFormat = IL_RGBA;

const bool converted = ilConvertImage( ilFormat, IL_UNSIGNED_BYTE ) == 1;

if( !converted )
{
	CLog::errorMessage("Failed to convert image data for texture %s", FileName.c_str() );
	return NULL;
}

GLenum target	= GL_TEXTURE_2D;
GLint MagFilter = GL_LINEAR;
GLint MinFilter = GL_LINEAR;
GLint format	= GL_RGB;

if( ilFormat == IL_RGBA )
	format = GL_RGBA;

glGenTextures( 1, &tu->m_iTextureID );
glBindTexture( target, tu->m_iTextureID );

// Set texture filter
glTexParameteri(target, GL_TEXTURE_MAG_FILTER, MagFilter); 
glTexParameteri(target, GL_TEXTURE_MIN_FILTER, MinFilter);

// Upload image data
glTexImage2D(target, 0, ilGetInteger(IL_IMAGE_BPP), ilGetInteger(IL_IMAGE_WIDTH), ilGetInteger(IL_IMAGE_HEIGHT), 0, ilGetInteger(IL_IMAGE_FORMAT), GL_UNSIGNED_BYTE, ilGetData());

ilDeleteImages( 1, &ilImage );

I have tried with ilut and I got the same result.

ilutInit();

tu->m_iTextureID = ilutGLLoadImage((ILstring)FileName.c_str());

subi
subi
how where you loading the images when u where using glut?
McZ
McZ
oh.. forgot to write that, I'm using the ilut version in GLUT.
Bradsco
Bradsco
When do you load the images? I can't say for sure, but I believe if you're trying to load the images before you've created your OpenGL context, it might fail.
I set the clouds in motion, turn up light and sound...Activate the window, and watch the world go 'round
hplus0603
hplus0603
The OpenGL context needs to be created and made current before you can load images as textures.
enum Bool { True, False, FileNotFound };
mrbastard
mrbastard
You may have to have a valid GL context before initialising IL or setting the ILUT renderer to ILUT_OPENGL.
[size="1"]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.