0

I am applying texture to objects and its fine but when I move camera because its 3D scene then texture also moves.. Texture having lines on it is clearly visible moving.. How can I fix the texture (paste) on the objects so that it will not move with me.

Here is the Texture Code.

    glBindTexture(GL_TEXTURE_2D, texture[0]);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); //scale linearly when image bigger than texture

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); //scale linearly when image smalled than texture
   //glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);

   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    glTexImage2D(GL_TEXTURE_2D, 0, 3, image1->sizeX, image1->sizeY, 0,GL_RGB, GL_UNSIGNED_BYTE, image1->data);

    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    glShadeModel(GL_FLAT);

I am applying it like this on objects (its glutSolidcube)

glPushMatrix();
    glColor3f(0.50f, 0.35f, 0.25f);
    glTranslated(-8, 2, -8);
    glScaled(2.8,5, 4);

    glEnable(GL_TEXTURE_2D);
    glEnable(GL_TEXTURE_GEN_S); //enable texture coordinate generation
    glEnable(GL_TEXTURE_GEN_T);


    drawhouse(0.08);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_TEXTURE_GEN_S); //enable texture coordinate generation
    glDisable(GL_TEXTURE_GEN_T);
    
    glPopMatrix();
  • How did you configure texture coordinate generation? That is, how did you tell it which coordinates to generate? – user253751 Oct 06 '20 at 13:23
  • I am not telling it...It is auto generating...mostly i am using it on glucylinder, glutsolidcubes and 3d cube(surface). – BeingHumayun Oct 06 '20 at 18:06
  • glEnable(GL_TEXTURE_2D); GLUquadric* qobj2 = gluNewQuadric(); gluQuadricTexture(qobj2, GL_TRUE); glRotatef(90, 1, 0, 0); gluCylinder(qobj2, 3, 1, 4, 17, 4); gluDeleteQuadric(qobj2); glDisable(GL_TEXTURE_2D); – BeingHumayun Oct 06 '20 at 18:09
  • here it is auto genrating coordinates glEnable(GL_TEXTURE_GEN_S); //enable texture coordinate generation glEnable(GL_TEXTURE_GEN_T); – BeingHumayun Oct 06 '20 at 18:15
  • Well, it's auto-generating coordinates that aren't the ones you want, right? – user253751 Oct 07 '20 at 09:23
  • Yes maybe thats'y texture is not correctly mapped due to diff size and diff coordinates.. – BeingHumayun Oct 07 '20 at 10:55
  • So how are you telling it which coordinates to generate? – user253751 Oct 07 '20 at 11:03
  • glEnable(GL_TEXTURE_GEN_S); glEnable(GL_TEXTURE_GEN_T); – BeingHumayun Oct 07 '20 at 11:39
  • Yeah, that tells it to generate coordinates, it doesn't tell it which coordinates you would like it to generate. The answer is that you're not telling it which coordinates to generate. So it shouldn't be surprising that it generated the wrong ones. Who told you to use GL_TEXTURE_GEN_S/T? – user253751 Oct 07 '20 at 12:32
  • I searched how to apply texture on glutSolidCube and guy here on stackoverflow answered – BeingHumayun Oct 07 '20 at 14:39
  • Here is the page https://stackoverflow.com/a/5011345/12135338 – BeingHumayun Oct 07 '20 at 14:40
  • Well, it doesn't exactly work. Maybe you should render your own cube with proper texture coordinates. – user253751 Oct 07 '20 at 14:59
  • I render the cube with proper coordinates but its one side is distorted and other is good – BeingHumayun Oct 07 '20 at 18:17

0 Answers0