Archived

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

Drawing Polygons?

This topic is 5752 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

hello i'm doing a 3d engine just for fun on my spare time ( wich is not much ) with my friends but i'm having trouble with framerate! It's not high enough, with a floor and a 6 sided cube with texture i get about 150fps if i'm close else about 600! this is my structure for holding the variables of the map! struct map_info { private: public: float Starting_Point[3]; int Starting_Direction; int num_polygons; int num_textures; char *texture_files[10]; float Polygon[100][4][5]; int Polygon_Texture[100]; }; and here i load my map! int map::Load_Map() { short int polygon_temp; new_map = true; FILE *bana; bana = fopen("data/maps/map1.txt", "rt"); rewind(bana); fscanf(bana, "Starting_Point %f %f %f /n", &map_info.Starting_Point[0], &map_info.Starting_Point[1], &map_info.Starting_Point[2]); fscanf(bana, "Starting_Direction %f /n", &map_info.Starting_Direction); fscanf(bana, "Polygons %i /n", &map_info.num_polygons); fscanf(bana, "Textures %i /n", &map_info.num_textures); for(int loop=0; loop < map_info.num_polygons; loop++) { fscanf(bana, " /n"); fscanf(bana, "Polygon %i /n", &polygon_temp); fscanf(bana, "Texture %i /n", &map_info.Polygon_Texture[loop]); fscanf(bana, "Vertex %f %f %f %f %f /n", &map_info.Polygon[loop][0][0], &map_info.Polygon[loop][0][1], &map_info.Polygon[loop][0][2], &map_info.Polygon[loop][0][3], &map_info.Polygon[loop][0][4]); fscanf(bana, "Vertex %f %f %f %f %f /n", &map_info.Polygon[loop][1][0], &map_info.Polygon[loop][1][1], &map_info.Polygon[loop][1][2], &map_info.Polygon[loop][1][3], &map_info.Polygon[loop][1][4]); fscanf(bana, "Vertex %f %f %f %f %f /n", &map_info.Polygon[loop][2][0], &map_info.Polygon[loop][2][1], &map_info.Polygon[loop][2][2], &map_info.Polygon[loop][2][3], &map_info.Polygon[loop][2][4]); fscanf(bana, "Vertex %f %f %f %f %f /n", &map_info.Polygon[loop][3][0], &map_info.Polygon[loop][3][1], &map_info.Polygon[loop][3][2], &map_info.Polygon[loop][3][3], &map_info.Polygon[loop][3][4]); } Texture[0] = texture_load.BMP("data/textures/textur1.bmp"); Texture[1] = texture_load.BMP("data/textures/textur2.bmp"); return 0; //return 0, there was no errors } and here i draw my map! int map::Draw_Map() { for(int loop = 0; loop < map_info.num_polygons; loop++) { glBindTexture(GL_TEXTURE_2D, Texture[map_info.Polygon_Texture[loop]]); glEnable(GL_TEXTURE_2D); glBegin(GL_POLYGON); glTexCoord2f(map_info.Polygon[loop][0][3], map_info.Polygon[loop][0][4]); glVertex3f(map_info.Polygon[loop][0][0], map_info.Polygon[loop][0][1], map_info.Polygon[loop][0][2]); glTexCoord2f(map_info.Polygon[loop][1][3], map_info.Polygon[loop][1][4]); glVertex3f(map_info.Polygon[loop][1][0], map_info.Polygon[loop][1][1], map_info.Polygon[loop][1][2]); glTexCoord2f(map_info.Polygon[loop][2][3], map_info.Polygon[loop][2][4]); glVertex3f(map_info.Polygon[loop][2][0], map_info.Polygon[loop][2][1], map_info.Polygon[loop][2][2]); glTexCoord2f(map_info.Polygon[loop][3][3], map_info.Polygon[loop][3][4]); glVertex3f(map_info.Polygon[loop][3][0], map_info.Polygon[loop][3][1], map_info.Polygon[loop][3][2]); glEnd(); glDisable(GL_TEXTURE_2D); } return 0; //return 0, there was no errors } i'm pretty new to OpenGL but not to new to c++, but i wonder if anyone can help me with a link or telling me right here how i can improve framerate, BTW i'm using NeheGL. Thanks in advance! Edited by - CondiS on March 19, 2002 3:01:00 PM

Share this post


Link to post
Share on other sites
I''m starting too and have a similar problem. The first problem you have it you are drawing everying in the level regardless of whether or not you see it. Most indoor games use levels made of sectors, and the openings between these sectors are used to define what parts of the level outside the sector you''re in can be seen. Though obviously OpenGL doesn''t draw polygons that can''t be seen on the screen, you are still sending that information to opengl and it has to process it. If you figure out what doesn''t need to be draw youself it''s much faster. The other thing that slows your engine down is your used of polygons. You should be able to draw at least your floor with triangles strips, which are much faster than polygons. You can probably use strips for much of your level.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Brad, the FPS change when he''s ''close'' means that this is a fillrate issue, not anything that triangle strips is going to help.

What kind of video card are you using, CondiS? 150 fps seems pretty good to me...

Share this post


Link to post
Share on other sites
i have tried triangle strip but it didnt speed it up more than 2 fps =(, but i''m going to follow onw of your ideas =)
finding what polygons to draw and not can''t be that difficult =)
se you later have a lot to do on my engine

Share this post


Link to post
Share on other sites