Jump to content
  • Advertisement

Archived

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

Drath

Q3 BSP code optimision

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

I''m a newbie to C++/DX (5 days so far!) so theres a few things I''m missing on. I converted a program from the texture source that comes from the DX SDK to load a text version of a BSP file (I made a program that takes only the face and vertex lumps from the file and builds it into an ASCII file). To render it I made two structures: typedef struct tagPNT { float px, py, pz; float u1, v1, u2, v2; float nx, ny, nz; unsigned char r, g, b, a; } PNT; typedef struct tagPOLYGON { int texidx, type, vtxpos, numvtx; D3DVERTEX PlyVtxF[16]; D3DVERTEX PlyVtxB[16]; // used to show both sides. I belive the back sides are true because OGL renders polygons the other way round. } POLYGON; I firstly load all ther verticies into a PNT array then I build the POLYGON''s and take the values from the PNT''s. I render them by going through the true number of polygons and making a fan primitive. My first problem is that I have to predefine a max number of PNT''s, POLYGON''s and D3DVERTEX''s with a const like this: const DWORD MAXVTX = 14000; PNT pnt[MAXVTX]; const DWORD MAXPLG = 2500; POLYGON plg[MAXPLG]; I have a value I load from a file but I cannot use it because it isn''t a constant. How do I fix this? (I only use faces of type 1) My next problem is more of a question. What is the best way to cull the polygons? Do I need to check if they are facing the camera or is it already built in (I know the formula). What other ways can I add? Finally, I currently use just a single texture for the whole lot because DX only nativly supports bmp''s and one other thing while the textures are jpg''s and tga''s. Does anyone know of some source or algorithm that I could use? Thanks...

Share this post


Link to post
Share on other sites
Advertisement
quote:

My first problem is that I have to predefine a max number of PNT''s, POLYGON''s and D3DVERTEX''s with a const like this:
const DWORD MAXVTX = 14000;
PNT pnt[MAXVTX];
const DWORD MAXPLG = 2500;
POLYGON plg[MAXPLG];
I have a value I load from a file but I cannot use it because it isn''t a constant. How do I fix this? (I only use faces of type 1)



You need to new the array and delete it manually. eg

  
// Creation

PNT* pnt = new PNT[number];

// Make sure you delete the memory when you don''t need it!!!

delete[] PNT;


quote:

My next problem is more of a question. What is the best way to cull the polygons? Do I need to check if they are facing the camera or is it already built in (I know the formula). What other ways can I add?



Direct3D does back-face culling for you automatically (assuming you haven''t overrriden that renderstate) based on the order you specify your vertices in your triangles (clockwise or counter clockwise). You might want to consider doing frustrum culling (do a search) for a start to reduce the number of primitives you draw. After that you might want to look into occlusion culling.

quote:

Finally, I currently use just a single texture for the whole lot because DX only nativly supports bmp''s and one other thing while the textures are jpg''s and tga''s. Does anyone know of some source or algorithm that I could use?



You can use D3DXCreateTextureFromFile to create textures from files containing images of the following formats:

.bmp, .dds, .dib, .jpg, .png, and .tga


Hope this helps,

Rory.

Share this post


Link to post
Share on other sites
Thanks a lot!
I rebuilt my base. I was using the source from the texture tutorial and now I am using a source from the D3DX examples. This works out a lot better and I am using a vertex buffer for all the points and a list of polygons that show which points are rendered.

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!