My 3D House
I''ve modified NeHe''s Lesson 10 (3D world) tutorial to include 2 textures, and multiple files to use for input. Each files data is stored in the array sectors[2]. I also added things like strafing, crouching, and you now go faster.
The code below is found in my DrawGLScene() function. As you can see, I had to nest my loops in order to display both models, and there''s a lot of crap to do within these loops. I was wondering if this is an efficient enough method for me to display upwards of 10 sectors, or if that would be too slow. Should I drop the .txt file input idea and declare my vertex arrays in a header? or what? thanks in advance.
int numtriangles;
for(sectorloop=0; sectorloop<2; sectorloop++)
{
glBindTexture(GL_TEXTURE_2D, textures[sectorloop]);
numtriangles = sectors[sectorloop].numtriangles;
// Process Each Triangle for the current sector
for (int loop_m = 0; loop_m < numtriangles; loop_m++)
{
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
x_m = sectors[sectorloop].triangle[loop_m].vertex[0].x;
y_m = sectors[sectorloop].triangle[loop_m].vertex[0].y;
z_m = sectors[sectorloop].triangle[loop_m].vertex[0].z;
u_m = sectors[sectorloop].triangle[loop_m].vertex[0].u;
v_m = sectors[sectorloop].triangle[loop_m].vertex[0].v;
glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);
x_m = sectors[sectorloop].triangle[loop_m].vertex[1].x;
y_m = sectors[sectorloop].triangle[loop_m].vertex[1].y;
z_m = sectors[sectorloop].triangle[loop_m].vertex[1].z;
u_m = sectors[sectorloop].triangle[loop_m].vertex[1].u;
v_m = sectors[sectorloop].triangle[loop_m].vertex[1].v;
glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);
x_m = sectors[sectorloop].triangle[loop_m].vertex[2].x;
y_m = sectors[sectorloop].triangle[loop_m].vertex[2].y;
z_m = sectors[sectorloop].triangle[loop_m].vertex[2].z;
u_m = sectors[sectorloop].triangle[loop_m].vertex[2].u;
v_m = sectors[sectorloop].triangle[loop_m].vertex[2].v;
glTexCoord2f(u_m,v_m); glVertex3f(x_m,y_m,z_m);
glEnd();
}
}
...also, how do you post code in those code boxes?
----------Invincible intelligence isn't evincible.
Look into Display Lists. To format the code you can use [ source ] and [ /source ] for the little box or
and
to simply format it
____________________________________________________________AAAAA: American Association Against Adobe AcrobatYou know you hate PDFs...
I''m using a bunch of different textures, so display lists wouldn''t work in this case.
----------Invincible intelligence isn't evincible.
Cuz the textures are mapped 6 times across on one quad, and maybe only 3 on another.
----------Invincible intelligence isn't evincible.
How many triangles/quads do you have in your scene? If not more than a few hundred, try to just write the entire scene into one large display list. i.e...
// global
GLuint g_Disp;
// in the scene initialization function
g_Disp=glGenLists(1);
glNewList(g_DispModel,GL_COMPILE);
...
glEndList();
//then in the scene rendering function call:
glCallList(g_Disp);
// global
GLuint g_Disp;
// in the scene initialization function
g_Disp=glGenLists(1);
glNewList(g_DispModel,GL_COMPILE);
...
glEndList();
//then in the scene rendering function call:
glCallList(g_Disp);
sorry, the "..." was also supposed to include the comment: include your entire sector writing loop here...
Ahhh, clever. I''m taking up another project now, expanding on the 3D house, and thought that in DrawGLScene() I could put one sector in a display list, and then use a for loop to replicate that sector across the z-plane. But that reset my ModelView Matrix (or whatever matrix is cleared by glLoadIdentity()), making it impossible to move the camera, as it was constantly being reset. This was so simple it escaped me. Thank you much.
----------Invincible intelligence isn't evincible.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement