Advertisement

bitmap template

Started by December 16, 2003 06:59 AM
14 comments, last by aperry 21 years, 2 months ago
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]);
You must bind (assign) a texture using glBindTexture before loading a texture into it using TexImage2D and Build2DMipmaps.
- growl -
Advertisement
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!
First this; texture width and height should be powers of 2 (2, 4, 8, 16, 32, 64, 128, etc.)
- growl -
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?
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);
- growl -

This topic is closed to new replies.

Advertisement