PDA

View Full Version : Splitting textures



DaViper
06-15-2001, 05:58 AM
Actually all I want to do is doing the same as GL_TEXTURE_MIN_FILTER, GL_LINEAR. The only difference is, that I only want texels with ALPHA=1 mapped and filter on the smaller Polygon.

To achieve this I need to split up the original Texture in 4 Textures, each a quarter of the size of the original.





GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0.0, (GLfloat)viewport[2],
0.0, (GLfloat)viewport[3],
-1.0,1.0); //setting to raster pixel exact
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScaled(1./255,1./255.,1.0); //setting to reach each texel
glMatrixMode(GL_MODELVIEW);
....
....
generating the 256x256 texture and binding it
....
....
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _CLAMP);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _CLAMP);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST); //nearest to prevent interpolation

//okay here the interesting part starts, Texture is bound
glBegin(GL_POLYGON);
glTexCoord2d(0.,0.);
glVertex2d(0.,0.);
glTexCoord2d(0.,126);
glVertex2d(0.,64);
glTexCoord2d(126.,126.);
glVertex2d(64.,64.);
glTexCoord2d(126.,0.);
glVertex2d(64.,0);
glEnd();
glBegin(GL_POLYGON);
glTexCoord2d(1.,0.);
glVertex2d(64,0);
glTexCoord2d(1.,126);
glVertex2d(64.,64.);
glTexCoord2d(127.,126.);
glVertex2d(128.,64.);
glTexCoord2d(127.,0.);
glVertex2d(128.,0);
glEnd();
glBegin(GL_POLYGON);
glTexCoord2d(1.,1.);
glVertex2d(64.,64.);
glTexCoord2d(1.,127);
glVertex2d(64.,128.);
glTexCoord2d(127.,127.);
glVertex2d(128.,128.);
glTexCoord2d(127.,1.);
glVertex2d(128.,64.);
glEnd();
glBegin(GL_POLYGON);
glTexCoord2d(0.,1.);
glVertex2d(0.,64.);
glTexCoord2d(0.,127);
glVertex2d(0.,128.);
glTexCoord2d(126.,127.);
glVertex2d(64.,128.);
glTexCoord2d(126.,1.);
glVertex2d64.,64.);
glEnd();



after this the Orginial Texture should be splitt up like that:

12121212 11112222
34343434 11112222
12121212 11112222
34343434 11112222
12121212 33334444
34343434 33334444
12121212 33334444
34343434 33334444
original Textur what should be in framebuffer after my code

and the big Problem is that this is not working correctly, I am always getting texels mixed in the four seperated parts.

Anyone out there to help????????

Chris

DaViper
06-18-2001, 12:32 AM
anyone??