Jump to content
  • Advertisement
Sign in to follow this  

Extracting textures from large bmps

This topic is 4813 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

hiya, Is there a way to extract a 16x16 piece of a larger BMP picture that I can use as a texture?? The only way I know how to do it as of now is to load the entire BMP and figure out what part of it to draw in my Render() method. The issue I have is that I need to change the texture (which is being used by many tiles in my 2D game). So I figured if I need to change it (making part of the texture transparent later in the game) I would have to make more than one copy of the texture so every object's texture would not change, only the one I want to change. anyways, if you can help me I'd be very thankful.

Share this post

Link to post
Share on other sites
load the bitmap, create a texture object and initalise it with glTexImage() to 16x16 in size and NULL for the data location and then use glSubTeximage() to select the correct 16x16 image from the bitmap and copy it into the texture.

job done.

Share this post

Link to post
Share on other sites
Take a look at This also if you are having trouble. It deals with isolating areas in a larger texture so that smaller textures could be created.

Share this post

Link to post
Share on other sites
Is glSubTexImage() a well-known function??? I searched google and found nothing useful, and when I try to build my prog it gives me
Desktop\OpenGL\GorillaTesting\video.cpp(124): error C3861: 'glSubTexImage': identifier not found, even with argument-dependent lookup
I'm not sure what arguements that function takes anyhow...

Share this post

Link to post
Share on other sites
Now I have a question... how do I select the 16x16 region I wish to use for the texture. Do I use that xoffset and yoffset values for this?? If so, which corner is 0,0??

BTW, thanks so much for all these links!!

Share this post

Link to post
Share on other sites

glTexSubImage2D - specify a two-dimensional texture subimage

void glTexSubImage2D( GLenum target,
GLint level,
GLint xoffset,
GLint yoffset,
GLsizei width,
GLsizei height,
GLenum format,
GLenum type,
const GLvoid *pixels )

target Specifies the target texture. Must be GL_TEXTURE_2D.

level Specifies the level-of-detail number. Level 0 is the base
image level. Level n is the nth mipmap reduction image.

xoffset Specifies a texel offset in the x direction within the texture

yoffset Specifies a texel offset in the y direction within the texture

width Specifies the width of the texture subimage.

height Specifies the height of the texture subimage.

format Specifies the of the pixel data. The following symbolic val-
ues are accepted: GL_COLOR_INDEX, GL_RED, GL_GREEN, GL_BLUE,

type Specifies the data type of the pixel data. The following sym-
bolic values are accepted: GL_UNSIGNED_BYTE, GL_BYTE,
GL_UNSIGNED_INT_8_8_8_8_REV, GL_UNSIGNED_INT_10_10_10_2, and

pixels Specifies a pointer to the image data in memory.

Texturing maps a portion of a specified texture image onto each graphi-
cal primitive for which texturing is enabled. To enable and disable
two-dimensional texturing, call glEnable and glDisable with argument

glTexSubImage2D redefines a contiguous subregion of an existing two-
dimensional texture image. The texels referenced by pixels replace the
portion of the existing texture array with x indices xoffset and xoff-
set+width−1, inclusive, and y indices yoffset and yoffset+height−1,
inclusive. This region may not include any texels outside the range of
the texture array as it was originally specified. It is not an error
to specify a subtexture with zero width or height, but such a specifi-
cation has no effect.

Share this post

Link to post
Share on other sites
The xoffset and yoffset part is confusing me to no end.
I have stored the coords of the correct portion of the BMP in my Sprite class, so how do I use this in the glTexSubImage2D() function?? I also have no idea how to copy this data into the texture, as instructed by the 1st reply...

I guess I'll take a break. I obviously am slow.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!