Sign in to follow this  
Vanshi

OpenGL Need help for better performance

Recommended Posts

Hi guys, I am working on a project that involves importing textured 3ds max objects of the .3ds format into OpenGL . i have been able to do that but i have observed that it takes a lot of time to render the scence and loading just 4 buildings(.3ds format) takes upto 250 MB. The framerate is very low too. Can anyone give tips/tricks on how to improve performance and reduce memory usage? Would appreciate ur help a lot. Thanx.

Share this post


Link to post
Share on other sites
Hi. You'll need to give much more information than that before anyone can help. Firstly can you tell us how many vertices/triangles are in your models. And secondly what is your hardware spec and what drivers you have got. 250Mb is way too much theres something very wrong there. For improving performance have a look at vertex buffer objects or even display lists if youre not already using them. Post more details or some code and you'll get help.

Share this post


Link to post
Share on other sites
You're probably trying to load four huge buildings into RAM, which implies they contain a lot of polygons. At least tell us what size the 3ds files are (or better yet, as comedypedro said, how many polygons each building consists of). You're probably trying to render as many as a several million polys (based on your RAM usage and framerate), which - unless you're doing things very inefficiently - would clog up even the newest hardware.

Share this post


Link to post
Share on other sites
I am sorry for that really low amount of information. But being a newbie i didn't know much what to ask. I did find out the polygon count for my models.
1:32668 polygons file is 830 KB
2:59610 polygons --1.54 mB
3: 4058 polygons --116 KB
4: 224 polygons -- 11.7KB

so i guess from the earlier replies that i should try to reduced the polygon count for the .3ds objects. Any other suggestions are welcome. Thanx for ur time.

Share this post


Link to post
Share on other sites
Those polygon counts seem pretty reasonable for current hardware and shouldn't under any circumstances take up 250 megabytes in RAM. Check your code for memory leaks and be sure to free up all temporarily allocated objects. Can you also post your system specs? For instance, I wouldn't expect much over 4-5 FPS on a GeForce 2 with close to 100000 polygons on the screen.

Share this post


Link to post
Share on other sites
Agreed, that amount of polys shouldnt be a problem for a decent speced machine. How do you know that 250mg of memory is being used?? Or maybe you meant 2.5megs?? 830k + 1.54 mB + 116 KB + 11.7KB = about 2.5mg so Im assuming thats what you mean. If thats giving your machine trouble then like irreversible says youre doing something wrong. Let us know your specs and the relevant code and we'll see what the problem is.

Share this post


Link to post
Share on other sites
Tip for better performance: use a display list. This makes material changes pre-calculated, and that translates to much higher frame rates (I had my framerates drop 4 times by using a display list!). This has nothing to do with memory though. After you compile the display list, delete all the mesh info you have loaded (vertices, materials, etc).

There are also other options like VBO's or vertex arrays which you could look into.

Share this post


Link to post
Share on other sites
Thank u for ur replies everyone.
My machine specs are as follows:
AMD 3000+
MSI RS-480 m2 IL motherboard
onboard video(ATI Xpress Chipset)
1 GB RAM

the code can be found on APRON TUTORIALS for loading 3ds objects into OpenGL
http://www.morrowland.com/apron/tut_gl.php
3DS loader with just a few changes in the code for placing multiple objects into scene and some camera movement with the keyboard.
I found the memory usage with the Taskmanager

Share this post


Link to post
Share on other sites
Well Im not really an expert on hardware but I reckon the problem or part of the problem lies with your hardware. The CPU is fine but for graphics youre probably better of with a dedicated video card - even something cheap like an FX5200 would do the job. Like I said Im not really up on hardware so maybe someone else can confirm this.

I was able to optimise my 3ds code a bit by using temporary pointers to avoid excessive dereferencing i.e. if you have something like


for(iCurrectVertex = 0; iCurrectVertex < NumVerts; iCurrectVertex ++)
{
pModel->pObject[iCurrentObject]->pVertexList[iCurrectVertex] = some_value;
}





you can speed things up by



float* pVertexList = pModel->pObject[iCurrentObject]->pVertexList
for(iCurrectVertex = 0; iCurrectVertex < NumVerts; iCurrectVertex ++)
{
pVertexList[iCurrectVertex] = some_value;
}





Hope this helps, and Id also consider using ms3d over 3ds, its a much more user friendly format - check the other tutorial on that link you gave.

Share this post


Link to post
Share on other sites
Hi guys,
thanks for all the suggestions. i will try them out and let u know what the results are. but i cant use ms3ds format for my project. it has to be .3ds formats. once again thank u for all ur concern and time.

Share this post


Link to post
Share on other sites
Hi guys,
i need help on another issue. Somebody suggested to go for objects (buildings) in multiple resolution. as i go away from the building, the level of detail should decrease. this may help my frame rate go up. any suggestions on how to accomplish this will be really welcome. thanks for all the help earlier. working on the display list implementaion right now.

Share this post


Link to post
Share on other sites
That technique is used quite often in games/graphics, its often called dynamic level of detail or something similar. One way you could do this is to simply have different .3ds models for the various levels of detail you require. For a simple example : you keep the current model for close up viewing, have a reduced detail model for medium ranges and maybe just simply draw a box at long range. You can experiment to find out what works best and the idea is that the user dosent realise what is happening. In 3ds max theres an option somewhere to reduce the number of faces/vertices in a model, this might help you create simpler models. Then you simply calculate the distance from the camera to each model and decide which model to draw. Like I said, experimentation is needed. You could also look into occlusion or frustum culling which basically means that you only send the geometry to be rendered if its actually in front of the camera. This can involve a bit of maths though but most games/graphics programs also use this technique.

Share this post


Link to post
Share on other sites
Thank you for the suggestion. but the problem with loading two or more objects would elevate my problem of memory usage. i have already been trying that direct replacement and it has given good results. the frame rate does increase a little bit(by 8-9 frames). but then the memory usage increases. so i was hoping u guys could help me with more advanced methods of implementing this teachnique. thank u for ur time.

Share this post


Link to post
Share on other sites
Well you have 1 gig of ram so I dont see why youre worried about memory!!
The only other thing I can think of is to keep the one model but only draw the sides that are facing the camera. This would involve implementing some form of geometry management such as a quad-tree or bsp-tree. You may get away with spliting each building into 4 separate models (one for each wall, assuming theyre basic 4 sided buildings) and only drawing what will actually be seen. But like I said youve more than enough ram so why worry about the extra memory. My PC has only 1/2 gig and it runs Doom 3 and Quake 4!!!

Share this post


Link to post
Share on other sites
Some people will disagree with me, but you don't really need to be so careful with memory like we used to do. Now, the requirements usually fall on the rendering, as in the amount of rendering. Memory very unlikely will run out unless you have a low quality video card and use high resolution textures in a no compression format.
That is not to say that you should just waste memory because you can, but on modern computers, trading memory for speed is probably always better, unless it is a lot of memory and next to nil on the speed.

Share this post


Link to post
Share on other sites
Thank you for the suggestion. just like u said it is not the ram i am worried about. The problem is that the project i am doing is academic(counts for grades)and i have to do the rendering in realtime and on machines with lower memory than mine. i will try the quad-tree or bsp-tree technique u have suggested. the fps is really low just about 15 FPS with nothing but the basic flat textured surface with two billboarded trees.it goes down to 10 when i add just 4 buildings.
Also can u guys suggest good tutorials online for billboarding. thank you once again for ur time.
and about the quad-tree method can this be done for 3ds objects too??

Share this post


Link to post
Share on other sites
Well I may have missed a few things so if this is already said feel free to ignore it. Firstly make sure you are running in hardware(I assume part of the problem is due to running in software). Even in software when I was writing my rendering engine I was able to get a decent 30 fps with a lot of polygons, ofcourse I did use a few occlusion culling tricks. So its definitely feasible. I think the cost of FX 5200 in India at the moment is around Rs 5000 - 6000 depending on where you buy it. If you can afford it buy it but otherwise go with a few tricks like quad-tree/octree culling to reduce polygons thrown at the card.

Share this post


Link to post
Share on other sites
Here you go : Nehe Billboarding Tutorial

To answer your other question, yes you can store any geometry in a quad tree.

To be honest I dont think its very fair of your lecturers/university/college to expect you to do 3d graphics on low spec machines. If you want to post your rendering code I'll have a look and see if I can suggest how to speed it up.

Share this post


Link to post
Share on other sites
thank you for ur offer comedypro.but how do i post the code online? i don't have my own website. i could send it to u if you could give me ur mail id or something. really appreciate ur help. thank you.

Share this post


Link to post
Share on other sites
Check the forum faqs for how to post code in a forum. Its probably best to post it here rather than mail it to me so that other people can help or be helped by it!!

Share this post


Link to post
Share on other sites
Hi guys,
thanks for the help. i have managed to solve the memory problem that i was having. i was not deleting the textures when redrawing the window. without that the memory usage increased. now that the problem has been solved the fps has increased to 26 to 24 fps. i am looking for more ways to increase performance. thank u all for the help.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Forum Statistics

    • Total Topics
      627733
    • Total Posts
      2978839
  • Similar Content

    • By DelicateTreeFrog
      Hello! As an exercise for delving into modern OpenGL, I'm creating a simple .obj renderer. I want to support things like varying degrees of specularity, geometry opacity, things like that, on a per-material basis. Different materials can also have different textures. Basic .obj necessities. I've done this in old school OpenGL, but modern OpenGL has its own thing going on, and I'd like to conform as closely to the standards as possible so as to keep the program running correctly, and I'm hoping to avoid picking up bad habits this early on.
      Reading around on the OpenGL Wiki, one tip in particular really stands out to me on this page:
      For something like a renderer for .obj files, this sort of thing seems almost ideal, but according to the wiki, it's a bad idea. Interesting to note!
      So, here's what the plan is so far as far as loading goes:
      Set up a type for materials so that materials can be created and destroyed. They will contain things like diffuse color, diffuse texture, geometry opacity, and so on, for each material in the .mtl file. Since .obj files are conveniently split up by material, I can load different groups of vertices/normals/UVs and triangles into different blocks of data for different models. When it comes to the rendering, I get a bit lost. I can either:
      Between drawing triangle groups, call glUseProgram to use a different shader for that particular geometry (so a unique shader just for the material that is shared by this triangle group). or
      Between drawing triangle groups, call glUniform a few times to adjust different parameters within the "master shader", such as specularity, diffuse color, and geometry opacity. In both cases, I still have to call glBindTexture between drawing triangle groups in order to bind the diffuse texture used by the material, so there doesn't seem to be a way around having the CPU do *something* during the rendering process instead of letting the GPU do everything all at once.
      The second option here seems less cluttered, however. There are less shaders to keep up with while one "master shader" handles it all. I don't have to duplicate any code or compile multiple shaders. Arguably, I could always have the shader program for each material be embedded in the material itself, and be auto-generated upon loading the material from the .mtl file. But this still leads to constantly calling glUseProgram, much more than is probably necessary in order to properly render the .obj. There seem to be a number of differing opinions on if it's okay to use hundreds of shaders or if it's best to just use tens of shaders.
      So, ultimately, what is the "right" way to do this? Does using a "master shader" (or a few variants of one) bog down the system compared to using hundreds of shader programs each dedicated to their own corresponding materials? Keeping in mind that the "master shaders" would have to track these additional uniforms and potentially have numerous branches of ifs, it may be possible that the ifs will lead to additional and unnecessary processing. But would that more expensive than constantly calling glUseProgram to switch shaders, or storing the shaders to begin with?
      With all these angles to consider, it's difficult to come to a conclusion. Both possible methods work, and both seem rather convenient for their own reasons, but which is the most performant? Please help this beginner/dummy understand. Thank you!
    • By JJCDeveloper
      I want to make professional java 3d game with server program and database,packet handling for multiplayer and client-server communicating,maps rendering,models,and stuffs Which aspect of java can I learn and where can I learn java Lwjgl OpenGL rendering Like minecraft and world of tanks
    • By AyeRonTarpas
      A friend of mine and I are making a 2D game engine as a learning experience and to hopefully build upon the experience in the long run.

      -What I'm using:
          C++;. Since im learning this language while in college and its one of the popular language to make games with why not.     Visual Studios; Im using a windows so yea.     SDL or GLFW; was thinking about SDL since i do some research on it where it is catching my interest but i hear SDL is a huge package compared to GLFW, so i may do GLFW to start with as learning since i may get overwhelmed with SDL.  
      -Questions
      Knowing what we want in the engine what should our main focus be in terms of learning. File managements, with headers, functions ect. How can i properly manage files with out confusing myself and my friend when sharing code. Alternative to Visual studios: My friend has a mac and cant properly use Vis studios, is there another alternative to it?  
    • By ferreiradaselva
      Both functions are available since 3.0, and I'm currently using `glMapBuffer()`, which works fine.
      But, I was wondering if anyone has experienced advantage in using `glMapBufferRange()`, which allows to specify the range of the mapped buffer. Could this be only a safety measure or does it improve performance?
      Note: I'm not asking about glBufferSubData()/glBufferData. Those two are irrelevant in this case.
    • By xhcao
      Before using void glBindImageTexture(    GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format), does need to make sure that texture is completeness. 
  • Popular Now