So the latest on this is that the existing version of ViewScene as per 2011.3 only shows wireframe unless the model has a .tga texture (apparently, but no .tga textured model is supplied :-{
If there is no texture, then it defaults to wireframe. I have added a menu option (which is also in the 2012.2 SDK) to allow you to choose wireframe, textured or lighted
I hacked this together from my OpenGL code so it is very ugly but functional and easy to follow (I think)
Since I have been asking for the code myself it is only fair I post this 🙂 If anyone has a better solution, I'd love to see it. ViewScene will now draw wireframe or lighted and will apparently texture when it can. If ANYONE has other than .tga texturing for ViewScene I'm very interested.
Simon
in main.cxx create menus
int lDrawModeMenu = glutCreateMenu(DrawModeSelectionCallback);
glutAddMenuEntry("Wire Frame", 0);
glutAddMenuEntry("Lighted", 1);
glutAddMenuEntry("Textured", 2);
bit later in same function
// Build the main menu.
glutCreateMenu(MenuSelectionCallback);
glutAddSubMenu("Select Camera", lCameraMenu);
glutAddSubMenu("Select Animation Stack", lAnimStackMenu);
if (lBindPoseCount>0 || lRestPoseCount>0)
glutAddSubMenu("Go to Pose", lPoseMenu);
glutAddMenuEntry("Play", PLAY_ANIMATION);
glutAddSubMenu("Draw Mode", lDrawModeMenu); ADDED SJW
glutAddMenuEntry("Exit", EXIT_ITEM);
glutAttachMenu(GLUT_RIGHT_BUTTON);
call function added global in main.cxx
int gDrawMode = 0;
void DrawModeSelectionCallback(int pItem)
{
gDrawMode = pItem;
gSceneStatus = MUST_BE_REFRESHED;
}
// Modify call to GlDrawMesh in DrawMesh() file DrawScene.cxx
GlDrawMesh(pGlobalPosition,
lMesh,
lVertexArray,
gDrawMode);
In GlFunctions.cxx
// This is commented out lDrawMode = (lDrawMode == DRAW_MODE_TEXTURED && lTexture) ? lDrawMode : DRAW_MODE_WIREFRAME;
lDrawMode = (lDrawMode != DRAW_MODE_TEXTURED) ? lDrawMode : (lTexture ? lDrawMode : DRAW_MODE_WIREFRAME);
//printf("Want to draw %d, going to %d\n", pDrawMode, lDrawMode);
int lGLPrimitive = lDrawMode == DRAW_MODE_WIREFRAME ? GL_LINE_LOOP : GL_POLYGON;
Then in the polygon BEFORE the vertex loop add
// Polygon loop for (lPolygonIndex = 0; lPolygonIndex < lPolygonCount; lPolygonIndex++)
// Shaded, just find the normal for the surface
if (lDrawMode == DRAW_MODE_LIGHTED)
{
VECTOR normal;
POLYGON poly;
// Need 3 points for a normal on a plane.
pVertex = (GLdouble *)pVertexArray;
poly.x1 = *pVertex++;
poly.y1 = *pVertex++;
poly.z1 = *pVertex++;
pVertex = (GLdouble *)pVertexArray;
poly.x2 = *pVertex++;
poly.y2 = *pVertex++;
poly.z2 = *pVertex++;
pVertex = (GLdouble *)pVertexArray;
poly.x3 = *pVertex++;
poly.y3 = *pVertex++;
poly.z3 = *pVertex++;
determine_normal(&poly, normal);
glNormal3fv(normal);
}
NEEDED DEFS and FUNCTIONS
typedef struct tagPOLYGON
{ /* Polygon information */
float x1; /* First vertex x coordinate */
float y1; /* First vertex y coordinate */
float z1; /* First vertex z coordinate */
float x2; /* Second vertex x coordinate */
float y2; /* Second vertex y coordinate */
float z2; /* Second vertex z coordinate */
float x3; /* Third vertex x coordinate */
float y3; /* Third vertex y coordinate */
float z3; /* Third vertex z coordinate */
float x4; /* Fourth vertex x coordinate */
float y4; /* Fourth vertex y coordinate */
float z4; /* Fourth vertex z coordinate */
}POLYGON;
typedef POLYGON *PPOLYGON;
typedef GLfloat VECTOR; /* 3 vector */
#ifndef VSMALL
#define VSMALL (1e-10) /* Small float */
#endif
float vecnorm(VECTOR v)
{
/* Normalize vector to unit length. Return its original length. */
float x, y, z, s, r, rr;
/* Make the vector components positive */
x = v; y = v; z = v;
if( x < 0.0 )
x = -x;
if( y < 0.0 )
y = -y;
if( z < 0.0 )
z = -z;
/* Find the square of the length */
s = x * x + y * y + z * z;
/* The best guess of the length is the largest component. Find it. */
if( x < y )
x = y;
if( x < z )
x = z;
if( x < VSMALL )
{
rr = 0.0;
v = v = v = 0.0;
}
else
{
/* Polish up the guess using 3 in-line N-R iterations */
r = x + s / x;
r = 0.25 * r + s / r;
r = 0.5 * ( r + s / r );
/* Normalize the vector */
rr = r;
r = 1.0 / r;
v *= r;
v *= r;
v *= r;
}
/* Return the length */
return( rr );
}
void determine_normal(PPOLYGON poly, VECTOR normal)
{
/* It is necessary to determine the normals of each polygon in order to */
/* do the lighting correctly. Note only the first three vertices of the */
/* polygon are used for this normal calculation. */
float A, B, C;
/* Firstly, find the plane coefficients */
/* (page 308, "Computer Graphics", Hearn and Baker) */
A = poly->y1*(poly->z2 - poly->z3) + poly->y2*(poly->z3 - poly->z1) + poly->y3*(poly->z1 - poly->z2);
B = poly->z1*(poly->x2 - poly->x3) + poly->z2*(poly->x3 - poly->x1) + poly->z3*(poly->x1 - poly->x2);
C = poly->x1*(poly->y2 - poly->y3) + poly->x2*(poly->y3 - poly->y1) + poly->x3*(poly->y1 - poly->y2);
/* The surface normal vector has coordinates (A, B, C) */
normal = A;
normal = B;
normal = C;
vecnorm(normal);
}