Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Please help me with this code...

This topic is 6459 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 =)

Share this post

Link to post
Share on other sites
Guest Anonymous Poster
How do you know it works if you can not see anything.

I would look at the init code first.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!