PDA

View Full Version : Does opengl support templating?



09-29-2003, 09:47 AM
Hi,
I was just wondering if opengl supports the use of templating, because I have a algorithm that I don't want to call up in real time, I would much rather call it in the actual program when I need it. By the way maybe I shuold mention that the algorithm is a hair model for a game that I am writing http://www.opengl.org/discussion_boards/ubb/smile.gif
Thanks

09-29-2003, 11:28 AM
I'm guessing that you use Visual C++? If you are, any templates you want to use must be INCLUDED in a header file. If you put them into your cpp file, the program will not run. I hope this answers your question.

starman
09-30-2003, 04:20 AM
"because I have a algorithm that I don't want to call up in real time, I would much rather call it in the actual program when I need it. "

Isn't that the same thing? Anyway, if you're talking about C++ templates, they have nothing to do with OpenGL. Templates are supported at some level by most (all?) modern C++ compilers, but as the first reply stated, you may have to completely define your template classes/functions in the header file.

[This message has been edited by starman (edited 09-30-2003).]

09-30-2003, 04:45 AM
I mean, like could you call the template in the normal program code before the game even starts, then use it in the game while it is running?

09-30-2003, 08:27 AM
Originally posted by neo88:
I mean, like could you call the template in the normal program code before the game even starts, then use it in the game while it is running?

OGL cannot tell the difference between a call from within a template or a call from function or method. OpenGL knows nothing about C++ templates, therefore it cannot constrain the use of templates in your program from a C++ perspective. However, if you make OGL calls in your template then all the rules for OGL calls apply to your templates. For instance, you still cannot make calls to certain functions between glBegin() and glEnd() calls. You must also make sure you have a gl context of some kind to make the gl calls in your template.

I hope I'm making sense here. Have any of these replies answered your question?

Honk
09-30-2003, 01:03 PM
Are you really sure you understood the concept of C++ templates?

They arent *called* they generate classes.

If you place OpenGL calls into an template, make sure you have an valid rendering context before you create an instance of a template class.

Jan
09-30-2003, 01:31 PM
You should really learn C++, templates have nothing to do with OpenGL and they can only in very rare cases be used to speed up a mathematical calculation, but only if the result of the calculation can be calculated at compile-time (so you could precalculate it by yourself, but since you are foul, you let the compiler do it for you).

However, i think you should take a look into display lists (for example at http://nehe.gamedev.net ), i think you mean something like that.

Jan.