Thank your for your reply. Yes i got 2 good examples actually which create opengl texture from npot bitmaps, one is that DevIL and one is with SDL. They load texture fine but biggest problem for me now is rendering quad which has the newly created texture centered exactly on the quad.
I even did a simple example with crosshair on screen and rotated the quad on center and then i discovered that texture is not actually centered on the quad.
The quad itself was "perfect", npot texture was also OK but texture had offset on the quad. But in my case the npot texture must be exactly centered on the quad.
So have discovered that im unable to center the texture on quad. As you said: "rescale your texture co-ordinates by the ratio of the new NPOT image size to the Original image size"
I don't care about memory atm, i need to make it work first.
Im now even unable to find the example i wanted to show you, how the texture is not centered.
I was so disappointed. I thought i got it finally working but no, again some bug or problem.
But i would like to make it work. I will at least learn something from it.
I will try to find the example i made and post a screenshot later.
EDIT
It should be like in image B, but atm its like A. Which is bad!
It should be centered perfectly like in image B.
Original texture size is 32x18
By ratio you mean in this case 32 / 32 and 18 / 32 ?
Since next POT for 32 is 32 (unchanged in this case) and for 18 it's 32.
Here is the way im doing atm:
Code:
var texTop, texbottom, texleft, texright:single;
w,h:Single;
texTop:=0; // This shouldnt be 0 i think, must be calculated?
texleft:=0; // This shouldnt be 0 i think, must be calculated?
texbottom:=th /getnextpot(th);
texright:=tw / getnextpot(tw);
w:=tw/64;
h:=th/64;
glBegin( GL_QUADS );
// Top-left vertex (corner)
glTexCoord2f( texLeft, texTop ); glVertex3f( -w/2, -h/2, 0 );
// Bottom-left vertex (corner)
glTexCoord2f( texRight, texTop); glVertex3f( w/2, -h/2, 0 );
// Bottom-right vertex (corner)
glTexCoord2f( texRight, texBottom); glVertex3f( w/2, h/2, 0 );
// Top-right vertex (corner)
glTexCoord2f(texLeft, texBottom); glVertex3f( -w/2, h/2, 0 );
glEnd();
If i modify either texTop and / or texLeft then i can move texture to center.
But then it looks pretty bad, like squeezed together a bit or something.
"tw" and "th" are NPOT image width and height, assigned on image loading!
In this case they contain: 32 and 18.
This code causes things look like in image A.
I divide by 64 because every tile in GTA2 is 64x64. Main gfx. Every object like this roadblock is placed on the tiles of size 64x64.
It seems everything should be calculated. But whats the correct math?
I will try to find some example on net.
Texture centering is the only problem atm.
Bookmarks