Sign in to follow this  
silaros

256x256 Textures

Recommended Posts

Hi, I implemented texture object to my engine, but i have problem with resolutions of textures. When texture is 16x16, 32x32, 64x64 the process of loading ends successfuly. The problem starts when i try to load texture which is 128x128 or 256x256 - the screen is black. Should I change some parameters to load this textures? Paul

Share this post


Link to post
Share on other sites
There are no "special parameters" to load larger textures (other than changing the width and the height when passing it to OpenGL, obviously). It could be any number of cases at this point. You could have bad loading code to load the image from a file, or bad uploading code that sends it to OpenGL. Either describing your problem more in detail or showing us some code would be useful.

Hope that helps,
~Chris

Share this post


Link to post
Share on other sites
The code for loading:

unsigned char* CTexture::LoadBmpFile(std::string fileName)
{
FILE *filePtr;
BITMAPFILEHEADER bitmapFileHeader;
unsigned char* bitmapImage;
int imageIdx = 0;
unsigned char tempRGB;

filePtr = fopen(fileName.c_str(), "rb");

if (filePtr == NULL)
return NULL;

fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER), 1, filePtr);

if (bitmapFileHeader.bfType != BITMAP_ID)
{
fclose(filePtr);
return NULL;
}

fread(&bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, filePtr);

fseek(filePtr, bitmapFileHeader.bfOffBits, SEEK_SET);

bitmapImage = (unsigned char*) malloc(bitmapInfoHeader.biSizeImage);

if (!bitmapImage)
{
free(bitmapImage);
fclose(filePtr);
return NULL;
}

fread(bitmapImage, 1, bitmapInfoHeader.biSizeImage, filePtr);

if (bitmapImage == NULL)
{
fclose(filePtr);
return NULL;
}

for (imageIdx = 0; imageIdx < bitmapInfoHeader.biSizeImage; imageIdx+=3)
{
tempRGB = bitmapImage[imageIdx];
bitmapImage[imageIdx] = bitmapImage[imageIdx + 2];
bitmapImage[imageIdx + 2] = tempRGB;
}

fclose(filePtr);

return bitmapImage;
}

and code which sends loaded texture to opengl:


glGenTextures(size, texStorage);
glBindTexture(texDimension, *texStorage);
glEnable(GL_TEXTURE_2D);

this->texData = this->LoadBmpFile(fileName);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, this->bitmapInfoHeader.biWidth,
this->bitmapInfoHeader.biHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, this->texData);

Share this post


Link to post
Share on other sites
Have you tried resizing one of the working textures to a greater size, or are the larger textures another set of textures?

It could be a difference in bit-depth among the textures, or that you allocate too little memory to make room for the entire texture (or something).

Share this post


Link to post
Share on other sites
> glGenTextures(size, texStorage);
> glBindTexture(texDimension, *texStorage);

This two lines are probably wrong.

They should be

GLuint texid;
glGenTextures(1, &texid);
glBindTexture(GL_TEXTURE_2D, texid);

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this