Jump to content
  • Advertisement

Archived

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

ryan_carter87

texture help

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

ok I have made the code for building a house. Now when i try to put the textures onto it, it appears white, How do i make it fit the house when my textures have to 64 or 128 or 256 pixels?

Share this post


Link to post
Share on other sites
Advertisement
I''m not sure but I don''t think you have to have your textures in powers of 2. I think that if you use mipmapping you can bypass that little problem. But if you dont want to use mipmapping (I dont know why you wouldnt) then I''m pretty sure you can go above 256x256, you can use 512x512 or 1024x1024.

Share this post


Link to post
Share on other sites
Hmm, appearing white? Do you have any code that I can see? There are a couple of causes for a white texture (I am pretty sure its happened to me before) .. check and make sure you are enabling texturing in your program: glEnable(GL_TEXTURE_2D);

Share this post


Link to post
Share on other sites
ok i can give you some code, im sure i have the glEnable thing in there too. Heres the Code for the main section of the house.

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glBindTexture(GL_TEXTURE_2D,texture[2]);
glTranslatef(0.0f,0.0f,-6.0f);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,1.0f); glVertex3f(-1.5f,1.0f,0.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(2.0f,1.0f,0.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f(2.0f,-1.0f,0.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.5f,-1.0f,0.0f);
glEnd();

Hope you can help.

Share this post


Link to post
Share on other sites
That code seems OK, but I wouldn''t know as I havent seen your texture. Is there much white on the texture? You may be assigning the texture coordinates wrong but I doubt thats it

What about the initialization code?

Share this post


Link to post
Share on other sites
hmm,
OpenGL normally only supports powers of two,
this is to get better performance as far as I know.

And as someone mentioned before, even it was in a
weird way, if you don''t use a function which resizes
the texture for you ( I think this meant as he said
when you use mipmapping, but it hasn''t to do anything
with mipmapping at all ).
Or 2nd option, you resize it manually so you haven''t to do
it while runtime.

gluBuild2DMipmaps() is the function which resizes the
texture for you and allows you to use mipmapping.

However if you don''t want to use mipmapping you could also use
this one gluScaleImage() to scale at runtime.

Hope this helped you!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
resize your texture to 256 x 256.

(needs to be a power of two for most hardware. thinking that latest nvidia boards support non-powers of two, but i don''t really know.)

make sure you create your textures after you have made an opengl context (after you''ve created the window is usually a safe point of reference, if you don''t know exactly when.)

by "creating textures" i mean glGenTex/glTexImage2d.

(i''m sure i''m screwing up the call names, but you get the idea.)


Share this post


Link to post
Share on other sites
Ok look obviusly your not loading the texture into memory using this function..

-------start from here with the copying---------

///////Defines
#define BITMAP_ID 0x4D42

//////Texture Information
BITMAPINFOHEADER bitmapInfoHeader;
unsigned char* bitmapData;
unsigned int texture;

unsigned char *LoadBitmapFile(char *filename, BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *filePtr;
BITMAPFILEHEADER bitmapFileHeader;
unsigned char *bitmapImage;
int imageIdx = 0;
unsigned char tempRGB;

//open filename in "read binary" mode
filePtr = fopen(filename, "rb");
if(filePtr == NULL)
return NULL;

//read the bitmap file header
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);

//verify that this is a bitmap by checking for the universal bitmap id
if(bitmapFileHeader.bfType !=BITMAP_ID)
{
fclose(filePtr);
return NULL;
}

//read the bitmap information header
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1 ,filePtr);

//move file pointer to beginning of bitmap data
fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);

//allocate enough memory for the bitmap image data
bitmapImage = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);

//verify memory allocation
if (!bitmapImage)
{
free(bitmapImage);
fclose(filePtr);
return NULL;
}

//read in the bitmap image data
fread(bitmapImage, 1, bitmapInfoHeader->biSizeImage, filePtr);

//make sure the bitmap date was read
if (bitmapImage ==NULL)
{
fclose(filePtr);
return NULL;
}

//swape the R and B values to get RGB sinse the bitmap color format is in BGR
for (imageIdx = 0; imageIdx < bitmapInfoHeader->biSizeImage; imageIdx+=3)
{
tempRGB = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;
}

//close the file and return the bitmap image data
fclose(filePtr);
return bitmapImage;

}

Then after that you need to enable glTexture2D like so........
The code below load the BMP and bind it and textures it on the object.

-------start copying-------
copy this after the first code earlier and declare the init function at the begging of the file like so void init(void).
thats all and your done.


void init(void)
{
glClearColor(0.0f ,0.0f ,0.0f ,0.0f);
glClear(GL_COLOR_BUFFER_BIT);
glShadeModel(GL_SMOOTH);
glFrontFace(GL_CCW);
glEnable(GL_TEXTURE_2D);

//loads BMP but change it to your file(this is mines).
bitmapData=LoadBitmapFile("C:/Documents and Setting/Owner/Desktop/DEV save/paint.bmp", &bitmapInfoHeader);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

//load the texture image
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, bitmapInfoHeader.biWidth, bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, bitmapData);

}

Andrew rulz and u know it.........

Share this post


Link to post
Share on other sites

  • 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!