RGBpixmap *pt1, *pt2;
void morphPixmap(float factor, int currentImage) {
float f = 1.0-factor;
mRGB first, second, next;
switch(currentImage) {
case 2001:
pt1 = &pic[0];
pt2 = &pic[1];
break;
case 2002:
pt1 = &pic[1];
pt2 = &pic[2];
break;
case 2003:
pt1 = &pic[2];
pt2 = &pic[3];
case 2004:
pt1 = &pic[3];
pt2 = &pic[0];
break;
default:
return;
}
for (int i=0; i < 256; i++) {
for (int j=0; j < 256; j++) {
//formula - C[j] = (1-f)*A[j] + f*B[j];
first = pt1->getPixel(i,j);
second = pt2->getPixel(i,j);
next.r = (unsigned char)(f*first.r + factor*second.r);
next.g = (unsigned char)(f*first.g + factor*second.g);
next.b = (unsigned char)(f*first.b + factor*second.b);
pic[4].setPixel(i,j, next);
//printf("(%d,%d) %c %c %c\n", i,j, next.r, next.g, next.b);
}
}
}
/*****************************************************************************/
float currentfactor=0;
int currentImage = 2001;
int counter=0;
void animation(void) {
if (counter > 5) counter=1;
if (currentfactor > 0 && currentfactor < 1) {
currentfactor += 0.2;
} else {
currentfactor = 0.2;
}
if (counter == 5) {
if (currentImage + 1 > 2004) {
currentImage = 2001;
} else {
currentImage += 1;
}
}
morphPixmap(currentfactor, currentImage);
drawScene();
sleep(1); counter++;
//glutPostRedisplay();
}
void drawScene(void) {
glClearColor(0,0,0, 0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D); //enable textures
glBindTexture(GL_TEXTURE_2D, TEMP_IMG); //bind texture to cube
glBegin(GL_QUADS);
glTexCoord2f(1,0); glVertex3f(-5,-5,5);
glTexCoord2f(0,0); glVertex3f( 5,-5,5);
glTexCoord2f(0,1); glVertex3f( 5, 5,5);
glTexCoord2f(1,1); glVertex3f(-5, 5,5);
glEnd();
glDisable(GL_TEXTURE_2D); //turn off textures
glFlush();
}
</pre> </i>
Morphing Textures
Hi everyone.
I have this little problem which may seem minor but I can''t get my head around it. Ive written this code (below) which is to morph one bitmap into another through a series of five pictures. But the image doesn''t change it stays with the very first image and doesn''t morph, is there something wrong with my logic. I believe the problem is with the writting of the pixel.
Hope You can help me, Thank You
Zane
The code does not look complete at all but I guess you have to redefine the texture once you modified it. (glBindTexture(GL_TEXTURE_2D, TEMP_IMG); //bind texture to cube)
You can do this using TexImage or, even better, TexSubImage, which is faster.
The point is that you are binding always to the same texture. GL does not track texture changes you do in application so, the texture GL is using may not be the texture you got in the app, so, you need to let the GL know the texture must be updated. Here''s TexSubImage (or whatever it is called).
BTW, using TexImage will redefine a lot of things which will slow down everything. TexSubImage is meant to *redefine* the contents of the texture object w/o modify every other parameter. Not sure if this is clear.
If I missed something or you do that outside the piece of code you posted, well, I have no idea.
You can do this using TexImage or, even better, TexSubImage, which is faster.
The point is that you are binding always to the same texture. GL does not track texture changes you do in application so, the texture GL is using may not be the texture you got in the app, so, you need to let the GL know the texture must be updated. Here''s TexSubImage (or whatever it is called).
BTW, using TexImage will redefine a lot of things which will slow down everything. TexSubImage is meant to *redefine* the contents of the texture object w/o modify every other parameter. Not sure if this is clear.
If I missed something or you do that outside the piece of code you posted, well, I have no idea.
Previously "Krohm"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement