mytakamineg240
November 1st, 2006, 03:58 PM
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?
Full source code is attached.
Thanks.
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?
Full source code is attached.
Thanks.