Jump to content

  • Log In with Google      Sign In   
  • Create Account

Loading Textures


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Fooberman   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 October 2001 - 06:23 PM

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~

Sponsor:

#2 Reverse_Gecko   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 October 2001 - 06:26 PM

tough question......

"A cow, now that cuold be useful" - Conker(Conkers BFD for N64)

#3 Thek   Members   -  Reputation: 122

Like
Likes
Like

Posted 06 October 2001 - 06:28 PM

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

#4 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

Posted 06 October 2001 - 06:33 PM

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.

#5 masonium   Members   -  Reputation: 118

Like
Likes
Like

Posted 06 October 2001 - 09:21 PM

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

#6 iONiC   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 October 2001 - 10:29 AM

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...

#7 Null and Void   Moderators   -  Reputation: 1087

Like
Likes
Like

Posted 09 October 2001 - 11:07 AM

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!]

#8 Gillies   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 October 2001 - 11:28 AM

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.

#9 Fooberman   Members   -  Reputation: 122

Like
Likes
Like

Posted 09 October 2001 - 01:40 PM

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~

#10 Gillies   Members   -  Reputation: 122

Like
Likes
Like

Posted 10 October 2001 - 12:02 AM

It looks like your are having the same problem as the "glTexImage2D gives ''invalid value'' error" thread.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS