Jump to content
  • Advertisement
Sign in to follow this  

Textures not showing up properly

This topic is 3943 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
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();

         glTranslatef(position.x, position.y, position.z);
          for(int i = 0; i < numAnimations; i++)
         if (!overrideColourPainting) 
            glColor3f(r, g, b);
         else {
            glColor4f(secR, secG, secB, 0.2);
         //JImage * a = new JImage("fighter2.jpg");

            for(int i = 0; i < 24 ;i+=4) {
               Plane p(points, points[i+1], points[i+2]);
               GLfloat pEquation [4];
               glNormal3f(pEquation[0], pEquation[1], pEquation[2]);
               //if (!inwardNormals) 
               //   glNormal3f(normals[i/4][0], normals[i/4][1], normals[i/4][2]);
               //   glNormal3f(-normals[i/4][0], -normals[i/4][1], -normals[i/4][2]);
               glTexCoord2f(points[0] /scale, points[2]/scale);
               glTexCoord2f(points[i+1][0] /scale, points[i+1][2]/scale);
               glTexCoord2f(points[i+2][0] /scale, points[i+2][2]/scale);
               glTexCoord2f(points[i+3][0] /scale, points[i+3][2]/scale);
          if(drawBoundingBox && !overrideColourPainting) boundingBox->Render();
          if(normalsvisible && !overrideColourPainting) renderNormals();

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

  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().


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


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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!