
bitmap template
i have been able to, through exporting my 3ds file to milkshape, then to an ascii text file, to render a wireframe version of my model. i know everything about how to texture triangles(normals, uv coordinates, etc..) ..however i do not have any idea how to take a bitmap template and get individual parts of the bitmap onto my triangles.
thanks in advance for any help you can provide

If you use the NeHe texture loading routine:
I might have switched width/height, sorry about that.
BYTE tex[width*height*3];// Or allocate it another way :)for(unsigned int x=0;x<width;x++){ for(unsigned int y=0;y<height;y++){ tex[(x*height+y)*3+0]=img->data[((x+xoffset)*sizeY+y+yoffset)*3+0]; tex[(x*height+y)*3+1]=img->data[((x+xoffset)*sizeY+y+yoffset)*3+1]; tex[(x*height+y)*3+2]=img->data[((x+xoffset)*sizeY+y+yoffset)*3+2]; };};glTexImage2D(GL_TEXTURE_2D, 0, 3, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, tex);
I might have switched width/height, sorry about that.
- growl -
call me new but i haven''t come across this before:
BYTE tex[width*height*3];
if i could get an explanation for that i think i will be set
thanks for your help!
BYTE tex[width*height*3];
if i could get an explanation for that i think i will be set

thanks for your help!
BYTE is a type, (i am not sure if it''s char or unsigned char)
tex is the array you create with this line
[what stands between these brackets is the size of the array you allocate]
In this line the width of the image part you wish to get and the height of it are multiplied, which gives you exactly enough texture data for an 8-Bit texture of that size.
Now we multiply that value with 3 as all textures are loaded as 24 bit (rgb) textures, so we''ll have 3 Bytes per pixel.
xoffset is x coordinate in the original texture where the new texture begins, yoffset is the y coordinate for that.
A is the coordinate (xoffset,yoffset).
The large rectangle is the original texture.
The small rectangle is the new texture.
Then you copy all pixel data from the original texture to the new texture.
I hope i am clear.
tex is the array you create with this line
[what stands between these brackets is the size of the array you allocate]
In this line the width of the image part you wish to get and the height of it are multiplied, which gives you exactly enough texture data for an 8-Bit texture of that size.
Now we multiply that value with 3 as all textures are loaded as 24 bit (rgb) textures, so we''ll have 3 Bytes per pixel.
xoffset is x coordinate in the original texture where the new texture begins, yoffset is the y coordinate for that.
_____________________________________________________| || --> width || A_____________ || | | | || \|/| | || height| | || |_____________| || || || || || |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
A is the coordinate (xoffset,yoffset).
The large rectangle is the original texture.
The small rectangle is the new texture.
Then you copy all pixel data from the original texture to the new texture.
I hope i am clear.
- growl -
nevermind about the allocation, i looked at it again and figured it out
all i need to know now is what is meant by xoffset and yoffset. do these values ever change?
thanks!

thanks!
As you can see xoffset and yoffset are simply the coordinates of the part you want to make a new texture from
- growl -
thank you so much for your help!
i think with a little bit of doing, i will have my model textured!
thanks again
i think with a little bit of doing, i will have my model textured!
thanks again

i apologize for being such a hassle, but i''ve tried this and it doesn''t seem to work:
glBindTexture(GL_TEXTURE_2D, texture_inputted[0]);
for(unsigned int x=0;x<5;x++)
{
for(unsigned int y=0;y<5;y++)
{
tex[(x*5+y)*3+0]=TextureImage[0]->data[((x+xoffset)*TextureImage[0]->sizeY+y+yoffset)*3+0];
tex[(x*5+y)*3+1]=TextureImage[0]->data[((x+xoffset)*TextureImage[0]->sizeY+y+yoffset)*3+1];
tex[(x*5+y)*3+2]=TextureImage[0]->data[((x+xoffset)*TextureImage[0]->sizeY+y+yoffset)*3+2];
}
}
glBindTexture(GL_TEXTURE_2D, texture_inputted[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 5, 5, 0, GL_RGB, GL_UNSIGNED_BYTE, tex);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
glBindTexture(GL_TEXTURE_2D, texture_inputted[0]);
for(unsigned int x=0;x<5;x++)
{
for(unsigned int y=0;y<5;y++)
{
tex[(x*5+y)*3+0]=TextureImage[0]->data[((x+xoffset)*TextureImage[0]->sizeY+y+yoffset)*3+0];
tex[(x*5+y)*3+1]=TextureImage[0]->data[((x+xoffset)*TextureImage[0]->sizeY+y+yoffset)*3+1];
tex[(x*5+y)*3+2]=TextureImage[0]->data[((x+xoffset)*TextureImage[0]->sizeY+y+yoffset)*3+2];
}
}
glBindTexture(GL_TEXTURE_2D, texture_inputted[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 5, 5, 0, GL_RGB, GL_UNSIGNED_BYTE, tex);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
Use the new texture when loading:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, tex);
instead of
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
The way you did it sends the old texture to your graphicscard.
[edited by - Living Monstrosity on December 16, 2003 10:07:18 AM]
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, width, height, GL_RGB, GL_UNSIGNED_BYTE, tex);
instead of
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);
The way you did it sends the old texture to your graphicscard.
[edited by - Living Monstrosity on December 16, 2003 10:07:18 AM]
- growl -
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement