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

Texture appears white.

Started by Braden Apr 8, 2005 at 7:19 AM 11 replies 2.8k views
Original Post
Braden
Braden
I am trying to load a texture directly into opengl using the DevIL/OpenIL library. The ilutGLLoatImage() returns successfully, but when it tries to draw the image on the screen it just looks white. Any ideas? Thanks, Braden


GLuint ui_textures[100];

void LoadUI_Image(unsigned long index, char *filename)
{
	GLuint tmp_texture;
	GLint x;
	GLint y;
	
	tmp_texture=ilutGLLoadImage(filename);
	glGenTextures(1,&ui_textures[index]);
	glBindTexture(GL_TEXTURE_RECTANGLE_ARB,ui_textures[index]);
	glGetTexLevelParameteriv(GL_TEXTURE_RECTANGLE_ARB,0,GL_TEXTURE_WIDTH,&x);
	glGetTexLevelParameteriv(GL_TEXTURE_RECTANGLE_ARB,0,GL_TEXTURE_HEIGHT,&y);
	glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,3,x,y,0,GL_RGB,GL_UNSIGNED_BYTE,&tmp_texture);

	glDeleteTextures(1,&tmp_texture);
}


/* ...Inside of function trying to display the texture... */

glBindTexture(GL_TEXTURE_RECTANGLE_ARB,ui_textures[xml[needle].img_index]);
glGetTexLevelParameterfv(GL_TEXTURE_RECTANGLE_ARB,0,GL_TEXTURE_WIDTH,ℑ_size_x);
glGetTexLevelParameterfv(GL_TEXTURE_RECTANGLE_ARB,0,GL_TEXTURE_HEIGHT,ℑ_size_y);
glColor3f(1,1,1);
glEnable(GL_TEXTURE_RECTANGLE_ARB);
glBegin(GL_QUADS);
{
glTexCoord2f(0,0); glVertex2f(x+upperleftX,y+lowerrightY);
glTexCoord2f(0,image_size_y); glVertex2f(x+upperleftX,y+upperleftY);
glTexCoord2f(image_size_x,image_size_y); glVertex2f(x+lowerrightX,y+upperleftY);
glTexCoord2f(image_size_x,0); glVertex2f(x+lowerrightX,y+lowerrightY);
}
glEnd();
glDisable(GL_TEXTURE_RECTANGLE_ARB);


Regards,Braden
Basiror
Basiror
you need to create mipmaps

theres a function glubuildxyz maps search the glu specification on google
http://www.8ung.at/basiror/theironcross.html
Braden
Braden
My texture is not a power of 2 (hence the GL_TEXTURE_RECTANGLE_ARB), so I don't think I can do mipmaps.
Regards,Braden
darookie
darookie
Seems as if your card doesn't support the extension.
_the_phantom_
_the_phantom_
errm.. ilutGLLoadImage() loads an image directly into OpenGL and returns a GL handle to it, glTexImage2D() takes a pointer to the pixel data not an address of a varible with an OpenGL texture handle as its last parameter. You're probably lucky to get getting white and not some random pixels.

I wouldnt be overly shocked if ilutGLLoadImage is resizing your data to a power of two as well.

In short, this way wont work, find a way to load the raw pixel data.
Braden
Braden
That is a very good point. How do I get a pointer to the pixel data? (using opengl functions).
Regards,Braden
jeroenb
jeroenb
OpenGL isnt about loading textures etc into memory. If you want to get the bitmaps data you should make a file loader yourself and use glTexImage2D to insert that data in the texture (which is the required extensions are support, doesnt have to be a power of 2).
Crafter 2D: the open source 2D game framework ?Github: https://github.com/crafter2d/crafter2d
Twitter: [twitter]crafter_2d[/twitter]
Braden
Braden
Jeroenb,

Huh? That is not relevant to this topic.

I am wondering if there is an opengl function which can return a pointer to the pixel data or something of that nature.
Regards,Braden
_the_phantom_
_the_phantom_
yeah, there is, glGetTexImage() is the function you are after.

However, i'm not convinced it will help as chances are that ilutGLLoadImage() call is going to resize the image to a power of two at best and at worse the texture upload will fail and you'll get nowt back.

As jeroenb says, you are better off loading it as raw pixel data and uploading it yourself than trying to bend IL and GL to some arcane purpose.
Braden
Braden
hehehe. I like how you put that. Alright, I will re-think my design.
Regards,Braden
Hobitz
Hobitz
Well I don't see a problem with devil.
You can load whatever you want and then get that pixel data from mem by
calling ilGetData();
Also you probably should need this:
ilGetInteger(IL_IMAGE_BYTES_PER_PIXEL);
ilGetInteger(IL_IMAGE_WIDTH);
ilGetInteger(IL_IMAGE_HEIGHT);
to make an actually ogl texture.
Hope it helps.
_the_phantom_
_the_phantom_
as long as it doesnt do any resizing under the hood, then yes DevIL would be fine to loading the image data, however in this instance the useage of ilutGLLoadImage() which loads and uploads a texture to OGL probably does some resizing work under the hood
Hobitz
Hobitz
Yes but why then not to use ilLoadImage() or even ilLoadL()
I think these are not resizing anything unless you resize texture by yourself.

Topic Locked

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

Sign in to reply to this topic.