Advertisement

Please help me with this code...

Started by February 15, 2001 02:55 PM
0 comments, last by sAcreDkiLLa 23 years, 9 months ago
Hi People, I began to write a very simple 3d-Engine and used some of the code of NeHe''s Lesson 10. This code works, but when I start it i wont see anything... i think there is something wrong with the structures : typedef struct tagVERTEX { float x, y, z; float u, v; } VERTEX; typedef struct tagTRIANGLE { char* texturename; VERTEX vertex[3]; } TRIANGLE; typedef struct tagSECTOR { int numtriangles; TRIANGLE* triangles; } SECTOR; typedef struct tagWORLD { int numsectors; int ActiveSector; SECTOR* sectors; } WORLD; WORLD TheWorld; void readstr(FILE *f,char *string) { do { fgets(string, 255, f); } while ((string[0] == ''/'') || (string[0] == ''\n'')); return; } void LoadMap(char* filename, WORLD welt) { float x, y, z, u, v; char OneLine[255]; FILE* levelfile = fopen(filename, "rt"); int numsectors; int numtriangles; int ActiveSector; readstr(levelfile, OneLine); sscanf(OneLine, "NUMSECTORS %d\n", &numsectors); welt.sectors = new SECTOR[numsectors]; welt.numsectors = numsectors; readstr(levelfile, OneLine); sscanf(OneLine, "SECTOR %d\n", &ActiveSector); readstr(levelfile, OneLine); sscanf(OneLine, "NUMTRIANGLES %d\n", &numtriangles); welt.sectors[ActiveSector].triangles = new TRIANGLE[numtriangles]; welt.sectors[ActiveSector].numtriangles = numtriangles; welt.ActiveSector = ActiveSector; for (int loop = 0; loop < numtriangles; loop++) { for (int vert = 0; vert < 3; vert++) { readstr(levelfile, OneLine); sscanf(OneLine, "%f %f %f %f %f %f %f", &x, &y, &z, &u, &v); welt.sectors[ActiveSector].triangles[loop].vertex[vert].x = x; welt.sectors[ActiveSector].triangles[loop].vertex[vert].y = y; welt.sectors[ActiveSector].triangles[loop].vertex[vert].z = z; welt.sectors[ActiveSector].triangles[loop].vertex[vert].u = u; welt.sectors[ActiveSector].triangles[loop].vertex[vert].v = v; } } fclose(levelfile); return; } GLvoid BuildList() { GLfloat x_m, y_m, z_m; LevelList = glGenLists(1); glNewList(LevelList, GL_COMPILE); glColor3f(1.0f, 0.0f, 0.0f); for (int loop1 = 0; loop1 < TheWorld.numsectors; loop1++) { TheWorld.ActiveSector = loop1; for (int loop2 = 0; loop2 < TheWorld.sectors[TheWorld.ActiveSector].numtriangles; loop2++) { glBegin(GL_TRIANGLES); x_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[0].x; y_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[0].y; z_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[0].z; glVertex3f(x_m, y_m, z_m); x_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[1].x; y_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[1].y; z_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[1].z; glVertex3f(x_m, y_m, z_m); x_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[2].x; y_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[2].y; z_m = TheWorld.sectors[TheWorld.ActiveSector].triangles[loop2].vertex[2].z; glVertex3f(x_m, y_m, z_m); glEnd(); } } glEndList(); } I know it''s a bit long but please help me anybody ! think like a wise man but communicate in the language of the people =)
think like a wise man but communicate in the language of the people =)
How do you know it works if you can not see anything.

I would look at the init code first.

This topic is closed to new replies.

Advertisement