PDA

View Full Version : porting linux glut code to mac os x


zynek
2005.01.21, 11:36 AM
Hi,
I am porting a linux program to Mac OS X and I am realtivley new to OpenGl. The program is a talking head application that uses Glut for displaying the graphics. The mouth, teeth, and the eyes are all saved as obj files. Except for the eyes everything is displayed. I found that the way the eyes are displayed is different from the other objects. I was wondering if there might be something mac specific that I don't know about that causes the eyes to be invisible?

Here is the code for diplaying the eyes:

void ObjModel::DrawObjModel()
{
for(int i = 0; i < m_number_f; i++){
glBegin(GL_POLYGON);
for(int j = 0; j < m_number_f_ele[i]; j++){
if( m_texture_ver )
//glTexCoord3dv((GLdouble *)&m_texture_ver[m_link[i].element[j].v]);
glTexCoord2d(m_texture_ver[m_link[i].element[j].v].x, m_texture_ver[m_link[i].element[j].v].y);
if( m_normal )
glNormal3dv((GLdouble *)&m_normal[m_link[i].element[j].n]);
glVertex3dv((GLdouble *)&m_vertex[m_link[i].element[j].v]);
}
glEnd();
}
}


this routine gets called from here:

void FaceEditView::DrawEyeModel(FaceModel *model)
{
ObjModel *obj = model->GetEyeObject();
glPushMatrix();
glTranslated(model->GetEyeRTrans()[0], model->GetEyeRTrans()[1], model->GetEyeRTrans()[2]);
glScaled(model->GetEyeRScale(), model->GetEyeRScale(), model->GetEyeRScale());
glRotated(model->GetEyeRLocalRot()[0] + model->GetAppEyeRotR()[0], 1.0, 0.0, 0.0);
glRotated(model->GetEyeRLocalRot()[1] + model->GetAppEyeRotR()[1], 0.0, 1.0, 0.0);
glRotated(model->GetEyeRLocalRot()[2], 0.0, 0.0, 1.0);
obj->DrawObjModel();
glPopMatrix();


glPushMatrix();
glTranslated(model->GetEyeLTrans()[0], model->GetEyeLTrans()[1], model->GetEyeLTrans()[2]);
glScaled(model->GetEyeLScale(), model->GetEyeLScale(), model->GetEyeLScale());
glRotated(model->GetEyeLLocalRot()[0] + model->GetAppEyeRotL()[0], 1.0, 0.0, 0.0);
glRotated(model->GetEyeLLocalRot()[1] + model->GetAppEyeRotL()[1], 0.0, 1.0, 0.0);
glRotated(model->GetEyeLLocalRot()[2], 0.0, 0.0, 1.0);
obj->DrawObjModel();
glPopMatrix();
}




The teeth get displayed using this routine, which apparently works:

void ObjectModel::drawTeethModel(int mode)
{
TRACE("ObjectModel::drawTeethModel()");

int i;
int pointNum = getPointNum();
int polygonNum = getPolygonNum();
int pointVectorNum = getPointVectorNum();
double x,y,z,y1,z1,xmax,ymax,zmax,xmin,ymin,zmin,xcenter;
double calc = moveTeeth(mode);
double jawAngle = getJawAngle();
Point3f tmp[600];
Point3f *pointPtr = getPoint();
Polygon3 *polygonPtr = getPolygon();
Vector3f *polygonVectorPtr = getPolygonVector();
Vector3f *pointVectorPtr = getPointVector();
glPushMatrix();

switch(mode){
case TEETH_UPPER:
for(i = 0 ; i < pointNum ; i++){
tmp[i].x = pointPtr->x;
tmp[i].y = pointPtr->y;
tmp[i].z = pointPtr->z;
pointPtr++;
}
pointPtr = getPoint();
break;
case TEETH_LOWER:
xmin = ymin = zmin = MAXDOUBLE;
xmax = ymax = zmax = -MAXDOUBLE;
for(i = 0 ; i < pointNum ; i++){
x = pointPtr->x;
y = pointPtr->y;
z = pointPtr->z;
if(x < xmin) xmin = x;
if(y < ymin) ymin = y;
if(z < zmin) zmin = z;

if(x > xmax) xmax = x;
if(y > ymax) ymax = y;
if(z > zmax) zmax = z;
pointPtr++;
}
pointPtr = getPoint();
for(i = 0 ; i < pointNum ; i++){
tmp[i].x = pointPtr->x;
tmp[i].y = pointPtr->y;
tmp[i].z = pointPtr->z;
pointPtr++;
}
pointPtr = getPoint();
xcenter =(xmax + xmin) / 2.0;
y1 = 0.00;
z1 = zmin;
glTranslated(-xcenter, -y1, -z1);
glRotated(jawAngle / 2.0, 1.0, 0.0, 0.0);
glTranslated(xcenter, y1, z1);
break;
}
glBegin(GL_TRIANGLES);
for(i = 0; i < polygonNum; i++){
glNormal3dv((GLdouble *)(pointVectorPtr + polygonPtr->tp0));
glVertex3d(tmp[polygonPtr->p0].x,tmp[polygonPtr->p0].y, tmp[polygonPtr->p0].z);

glNormal3dv((GLdouble *)(pointVectorPtr + polygonPtr->tp1));
glVertex3d(tmp[polygonPtr->p1].x,tmp[polygonPtr->p1].y, tmp[polygonPtr->p1].z);

glNormal3dv((GLdouble *)(pointVectorPtr + polygonPtr->tp2));
glVertex3d(tmp[polygonPtr->p2].x,tmp[polygonPtr->p2].y, tmp[polygonPtr->p2].z);
polygonPtr++;
}
glEnd();
glPopMatrix();

}



I hope someone here can help.
thanks,
Gregor

ravuya
2005.01.21, 12:12 PM
Is it possible you have endian issues when loading the model file in?

zynek
2005.01.21, 12:15 PM
well I had endian issues with the texture fiels but I got those resolved. If I do have endian issues here I don't see why they would only apply to the eye.obj and not to the other obj files. I checked with a debugger and sees like the obj files are loading fine. I believe that the problem is in the code.

thanks anyway,
Gregor

arekkusu
2005.01.22, 04:08 PM
So, the eyes are textured, and the teeth aren't. Are any other parts of the model textured? Are you sure the textures are complete?

zynek
2005.01.22, 10:19 PM
thanks for pointing that out. Iif the textures are incomplete and if I just display the wireframe this should not make a difference, right? Even in the wireframe the eyes are missing....

Gregor

arekkusu
2005.01.22, 10:51 PM
Wireframes can be textured, too ;) Try disabling texturing to be sure.

zynek
2005.01.23, 07:46 AM
The eyes do not display when I disable texturing but I found another part of the model that is textured as well, which is displayed fine. :blink:

void ObjectModel::drawMouthwallModel()
{
TRACE("ObjectModel::drawMouthwallModel()");

int polygonNum = getPolygonNum();
int pointVectorNum = getPointVectorNum();
Point3f *pointPtr = getPoint();
Polygon3 *polygonPtr = getPolygon();
Vector3f *pointVectorPtr = getPointVector();
Point2f *texturePointPtr = getTexturePoint();

moveMouthwall();

glBegin(GL_TRIANGLES);
for(int i = 0; i < polygonNum; i++){
glTexCoord2d(texturePointPtr[polygonPtr->p0].x, texturePointPtr[polygonPtr->p0].y);
glVertex3dv((GLdouble *)(pointPtr + polygonPtr->p0));

glTexCoord2d(texturePointPtr[polygonPtr->p1].x, texturePointPtr[polygonPtr->p1].y);
glVertex3dv((GLdouble *)(pointPtr + polygonPtr->p1));

glTexCoord2d(texturePointPtr[polygonPtr->p2].x, texturePointPtr[polygonPtr->p2].y);
glVertex3dv((GLdouble *)(pointPtr + polygonPtr->p2));
polygonPtr++;
}
glEnd();
}


thanks,
Gregor

arekkusu
2005.01.23, 11:48 AM
Hmm... well, I don't see anything else special about the eyes.

Do you have backface culling turned on? Is the eye geometry correctly wound?

zynek
2005.01.23, 01:08 PM
backface culling is turned on. I am not sure how to check if the geomerty is correctly wound?

thanks,
Gregor

SOUR-Monkey
2005.01.23, 06:29 PM
Read the man page on glFrontFace() for information on winding. Try both GL_CW and GL_CCW, and see if the eyes show up in either mode.

zynek
2005.01.23, 06:44 PM
I just tried it. The geometry was correctly wound. The model was turned inside out after I changed the orientation. I also just applied it to the part where the eyes are drawn but nothing happend. :frown:

thanks,
Gregor

Duane
2005.01.23, 07:20 PM
try posting the project, it's easier to look at that way.

zynek
2005.01.23, 07:47 PM
sorry I can't do that. First of all I am not allowed to post attachments and second the project is not open source. :( -its not my call- maybe it will be in the future. But are there any particular parts of the code that could be helpful?

cheers,
Gregor