Jump to content
  • Advertisement
Sign in to follow this  
subflood

loading a part of an image

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

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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:

Free Image Hosting at www.ImageShack.us

Share this post


Link to post
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

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!