Sign in to follow this  
Neutrinohunter

Textures not showing up properly

Recommended Posts

I can't seem to find out what the problem is with loading textures into my application. I have done this thousands of times before it seems and ive never had any problems till I've started my new project. All my models seem to be at glColor3f(1.0,1.0,1.0), which is what glEnable(GL_TEXTURE_2D) defaults to if no texels are assigned. Is there any setting such as GL_TEX_ENV or GL_COLOR_MATERIAL which could affect the textures from working? I'm scowering through old code (bad code too) which works and am not sure what the problem is. My code is as follows, some bits are shortened for brevity. JamieB
   glGenTextures(1, &textureValue);
	// Bind this texture to its id
   glBindTexture(GL_TEXTURE_2D, textureValue);

// Use mipmapping filter
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
	glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D (GL_TEXTURE_2D, 0, 3, this->width, this->height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
//gluBuild2DMipmaps(GL_TEXTURE_2D, type, width, height, type, GL_UNSIGNED_BYTE, data);

And then in my rendering code
void JBox::render(bool overrideColourPainting) {
   if (visible) {

   int numAnimations = animationManager->getNumberOfAnimations();

      glPushMatrix();
         glPushAttrib(GL_CURRENT_BIT);
         glTranslatef(position.x, position.y, position.z);
          for(int i = 0; i < numAnimations; i++)
            animationManager->getAnimation(i)->applyTransform();
         if (!overrideColourPainting) 
            glColor3f(r, g, b);
         else {
            glColor4f(secR, secG, secB, 0.2);
         }
         glScalef(scale,scale,scale);
         //glEnable(GL_TEXTURE_2D);
         //JImage * a = new JImage("fighter2.jpg");
         image->Use();

         glBegin(GL_QUADS);
            for(int i = 0; i < 24 ;i+=4) {
               Plane p(points[i], points[i+1], points[i+2]);
               GLfloat pEquation [4];
               p.getPlaneEquation(pEquation);
               glNormal3f(pEquation[0], pEquation[1], pEquation[2]);
               //if (!inwardNormals) 
               //   glNormal3f(normals[i/4][0], normals[i/4][1], normals[i/4][2]);
               //else
               //   glNormal3f(-normals[i/4][0], -normals[i/4][1], -normals[i/4][2]);
               glTexCoord2f(points[i][0] /scale, points[i][2]/scale);
               renderVertexv(points[i]);
               glTexCoord2f(points[i+1][0] /scale, points[i+1][2]/scale);
               renderVertexv(points[i+1]);
               glTexCoord2f(points[i+2][0] /scale, points[i+2][2]/scale);
               renderVertexv(points[i+2]);
               glTexCoord2f(points[i+3][0] /scale, points[i+3][2]/scale);
               renderVertexv(points[i+3]);
            }
         glEnd();
         glDisable(GL_TEXTURE_2D);
          if(drawBoundingBox && !overrideColourPainting) boundingBox->Render();
          if(normalsvisible && !overrideColourPainting) renderNormals();
      glPopMatrix();
      animationManager->Update();    
   }

void JImage::Use() {
  if (data == NULL)
   std::cout << "Error: No Texture Data Present\r";

  glEnable(GL_TEXTURE_2D);
  glBindTexture(GL_TEXTURE_2D, textureValue);
}

Share this post


Link to post
Share on other sites
The texture is incomplete because you have only supplied level 0 of the mipmap chain :

glTexImage2D (GL_TEXTURE_2D, 0, 3, this->width, this->height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);


Why do you have gluBuild2DMipmaps commented out?

Share this post


Link to post
Share on other sites
The minification filter you set requires a full set of mipmap levels to be complete. That is, all the way down to 1x1. You provide only the base level, which means the texture is missing level 1 and up. The texture is therefore incomplete, and any use of that texture will effectively disable that texture unit. The result is therefore as if texturing was disabled.

Share this post


Link to post
Share on other sites
Well I as trying to check whether just a simple glTexImage() would work because gluBuild2DMipmaps() wasn't working.

I've checked all the texture loading and I have written the outputted texture to file and it looks as it should do.

I have my filters like so and mipmap generation through GLU as follows and this still doesn't work, I've tried removing, adding and changing the filters but I still get no output. Is there anything else, as well as my oversight of the filters when changing to glTexImage().


glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

gluBuild2DMipmaps(GL_TEXTURE_2D, type, width, height, type, GL_UNSIGNED_BYTE, data);





Jamie


Edit: The problem wasn't with the filters (or that there were 2 problems), it was with the "TYPE" part I had the value as 3 or 4 rather than GL_RGB and GL_RGBA, always the simplest mistakes which are the hardest to fix!!

Thanks for all your help.

[Edited by - Neutrinohunter on January 1, 2008 8:41:12 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this