OpenGL Engine in C++

It’s been so long that I’ve looked at books on plain C++, that I don’t have any really good recommenations for books to learn C++. A book that I’ve found interesting is the The ANSI/ISO C++ professional programmer’s guide. (or something like that.) It explains a lot of the latest standards. (New casting methods, a little STL, etc.) It probably wouldn’t really be good as a beginner’s book. But once you get the hang of C++ more, it’s pretty informative on the latest standards.

If you optimize your code well enough, objects can be just as fast as standard C coding. For instance, overloaded operators, and other smaller functions can be written inline so that they don’t incur a function call overhead.

Q3’s written in C++?

Well, anyway, what do you mean? If the backend does nothing but drawing triangles, you can simply let it out. The list of triangles should be the same for an object (well, for me it’s not, but that’s another problem) over the game. Is it better to sort after states and then after texture (means, sort for every object, not global)? In any first person shooter, you can optimize the whole world. You can sort and sort and if you’re ready again sort, because the world is one object (or can be considered as one). Now, I’m talking about a space shooter. I will most probably sort after texture for every single object. If the NV20 is good enough, it might also be an option to not texture at all.

After all, my problem is, that I’ve thought about so many graphics effects, that I can’t see let’s say an embryo of them that they share. How to do it with deriving then?

I can also imagine people that derive where it isn’t necessary, just to stay completely in the oop. I don’t want that “I HAVE TO DERIVE A CLASS BECAUSE IT LOOKS LIKE I WOULD BE A GOOD C++ PROGRAMMER!!!” syndrome. Why to make a vector class? There is only one * and multiple vector multiplications, so you still have to stick with normal functions or have to use really weird operators. Why to put a vertex into a class where a simple array could serve as well? I only see overhead in that.

What I can imagine is however, to have these windows-system and global system parts in classes. That could guarantee that the interface to the system parts wouldn’t change so one can easily modify it’s intern functionality without having to look for dependent parts somewhere else in the engine.

Oh, I’m getting crazy.

Well, the big thing is that there’s no cost inherent to putting something into a class, so long as there are no virtuals.

Why make a vector class? Because you can add vectors together and have it look like any other fundamental type. Because it encapsulates the math to a layer that you don’t always have to look at, leaving the higher level logic more clear to read. If you inline those functions, you don’t even incurr the function overhead.

The “I MUST DERIVE” syndrome goes away. You start to recognize patterns that lead to very efficient and effective class structures. The biggest benefit I’ve found is that your code reflects the inherent order in a well-designed OO system. Maintenance and modification are a breeze.

As with everything else, though, YMMV.

Maunikar/Jason

Learning C++ is more than just learning a language, it is moving into a paradigm.

But still, here are the books I really like(for 00 and C++)

the C++ programming language. Bjarne Stroustrup

Effective C++, Meyers

Exceptional C++, Herb Sutter

The C++ standard library a tutorial and reference Nicolai M.Josuttis

Design Patterns. Gamma,Helm,Johnson,Vlissides

A System of Patterns. by a bunch of people.

There is also More Effective C++, but if you read all the other I just said, 90% of the stuff in the book you’ll have already read.

And if you want to modify value by using passing by reference or by using a pointer. Here is my view on it:

With references, the user might not know that value get change.

with pointers, you never now if the pointer is valid,but You have to assert. I only use pointer if I only need to modify one value. If I wanted to modify 2 or more values, then I simply return a pair or make a structure. But again, the objects might be huge, then you can avoid the copy by using pointers.

So both solution have their +/-, if well documented, the reference technique saves you an indirection and you don’t need to assert.

But my rule of thumb is : return new objects unless there is a really important reason to have modified and returned by the parameter.

[This message has been edited by Gorg (edited 01-29-2001).]

Hi!

>Q3’s written in C++?<
Nope but it uses the concept I mentioned…

The backend doesn´t alot more than just drawing triangles.
It does ALL rendering…
You pass a triangle and it´s shader and the backend renders it with multiple passes extures and all state changes just as it is specified in the shader.
However grasping the whole Q3 architecture by some explanation from me is a little difficult, especially without code or if you aren´t really involved\intersted in such a project…
So if you are really interested then look into the source of Titan(a Q3Clone).

Greets, XBTC!

Well, I don’t have abything against looking at some code, but the inet isn’t currently on my comp, so I’ll have to wait some days.
Titan you say? If they’re so good to write a clone, why don’t they just write their own game? I will never understand these cloners…

Forgot to get involved in the “by pointer/by reference” debate: one thing that has not been mentioned is that the pointer can take a convenient value of NULL while the object cannot be a NOOBJECT as in other programming languages…

It happens that some of my functions need a pointer to be passed: if it is not NULL, they use it. If it is NULL, they do something else (usually take a default value)…

Thought I would add this to the discussion !

Best regards.

Eric

Hi!
>Titan you say? If they’re so good to write a clone, why don’t they just write their own game? I will never understand these cloners…<

Yes Titan…Do know why they are so good?
You get good from cloning(Don´t confuse this with the political discussions at the time )!
I have nearly completed my own Q3 clone now and you can´t imagine what I have learned from it…
There is no better learning mehod(for realtime 3d programming) I think as cloning a good engine which already exists and tweaking it until it is nearly as good as the original. And with Q3 you learn real cool stuff like realtime bezier-patch rendering and all that shader stuff…Concepts which can very well be used in every modern engine.
Can you say “I can code a engine with Q3´s feature set and quality”?
After cloning one you can…

Greets, XBTC!

I never saw John Carmack cloning an Unreal though… Well, just kidding. I’m currently very ill (it’s some illness that goes through all the country, nearly everyone who didn’t take care gets it.)

I can’t find Titan. There’s always Titan AE popping out, even if I also search after 3d engine. Could you give me a link, XBCT?

http://talika.fie.us.es/~titan/