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

Recommended Posts

Hello, how can I load a part of a bitmap? I have an 800 x 600 bitmap image and I only want to load half of it. I tried loading it like this: gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 400, 300, GL_BGR_EXT, GL_UNSIGNED_BYTE, TextureImg[0]->pixels); but when I rendered the scene the texture looked like it was zoomed into and it had these horizontal lines going throught it.

Share on other sites
I think this is what you're looking for:
glTexSubImage2D

Share on other sites
I'm having some trouble figuring out how to use this function. I need this for loading multiple sprites from one file instead of having hundreads of bitmap files I plan to have a few that have multiple sprites. But like I said I can't seem to figure out how to do this.

Here is how I used the function:

glTexSubImage2D(GL_TEXTURE_2D, 0, 1024, 1024,
TextureImg[0]->w, TextureImg[0]->h, GL_BGR_EXT,
GL_UNSIGNED_BYTE, TextureImg[0]->pixels);

all I'm getting is a white texture.

Share on other sites
Well, it's hard to know exactly what's happening without seeing your image, but are you sure you want to have 1024, 1024 as the starting position?

Just an idea...
-Shane

Share on other sites
The image's resolution is 4096 x 1024. I just want to load half of it, that would be 2048 x 512. How would I acomplish this?

Share on other sites
Actually, 2048 X 512 is 1/4.

But assuming you wanted to load the left half of the image,
I think it would be something like this:

glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
TextureImg[0]->w / 2, TextureImg[0]->h, GL_BGR_EXT,
GL_UNSIGNED_BYTE, TextureImg[0]->pixels);

So you would go from 0 -> 2048 on the x direction,
and from 0 -> 1024 in the y direction.

Hope that helps

-Shane

Share on other sites
Here is my current code:

       glGenTextures(1, &texture[0]);               glBindTexture(GL_TEXTURE_2D, texture[0]);               glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImg[0]->w, TextureImg[0]->h, 0,                    GL_BGR_EXT, GL_UNSIGNED_BYTE, TextureImg[0]->pixels);                                     glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,                        TextureImg[0]->w / 2, TextureImg[0]->h, GL_BGR_EXT,                        GL_UNSIGNED_BYTE, TextureImg[0]->pixels);                              glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );       glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

I used the 256 x 256 nehe logo

Here is what I got:

Share on other sites
Alright disregard the previous posts. :)

Here's how you do it:

glPixelStorei(GL_UNPACK_ALIGNMENT,4);

// this skips the first 512 colums from the left
glPixelStorei(GL_UNPACK_SKIP_PIXELS,512);

// this skips the first 512 rows from the bottom
glPixelStorei(GL_UNPACK_SKIP_ROWS,512);

// this is the total width of the image
glPixelStorei(GL_UNPACK_ROW_LENGTH,1024);

// so this would load the upper right quarter of a bitmap that is 1024 x 1024
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,512,512,0,GL_RGB,GL_UNSIGNED_BYTE,pBitmap->data);

// you'll have to change the params to fit your image.

You can look here for what the GL_UNPACK enums represent.

Hopefully that works for you.

Some help from this post.

-Shane

• Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 30
• 9
• 16
• 22
×

Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!