Textures and Materials in openGL

6e302cbc6cbfdd80379301ce3764a384
0
mytakamineg240 101 Nov 01, 2006 at 21:15

I am having some trouble using openGL and GLUT in C++. I’m not sure if this is the right forum, so feel free to ignore this. I am trying to set up textures and call them during rendering. I have coded this, but it doesn’t seem to be working. I get shaded objects, but no textures. The textures are read in from .ppm files.

void draw()
  {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
   vector<int> tempFace;
   vector<int> tempTex;
   int corner;
   int texCorner;
   VERT tempVert;
   TEXVERT tempVT;
   
   glEnable(GL_TEXTURE_2D);
   for(int objLoop = 0; objLoop < objList.size(); objLoop++)  //Loops through the list of face structures
    {
      tempFace = objList.at(objLoop).face;
      tempTex = objList.at(objLoop).texVerts;
      
       if(tempTex.size() !=  0)
        {
           if(tempFace.size() == 3)
             glBegin(GL_TRIANGLES);
           else
             glBegin(GL_POLYGON);
         
           glBindTexture(GL_TEXTURE_2D, texName[objList.at(objLoop).material]);
           glMaterialfv(GL_FRONT, GL_AMBIENT, mtlList.at(objList.at(objLoop).material).ambient);
               glMaterialfv(GL_FRONT, GL_DIFFUSE, mtlList.at(objList.at(objLoop).material).diffuse);
               glMaterialfv(GL_FRONT, GL_SPECULAR, mtlList.at(objList.at(objLoop).material).specular);
               glMaterialf(GL_FRONT, GL_SHININESS, mtlList.at(objList.at(objLoop).material).shinyness);
           
           for(int facePos = 0; facePos < tempFace.size(); facePos++)   //Loops through the vertices of a face
                {
        //  glColor3f(0.0, 0.0, 1.0); 
          corner = tempFace.at(facePos) - 1;  //need to decrement by 1, since array indicies start at 0
              texCorner = tempTex.at(facePos) -1;
                  tempVert = vertices.at(corner);
              tempVT = textureVertices.at(texCorner);
                  
              glTexCoord2f(tempVT.u, tempVT.v);
              glVertex3f(tempVert.a, tempVert.b, tempVert.c);
                }
           glEnd();
         }
        else
         {
        //   glColor3f(1.0, 0.0, 1.0);
           glBegin(GL_POLYGON);
           for(int facePos = 0; facePos < tempFace.size(); facePos++)   //Loops through the vertices of a face
                {
                  int corner = tempFace.at(facePos) - 1;  //need to decrement by 1, since array indicies start at 0
                  tempVert = vertices.at(corner);
      
              glVertex3f(tempVert.a, tempVert.b, tempVert.c);
                }
           glEnd();
         } 
    }
    glDisable(GL_TEXTURE_2D); 
    glutSwapBuffers();
  } 

This is my draw fuction. Is this wrong?

Thanks.

9 Replies

Please log in or register to post a reply.

6837d514b487de395be51432d9cdd078
0
TheNut 179 Nov 02, 2006 at 00:15

You need to tell OpenGL which texture you plan on using. You do that via the glBindTexture(GL_TEXTURE_2D, id); call, right after you enable the texture_2d state. The ID is simply the identifier you assigned to the texture when you created it.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Nov 02, 2006 at 02:09

TheNut, he is callling BindTexture inside the body of the loop.

OP: Make sure you have disabled mipmapping when you set up your textures. Many cards have it enabled by default, and if you don’t load in a complete mipmap chain the GL will act as if texturing was disabled entirely.

Also, on an unrelated note I notice you’re using the “at” function a lot in your vectors. In case you didn’t know, you can also just use standard array notation, like myvector[3] instead of myvector.at(3). Makes things easier to type and read.

063d115a5d40de4246c05827bd34af2b
0
wiury123 101 Nov 02, 2006 at 03:17

from MSDN: :P
GL_INVALID_OPERATION The parameter texture did not have the same dimensionality as target, or the glBindTexture functions was called between a call to glBegin and the corresponding call to glEnd.

you call glBindTexture, between glBegin() and glEnd();
glBindTexture results GL_INVALID_OPERATION ;).

….
if(tempTex.size() != 0)
{
glBindTexture(GL_TEXTURE_2D, exName[objList.at(objLoop).material]); // <


TRY HERE! ;)
if(tempFace.size() == 3)
glBegin(GL_TRIANGLES);
else
glBegin(GL_POLYGON);

glMaterialfv(GL_FRONT, GL_AMBIENT, mtlList.at(objList.at(objLoop).material).ambient);
….

6e302cbc6cbfdd80379301ce3764a384
0
mytakamineg240 101 Nov 02, 2006 at 21:21

Thanks for the replies! Wiury123, I took your advice and moved the glBindTexture call out from between the begin and end calls. this didn’t do much. An error was also pointed out in the method where I was building the textures, but it didn’t seem to be a problem. When my scene renders, the ground is now yellow when lighting is enabled, but no other textures are appearing. Suggestions are highly appreciated, as I am trying to learn this well. I have included my entire source code. Other files, mtl file, obj file, etc can be sent by email if you would like to have a look.

/*    ***********************************************************
      Glut Object Veiwer
      
      Programmed by W. Stephen Murphy
      Fall 2006
      
      ITCS 3050-002: Game Engine Design
      
      This program reads in *.obj files and renders the contents
      ***********************************************************   */
    

#include <iostream>  //Needed for standard I\O (cin, cout)
#include <fstream>   //Needed for file streams
#include <vector>    //Needed to create vectors
#include <sstream>   //Needed for string streams
#include <stdio.h>
#include <GL/gl.h>   // OpenGL itself.
#include <GL/glu.h>  // GLU support library.
#include <GL/glut.h> // GLUT support library.

using namespace std;

typedef struct faceGroup
 {
    vector<int> face;  //indexes into a vertex list
    vector<int> texVerts; //indexes into the textureVertices list
    int material;  //name of material
 
 } FACE;
 
typedef struct vert
 {
   float a;
   float b;
   float c;
 } VERT;

typedef struct texVert
 {
   float u;
   float v;
 } TEXVERT;
 
typedef struct material
 {
    string name;
    float ambient[3];
    float diffuse[3];
    float specular[3];
    int illum;
    float shinyness;
    string map;
 
 } MTL;
 
vector<FACE> objList;
vector<VERT> vertices;
vector<TEXVERT> textureVertices;
vector<MTL> mtlList;

float zVal = 0.0;
float lookZ = 0.0;
int rightPress = 0;
static GLuint texName[10];

int M_NONE;
 
 /* String tokenizer breaks a string into words by whitespace, and adds each token to a vector
Tokenizer fuction adapted from http://www.oopweb.com/CPP/Documents/CPPHOWTO/Volume/C++Programming-HOWTO-7.html */
vector<string> tokenizer(string fileLine, vector<string> tokenBag)
{
    string buf; // Have a buffer string
    stringstream ss(fileLine); // Insert the string into a stream
    
    tokenBag.clear();
    while (ss >> buf)
        tokenBag.push_back(buf);
        
        return tokenBag;
}

/* Converts a string into a float. Returns an error if unable to convert */

float stringConverter(string text)
{
    float number;
    istringstream iss(text);
    if (iss >> number) // If conversion is successful, do nothing.
     {
       return number;
     }
    else
     { 
       cout << "Error occured while converting string to float\n";
       cout << "Text to convert was : " << text << endl;
       return -1;
     }
}

/* Converts an integer into a string. */

string intConverter(int number)
 {
   ostringstream oss;
   oss << number << flush;
  
   return(oss.str());
 }
 
 void setMaterial(MTL material)
  {
     
  }
 
 /* readMaterials method opens a *.mtl file, reads it's contents,
   and creates a vector of MTL objects.  */
void readMaterials(string mtlFileName)
{
    fstream mtlFile;
    string fileBuffer;
    int count  = 0;
    
    vector<string> tokens;
    
    try
     {
        mtlFile.open(mtlFileName.c_str(), ios::in);
        if (!mtlFile)  // If file name not found, and exception is thrown
         {
           cout << "Material file could not be opened\n";
           throw;        
         }
     }
    catch(...) //If any exception is thrown, exit program
     {
       exit(1);
     }
    
    MTL newMtl;
     
    while(!getline(mtlFile, fileBuffer).eof())
     {
       while(fileBuffer.empty() && !mtlFile.eof()) //Checks for empty line
         continue;

       tokens = tokenizer(fileBuffer, tokens);
       string firstToken = tokens.at(0);
       if(firstToken == "newmtl")
        {
      mtlList.push_back(newMtl); //first time will push on an empty object.

      newMtl.name = tokens.at(1);
      newMtl.map = ""; //initializes map
        }
       else if (firstToken =="Ka") 
        {
           newMtl.ambient[0] = stringConverter(tokens.at(1));
       newMtl.ambient[1] = stringConverter(tokens.at(2));
       newMtl.ambient[2] = stringConverter(tokens.at(3));
        }
       else if (firstToken =="Kd")
        {
           newMtl.diffuse[0] = stringConverter(tokens.at(1));
       newMtl.diffuse[1] = stringConverter(tokens.at(2));
       newMtl.diffuse[2] = stringConverter(tokens.at(3));
        }
       else if (firstToken =="Ks")
        {
           newMtl.specular[0] = stringConverter(tokens.at(1));
       newMtl.specular[1] = stringConverter(tokens.at(2));
       newMtl.specular[2] = stringConverter(tokens.at(3));
        }
       else if (firstToken =="illum")
        {
           newMtl.illum = (int)stringConverter(tokens.at(1));
        }
       else if (firstToken =="Ns")
        {
           newMtl.shinyness = stringConverter(tokens.at(1));
        }
       else if (firstToken == "map_Kd")
        {
           newMtl.map = tokens.at(1);
        }
       else if(firstToken == "#")
        {
      //line flagged as comment
    }
       else //if flag is of unknown type
        {
          // cout << "Unknown line : " << fileBuffer << endl;
        }
     }
     mtlList.push_back(newMtl);
  }
 
 /* readFile method opens a *.obj file, reads it's contents,
   and creates vectors of objects to hold each type of data(vertices, faces, etc). 
   Data is delimited based on flags in the file (v, f, #, etc) */
void readFile()
{
    fstream sceneFile;
    char sceneFileName[81];
    string fileBuffer;
    int count  = 0;
    
    vector<string> tokens;
    vector<int> face;
    vector<int> faceTex; //holds the index into the texture vertex list
    int currentMaterial = 0;
    
    try
     {
        cout << "Enter name of file to render : ";
        cin.getline(sceneFileName, 81);
        sceneFile.open(sceneFileName, ios::in);
        if (!sceneFile)  // If file name not found, and exception is thrown
         {
           cout << "File could not be opened\n";
           throw;        
         }
     }
    catch(...) //If any exception is thrown, exit program
     {
       exit(1);
     }
    while(!getline(sceneFile, fileBuffer).eof())
     {
       if(fileBuffer.empty() && !sceneFile.eof()) //Checks for empty line
     continue;

       tokens = tokenizer(fileBuffer, tokens);
       string firstToken = tokens.at(0);

       if(firstToken == "#") //if flag is for comment
        {
          // cout << "This is a Comment : " << fileBuffer << endl;
      //Do Nothing
        }
       else if (firstToken == "v")  //if flag is for vertex
        {  
          VERT newVert;

          newVert.a = stringConverter(tokens.at(1));
      newVert.b = stringConverter(tokens.at(2));
      newVert.c = stringConverter(tokens.at(3));

          vertices.push_back(newVert);  
        }
       else if (firstToken == "f") //if flag is for face
        {           
      FACE newFace;  

      faceTex.clear();
      face.clear();
          int tokenCount = 1;
          bool more = true;
          while(tokens.size() > tokenCount)
           {
             //Create vector.
             string tok = tokens.at(tokenCount); //At will throw an exception if vector overrun    
         int delPos = tok.length();    
         delPos = tok.find('/');
         string remainder = tok.substr(delPos + 1, tok.length() - 1);
             tok = tok.substr(0, delPos);

             int addTo = (int)stringConverter(tok);
             face.push_back(addTo);
         
         if(remainder != "")
          {
            addTo = (int)stringConverter(remainder);
            faceTex.push_back(addTo);
          } 

             //Test for more tokens             
             tokenCount = tokenCount + 1;
             if( !(tokens.size() >= tokenCount))
              more = false;
            }

        newFace.texVerts = faceTex;  //Set texVerts vector in FACE struc as this facetex vector
            newFace.face = face;         //Set face vector in FACE struc as this face vector
        newFace.material = currentMaterial; //Sets the material in the FACE struc as the current index into the material array
        objList.push_back(newFace);
        }
       else if (firstToken == "usemtl")
        {
      for(int i = 0; i < mtlList.size(); i++)
       {
         if(tokens.at(1) == mtlList.at(i).name)
          {
            currentMaterial = i;
          }
       }
    }
       else if (firstToken == "g") //if flag is for grouping
        {
          //cout << "This is a group : " << fileBuffer << endl;
      //Do nothing    
        }
       else if (firstToken =="vn") //if flag is for vertex normal
        {
           //cout << "This is a vertex normal : " << fileBuffer << endl;
       //Do Nothing
        }
       else if (firstToken == "vt") //if flag is for vertex texture
        {
      TEXVERT newTexVert;

      newTexVert.u = stringConverter(tokens.at(1));
      newTexVert.v = stringConverter(tokens.at(2));

          textureVertices.push_back(newTexVert);  
    }
       else if (firstToken == "s") //if flag is for smoothing group
        {
       //cout << "This is a smoothing group" << fileBuffer << endl;
       //Do Nothing
    }
       else if (firstToken == "mtllib")
        {
      //Open material file
      readMaterials(tokens.at(1));
    }
       else //if flag is of unknown type
        {
          // cout << "Unknown line : " << fileBuffer << endl;
        }
     }
  }
 
void init()
 {
    //Chooses color to clear buffer to
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    glShadeModel (GL_SMOOTH);
    glEnable(GL_DEPTH_TEST);
    glEnable(GL_BLEND);
    
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    // FOV, Aspect, Z Near, Z Far
    gluPerspective(100.0, 1.0,  0.1, 500.0);
    
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    
    /* Defines an ambient, a diffuse, and a positional light source  */
    GLfloat light_position0[] = {0.0, 200.0, 50.0, 0.0};
    GLfloat light_ambient0[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat light_diffuse0[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat light_position1[] = {0.0, 200.0, -50.0, 0.0};
    GLfloat light_ambient1[] = {1.0, 1.0, 1.0, 1.0};
    GLfloat light_diffuse1[] = {1.0, 1.0, 1.0, 1.0};
    
    glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient0);
    glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
    glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse0);
    glLightfv(GL_LIGHT1, GL_AMBIENT, light_ambient1);
    glLightfv(GL_LIGHT1, GL_POSITION, light_position1);
    glLightfv(GL_LIGHT1, GL_DIFFUSE, light_diffuse1);
    
    glEnable(GL_LIGHTING);
    glEnable(GL_LIGHT0);
    glEnable(GL_LIGHT1);     
    
    
    zVal = 100.0;
    lookZ = 0.0;
    gluLookAt(0.0, 6.0, zVal, 0.0, 0.0, lookZ, 0.0, 1.0, 0.0);
 }

void makeTextures()
 { 
    FILE *file;
    string fileBuffer;
    vector<string> tokens;
    unsigned char* image;
    int height;
    int width;
    int maxValue;
   glEnable(GL_TEXTURE_2D);
   glGenTextures((GLuint)mtlList.size(), texName);
   for(int i = 0; i < mtlList.size(); i++)
    {
      glBindTexture(GL_TEXTURE_2D, texName[i]);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
      if(mtlList.at(i).map != "")
       {
     FILE * fp = fopen(mtlList.at(i).map.c_str(), "r");
     char ch = ' ';
     for(;ch != '\n';)
       {
         ch = getc(fp);
       }
     ch = ' ';
     for(;ch != '\n';)
       {
         ch = getc(fp);
       }
         fscanf(fp, "%d%d%d\n", &width, &height, &maxValue);
     image = new unsigned char[width * height * 3];
         fread ((unsigned char*) image,  width*height, 3, fp);
     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
     delete[] (unsigned char*) image;
       }
    }
 }
 
void draw()
  {
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   
   vector<int> tempFace;
   vector<int> tempTex;
   int corner;
   int texCorner;
   VERT tempVert;
   TEXVERT tempVT;
   int currentMaterial = -1;
   
   for(int objLoop = 0; objLoop < objList.size(); objLoop++)  //Loops through the list of face structures
    {
      tempFace = objList[objLoop].face;
      tempTex = objList[objLoop].texVerts;
      
      if(currentMaterial != texName[objList[objLoop].material -1])
       {
          glBindTexture(GL_TEXTURE_2D, texName[objList[objLoop].material - 1]);
          glMaterialfv(GL_FRONT, GL_AMBIENT, mtlList[objList[objLoop].material].ambient);
              glMaterialfv(GL_FRONT, GL_DIFFUSE, mtlList[objList[objLoop].material].diffuse);
              glMaterialfv(GL_FRONT, GL_SPECULAR, mtlList[objList[objLoop].material].specular);
              glMaterialf(GL_FRONT, GL_SHININESS, mtlList[objList[objLoop].material].shinyness);
          currentMaterial = texName[objList[objLoop].material - 1];
       }
       
       if(tempTex.size() !=  0)
        {
           if(tempFace.size() == 3)
             glBegin(GL_TRIANGLES);
           else
             glBegin(GL_POLYGON);
           
           for(int facePos = 0; facePos < tempFace.size(); facePos++)   //Loops through the vertices of a face
                {
        //  glColor3f(0.0, 0.0, 1.0); 
          corner = tempFace[facePos] - 1;  //need to decrement by 1, since array indicies start at 0
              texCorner = tempTex[facePos] -1;
                  tempVert = vertices[corner];
              tempVT = textureVertices[texCorner];
                  
              glTexCoord2f(tempVT.u, tempVT.v);
              glVertex3f(tempVert.a, tempVert.b, tempVert.c);
                }
           glEnd();
         }
        else
         {
        //   glColor3f(1.0, 0.0, 1.0);
           glBegin(GL_POLYGON);
           for(int facePos = 0; facePos < tempFace.size(); facePos++)   //Loops through the vertices of a face
                {
                  int corner = tempFace.at(facePos) - 1;  //need to decrement by 1, since array indicies start at 0
                  tempVert = vertices.at(corner);
      
              glVertex3f(tempVert.a, tempVert.b, tempVert.c);
                }
           glEnd();
         } 
    }
    glutSwapBuffers();
  } 
 
void keys(unsigned char key, int x, int y)  //Any key pressed calls init to reset the scene, except...
  {
     if(key == 27)  //The excape key exits aborts the program
      {
        exit(0);
      }
     else if(key == 'l') //The 'l' key turns lighting on
      {
        glEnable(GL_LIGHTING);
    glutPostRedisplay();
      }
     else if(key == 'o')
      {
        glDisable(GL_LIGHTING);
    glutPostRedisplay();
      }
     else if(key == 'b')
      {
       glEnable(GL_BLEND);
       glutPostRedisplay();
      }
     else if(key == 'n')
      {
        glDisable(GL_BLEND);
    glutPostRedisplay();
      }  
     else
      {
        init();
        glutPostRedisplay();
      }
  }
 
 /* Mouse function listens for mouse clicks */
 void mouse(int button, int state, int x, int y)
  {
     if (button == GLUT_RIGHT_BUTTON)
      {
        if (state == GLUT_DOWN)
         {
       rightPress = 1;
       //button pressed
         }
        if (state == GLUT_UP)
     {
           rightPress = 0;
         }
      }
  }

/* mouseMotion listens for active motion (when button is pressed)*/
void mouseMotion(int x, int y)
 {    
    glMatrixMode(GL_MODELVIEW);
    
    if((rightPress == 1))
     {  
       if(y > ((glutGet(GLUT_WINDOW_HEIGHT))/2)) // If downward motion is detected while shift is held, camera moves backward
        {
         zVal += 1.0;
         lookZ +=  1.0;
         glLoadIdentity();
         gluLookAt(0.0, 6.0, zVal, 0.0, 0.0, lookZ, 0.0, 1.0, 0.0);
         glutPostRedisplay();
        }
       else //If upward motion is detected while shift is held, camera moves forward
        {
         zVal -= 1.0;
         lookZ -= 1.0;
         glLoadIdentity();
         gluLookAt(0.0, 6.0, zVal, 0.0, 0.0, lookZ, 0.0, 1.0, 0.0);
         glutPostRedisplay();
        }
     }
    else
     {
       if(x > ((glutGet(GLUT_WINDOW_WIDTH))/2)) // If Rightward motion is detected, object is rotated 5.625 degrees to the positive side
        {
         glRotatef(5.625, 0.0, 1.0, 0.0);
         glutPostRedisplay();
         // Motion on right side of window
        }
       else //If leftward motion is detected, object is rotated 5.625 degrees to the negitive side
        {
         glRotatef(-5.625, 0.0, 1.0, 0.0);
         glutPostRedisplay();
         // Motion on left of window
        }
     } 
 }
 
 void passiveMouseMotion(int x, int y)
  {
       //this function can be used to detect passive mouse motion
  }
  
  void menuFunc(int value)
  {
    //Do Nothing
  }
  
 void makeMenu()
  {
    glutCreateMenu(menuFunc);

    glutAddMenuEntry("b key enables blending ", M_NONE);
    glutAddMenuEntry("n key disables blending", M_NONE);
    glutAddMenuEntry("l key enables lighting ", M_NONE);
    glutAddMenuEntry("o key disables lighting", M_NONE);
    glutAddMenuEntry("ESC key exits", M_NONE);
    glutAddMenuEntry("Any other key resets scene", M_NONE);
    glutAttachMenu(GLUT_MIDDLE_BUTTON);
  }  
 
 /*Handles resizing the window. Uses the w/h ratio as aspect */
 void resize(int w, int h)
  {
    if(h == 0) //prevents divide by 0
      h = 1;

   float ratio = 1.0 * w / h;
   
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
        
   // Set the viewport to be the entire window
   glViewport(0, 0, w, h);

   // Set perspective.
   gluPerspective(100.0, ratio, 0.1, 500.0);
  }
  
 int main(int argc, char **argv)
 {    
    glutInit(&argc, argv);
  
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(100, 100);
   
    glutCreateWindow("OBJ Renderer");
    makeMenu();
    
    init(); //Clears the window and sets the projection
    readFile();
    makeTextures(); //Registers texures in glut
    glutDisplayFunc(draw);
    glutMouseFunc(mouse);
    glutMotionFunc(mouseMotion);
    glutPassiveMotionFunc(passiveMouseMotion);
    glutKeyboardFunc(keys);
    glutReshapeFunc(resize);
    
    glutMainLoop();
    
    return EXIT_SUCCESS;
}

Thanks so much.
Stephen

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Nov 03, 2006 at 00:07

Like I mentioned earlier: you’re not loading mipmaps, and you’re not setting whether mipmapping is on or off, and it might be on by default, which would cause a problem. Try adding these two lines to your makeTextures function:

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

The second one isn’t strictly necessary but it doesn’t hurt to have it. When you want to activate mipmapping again you can change the first GL_LINEAR to GL_LINEAR_MIPMAP_LINEAR.

Also, a hint on an unrelated topic: I notice you’re enabling blending in your setup code. If you don’t need to blend everything but only some things, it’s faster to disable blending when drawing the things that don’t need it.

6e302cbc6cbfdd80379301ce3764a384
0
mytakamineg240 101 Nov 04, 2006 at 18:55

OK, I put in the two calls to disable mipmaping, as was suggested by Reedbeta and others. I can now see textures, but only if I apply the same texture to everything.
If I change this:

glBindTexture(GL_TEXTURE_2D, texName[objList[objLoop].material - 1]);

to this:

glBindTexture(GL_TEXTURE_2D, 7);

or

glBindTexture(GL_TEXTURE_2D, 3);

I get a textured scene. Any idea why?

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Nov 05, 2006 at 00:05

There must be something going wrong in your texName array. Try using a debugger to ensure that the values stored in it are correct at runtime, and also that the indices stored in the ‘material’ members of objList are correct. What is the -1 for? That looks a little suspicious to me.

6e302cbc6cbfdd80379301ce3764a384
0
mytakamineg240 101 Nov 05, 2006 at 23:30

The reason I am using the -1 is: the material members of objList start at 1, and the texName array(and the texture names) starts at 0. Since my last post, I changed

glBindTexture(GL_TEXTURE_2D, texName[objList[objLoop].material - 1]);
to
glBindTexture(GL_TEXTURE_2D, objList[objLoop].material - 1);

and everything now works.
Go figure.

Thanks for the help, btw. I really appreciate it.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Nov 05, 2006 at 23:46

Hmm. I think the fact that this works is only coincidence - the GL probably has allocated texture names that happen to correspond to your material indices, since the textures are created in numerical order. I’m glad you’ve gotten it to work, but I’d still recommend figuring out why it doesn’t work the way you expected it to work - it sounds as if something is stomping on the contents of the texName array. Remember, the bug isn’t fixed just because it has disappeared :)