PDA

View Full Version : best quality for a texture sphere



alfredolo
11-18-2005, 08:52 AM
Hello, I am trying to have the best quality for a little planet animation. I have a sphere with a texture on it and I would like to make it better.
I am using 256x256 texture size and when I zoom the sphere it have a lot of little square so I am trying to change the texture size in 512x512 but i get a stack overflow error. I am using BCB6. here is my code :

GLubyte bits[256][256][4];
bitmap->LoadFromFile("sfondo.bmp"); // blue.bmp
for(int i = 0; i &LT 256; i++)
{
for(int j = 0; j &lt 256; j++)
{
bits[i][j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[i][j]);
bits[i][j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
glGenTextures(1, &texture3);
glBindTexture(GL_TEXTURE_2D, texture3);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
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_RGBA, 256, 256, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);

If i change all "256" value into "512" i get that error.
How can i fix it ?
Any idea on how to improve the quality ?
Thank you very much
Alfredolo

Trahern
11-18-2005, 10:06 AM
The artifacts you see are there mainly becouse you set your filtering to GL_NEAREST ( no-filtering )
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

you can change this to
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

and you will surely see the difference

jide
11-18-2005, 11:58 AM
You cannot have a best quality than the original, that makes sense. You can interpolate (using linear for the texture parameter) or try to find out best interpolation algorithms but that's all.

If what Trahern says isn't enough, try to find a best image quality.

NB: The errors you get are just your programming error.

11-19-2005, 05:48 AM
The stack error is due to many compilers having a default stack size of 1Mb (not sure about Borland anymore), which your function seems to exceed. Move that big array to file scope or use new/malloc.

11-19-2005, 06:07 AM
For the highest quality filtering, see this thread
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=3;t=013971