OpenGL and C vs C++
I personally think C is the way to go. C++ might be good for GUI''s and whatnot, but when it comes down to doing efficient graphics code, you want to make as few function calls as possible. You want to avoid setting the same things over again if they''ve already been set (textures, colors, etc). I find it difficult to impliment that well with classes since you basically want to sort and render things on a polygon (or strip or whatever) basis rather than on an "object" basis. When you try to do all that with C++, you might end up basically writing C code in a .cpp file, and I prefer direct access to data in structs and arrays over accessor methods any day. If you can optimize it with classes, more power to you, but I''m sticking to C when it comes to rendering.
I think the keyword in all of that was the second one ''personaly''... you like to do it that way, I think its more logical to render per object (grouping object types to cut down on state swtiching) but thats just my personal choice
quote:Original post by jitspoe
C++ might be good for GUI''s and whatnot, but when it comes down to doing efficient graphics code, you want to make as few function calls as possible. You want to avoid setting the same things over again if they''ve already been set (textures, colors, etc).
So group your data by texture, color, etc. Write a data manager that does this for you.
quote:
I find it difficult to impliment that well with classes since you basically want to sort and render things on a polygon (or strip or whatever) basis rather than on an "object" basis.
No offense, but your ineptness at a technique is not a valid argument against it.
Not that I''m advocating C++. This is a pointless argument/discussion/thread. Yeah, Doom3''s graphics engine is written in C. UT2003/Unreal Championship''s is written in C++. If you''re asking a question like this, your code is unlikely to be efficient or well-structured enough for it to make a difference.
So get back to work. Real work.
personally i use c++ but more as ''a better c''(tm)
in the old days c used to be quicker cause the c compilers used to be better than there c++ counterparts (mainly cause c is a simpler language IIRC only 21 keywords), nowadays c++ compilers will produce code around the same speed a c compilers.
what language u choose is not gonna make any difference to the final speed of your game all speed is in made in the hands of the programmeur/s (usually by choosing the most efficent algorithms)
personally i feel sorely tempted when i read posts ''java is slow'' of rewriting my KEA game in java, the only thing stopping me is, i dont know java + are unwilling to spend a month learning it.
http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
in the old days c used to be quicker cause the c compilers used to be better than there c++ counterparts (mainly cause c is a simpler language IIRC only 21 keywords), nowadays c++ compilers will produce code around the same speed a c compilers.
what language u choose is not gonna make any difference to the final speed of your game all speed is in made in the hands of the programmeur/s (usually by choosing the most efficent algorithms)
personally i feel sorely tempted when i read posts ''java is slow'' of rewriting my KEA game in java, the only thing stopping me is, i dont know java + are unwilling to spend a month learning it.
http://uk.geocities.com/sloppyturds/kea/kea.html
http://uk.geocities.com/sloppyturds/gotterdammerung.html
I understand the ''personal preference'' argument, but I was just wondering if there might possibly be a performance issue. But thanks for the information.
Yes, there is a performance issue with C and C++. You should be coding everything in ASM.
More seriously though, as has already been stated, you can get the same speed from C++ as from C (C being a subset of C++, this is to be expected).
If you care about performance, do some profiling, and find where the slowest parts of your code are. Most likely there''ll be one or two inner loops which could be optimised, and nothing else will make any difference. If you''re concerned about the overhead of virtual functions, bear in mind that all functions have a calling overhead, and in speed-critical inner loops you''re not going to be calling functions anyway (unless they''re inlined).
____________________________________________________________
www.elf-stone.com
More seriously though, as has already been stated, you can get the same speed from C++ as from C (C being a subset of C++, this is to be expected).
If you care about performance, do some profiling, and find where the slowest parts of your code are. Most likely there''ll be one or two inner loops which could be optimised, and nothing else will make any difference. If you''re concerned about the overhead of virtual functions, bear in mind that all functions have a calling overhead, and in speed-critical inner loops you''re not going to be calling functions anyway (unless they''re inlined).
____________________________________________________________
www.elf-stone.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement