Archived

This topic is now archived and is closed to further replies.

bitmap template

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

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

Share this post


Link to post
Share on other sites
If you use the NeHe texture loading routine:

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.

Share this post


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

Share this post


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

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

Share this post


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

Share this post


Link to post
Share on other sites
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);

Share this post


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

Share this post


Link to post
Share on other sites
texture_inputted is passed in and sent back to this function and is the one ultimately displayed. could that have anything to do with it?
tried this without any luck:
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];
}
}
glTexImage2D(GL_TEXTURE_2D, 0, 3, 5, 5, 0, GL_RGB, GL_UNSIGNED_BYTE, tex);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 5, 5, GL_RGB, GL_UNSIGNED_BYTE, tex);
glBindTexture(GL_TEXTURE_2D, texture_inputted[0]);

Share this post


Link to post
Share on other sites
i''m still having a bit of trouble. it doesn''t help that i''ve been up since yesterday could you post an example piece of code that works? (that does the entire process?)
thanks!

Share this post


Link to post
Share on other sites
ok, i changed the height and width both to 8.

glBindTexture(GL_TEXTURE_2D, texture_inputted[0]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 8, 8, 0, GL_RGB, GL_UNSIGNED_BYTE, tex);
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, tex);

do these go in this order? they come after the for loops right?

Share this post


Link to post
Share on other sites
Yes:
1a. allocating memory
1b. loading the base texture
2 . copying the data to the new texture data array (for loops)
3 . assign the texture (so we''ll load the data into the right texture.
4 . set texture parameters !!!!!
do this:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
5. load the data into the texture memory:
do this:
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 8, 8, GL_RGB, GL_UNSIGNED_BYTE, tex);

The glTexImage2D() function loads the texture as a normal texture, the gluBuild2DMipmaps() function does the same only for mipmapped texture so use one, not both as only the last one will have effect (it will simply overwrite the texture).
If you decide not to use mipmapping set the GL_TEXTURE_MIN_FILTER to GL_LINEAR (as GL_LINEAR_MIPMAP_NEAREST will only work for mipmapped textures);

Share this post


Link to post
Share on other sites