Hello Everyone. I was trying to get my head tightly wrapped around the Lesson 10 code, and I decided the best way would be to modify it a bit. So, I changed some of the functions to allow polygons to be drawn instead of just triangles. The problem is, trying to draw anything other than a triangle results in black, tryangle shaped holes in the polygon. Here is the setup code I changed:
void SetupWorld()
{
float x, y, z, u, v;
int numpolygons, maxverts, t;
FILE *filein;
char oneline[255];
filein = fopen("data/world.spm", "rt"); // File To Load World Data From
readstr(filein,oneline);
sscanf(oneline, "NUMPOLLIES %d\n", &numpolygons);
sector1.polygon = new POLYGON[numpolygons];
sector1.numpolygons = numpolygons;
for (int loop = 0; loop < numpolygons; loop++)
{
readstr(filein,oneline);
sscanf(oneline, "VERTS %d\n", &maxverts);
sector1.polygon[loop].maxverts = maxverts;
for (int vert = 0; vert < maxverts; vert++)
{
readstr(filein,oneline);
sscanf(oneline, "%f %f %f %f %f %i", &x, &y, &z, &u, &v, &t);
sector1.polygon[loop].vertex[vert].x = x;
sector1.polygon[loop].vertex[vert].y = y;
sector1.polygon[loop].vertex[vert].z = z;
sector1.polygon[loop].vertex[vert].u = u;
sector1.polygon[loop].vertex[vert].v = v;
sector1.polygon[loop].t = t;
}
}
fclose(filein);
return;
}
And the drawing code:
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
glLoadIdentity(); // Reset The View
GLfloat x_m, y_m, z_m, u_m, v_m;
GLfloat xtrans = -xpos;
GLfloat ztrans = -zpos;
GLfloat ytrans = -walkbias-0.25f;
GLfloat sceneroty = 360.0f - yrot;
int numpolygons;
glRotatef(lookupdown,1.0f,0,0);
glRotatef(sceneroty,0,1.0f,0);
glTranslatef(xtrans, ytrans, ztrans);
numpolygons = sector1.numpolygons;
// Process Each Triangle
for (int loop_m = 0; loop_m < numpolygons; loop_m++)
{
glBindTexture(GL_TEXTURE_2D, textures[sector1.polygon[loop_m].t].texID);
glBegin(GL_POLYGON);
for(int loop_v = 0; loop_v < sector1.polygon[loop_m].maxverts;loop_v++){
glNormal3f( 0.0f, 0.0f, 1.0f);
x_m = sector1.polygon[loop_m].vertex[loop_v].x;
y_m = sector1.polygon[loop_m].vertex[loop_v].y;
z_m = sector1.polygon[loop_m].vertex[loop_v].z;
u_m = sector1.polygon[loop_m].vertex[loop_v].u;
v_m = sector1.polygon[loop_m].vertex[loop_v].v;
glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);}
glEnd();
}
return TRUE; // Everything Went OK
}
What did I do wrong? Thanks for any help, Biubid_boy.