Skip to main content
gamedev.net
🔒 Locked

Loading Textures

Started by Fooberman Oct 7, 2001 at 12:23 AM 8 replies 1k views
Original Post
Fooberman
Fooberman
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~
Reverse_Gecko
Reverse_Gecko
tough question......

"A cow, now that cuold be useful" - Conker(Conkers BFD for N64)
Jeff Bland (Reverse_Gecko)reversegecko@gmail.com
Thek
Thek
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
"There are three kinds of people in the world: those who can count, and those who can't."
masonium
masonium
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
iONiC
iONiC
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...
Gillies
Gillies
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.
Fooberman
Fooberman
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~
Gillies
Gillies
It looks like your are having the same problem as the "glTexImage2D gives ''invalid value'' error" thread.

Topic Locked

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

Sign in to reply to this topic.