Archived

This topic is now archived and is closed to further replies.

Loading Textures

This topic is 5943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m trying to build a texture using a bitmap i loaded from a resource script in VC++, my code looks like this: BITMAP tex; loadBmpResource(IDB_STEEL, &tex); glTexImage2D(GL_TEXTURE_2D, 0, 3, tex.bmWidth, tex.bmHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, tex.bmBits); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glEnable(GL_TEXTURE_2D); /* drawing code goes here */ the thing is... the texture doesn''t show up on the cube i draw, i think it has a problem with the bmBits field in the BITMAP struct, but i can''t see why not. A little help here... Fooberman~

Share this post


Link to post
Share on other sites
Two possible solutions off the top of my head:

1.) Are you binding your textures (glBindTexture(GL_TEXTURE_2D, texture_id[0])

2.) Are you using glTexCoord2f() when drawing?

~Thek

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Yeah, i''m callign texture coordinates, and i''m not storing it in a texture object thing, so i dont'' need to bind it (it''s the only one). I have functions in there that will read in a bmp file and build the texture and put it in a texture object, and it works fine, except that is not what i want to do. I want to use the images i have in the resource script.

Share this post


Link to post
Share on other sites
First of all, I don''t think that you would want to load your bitmaps from an rc file. Second, I don''t think you can in OpenGL. It will save a lot of headaches if you just use texture objects and manually code the bitmap loading. This is near effortless if you use glaux, but some have a moral objection to it. whatever is easiest for you

Share this post


Link to post
Share on other sites
Bitmaps must be of size 64x64, 128x128, 256x256 etc. for OpenGL to use it. Check your image size, it must be powers of 2 ie. 2,4,8,16,32,64,128...etc. Had the same problem a few days ago...

Share this post


Link to post
Share on other sites
Actually, they must only be powers of two if your video card doesn''t support arbitrary dimensions of textures. It''s best to make them powers of two either way, since a lot of people still have Voodoo 3''s which only support powers of two up to 256x256.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post


Link to post
Share on other sites
I have the following code to get a texture to sphere map from a resource file.

//----------------------------------------------------------------------------------------------------
// LoadBitmapResource:
//
// Loads a bitmap straight from resources
//----------------------------------------------------------------------------------------------------
BYTE* LoadBitmapResource(int iResource, int* iTextureWidth, int* iTextureHeight)
{
// Find the bitmap resource
HINSTANCE hInstance = GetModuleHandle(NULL);
HANDLE hBitmap = LoadBitmap(hInstance, MAKEINTRESOURCE(iResource));

// Get the details
BITMAPINFO bmInfo;
GetObject(hBitmap, sizeof(BITMAPINFO), &bmInfo);
DeleteObject(hBitmap);

// Reload and save a the data
hBitmap = LoadResource(hInstance, FindResource(hInstance,MAKEINTRESOURCE(iResource), RT_BITMAP));
BYTE* pTextureImage = (BYTE*)LockResource(hBitmap);
// Shift the pointer on to the image data itself
pTextureImage += sizeof(BITMAPINFO)-1;

// Save the bitmap dimensions
*iTextureWidth = bmInfo.bmiHeader.biWidth;
*iTextureHeight = bmInfo.bmiHeader.biHeight;

return pTextureImage;
}


//----------------------------------------------------------------------------------------------------
// LoadTexture:
//
// Loads bitmaps and converts them to textures
//----------------------------------------------------------------------------------------------------
bool LoadTexture(int iResource, GLuint* piTexture)
{
// Set up a return value and image storage
bool fSuccessful = false;

// Set the data to catch the bmp resource details
BYTE* pTextureImage = NULL;
int iTextureWidth;
int iTextureHeight;

if (pTextureImage = LoadBitmapResource(iResource, &iTextureWidth, &iTextureHeight))
{
glGenTextures(1, piTexture);

// Create Linear Filtered Texture
glBindTexture(GL_TEXTURE_2D, *piTexture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, 3, iTextureWidth, iTextureHeight, 0, GL_BGR_EXT, GL_UNSIGNED_BYTE, pTextureImage);

// Mark the success
fSuccessful = true;
}

return fSuccessful;
}


This works for me. I am only doing simple demos so I much prefer to have bmps in resource so I can have a stand alone exe/scr etc.

The full example in which this is used is on my site www.knownoffender.btinternet.co.uk - in the transparentblock demo in the openGL bit. All source is there. Hope this helps.

Share this post


Link to post
Share on other sites
Thanks, that helps, now i can see what i''m doing differently. I did get it to work, sorta. Instead of calling glTexImage2D i call the equivalent function that makes mipmap textures, and it works. I think maybe there''s a bug somewhere, compiler, dll file, something, cause they take the two functions take the same data, right?

Chris~

Share this post


Link to post
Share on other sites
It looks like your are having the same problem as the "glTexImage2D gives ''invalid value'' error" thread.

Share this post


Link to post
Share on other sites