recreate shader or reuse shader

I am having trouble deciding if the normal mechanism is the required mechanism.

I am looking at the freetype example on their site. In the example, they only render to the screen once so they create and destroy the shader after the context has been made current. I have the example working, but my question is this.

What parts of the shader creation/destruction process need to be executed every loop execution and what portion can be kept around across multiple render cycles?

The sample program is helpful to show how to generate text in a glx context, but it seems wasteful to recompile and link the shader every time through the loop.

Also, the example loads one character/glyph in a loop and uploads the texture for each character one at a time. Could I upload the entire alphabet once and just reference the correct char/glyph?

I will be generating overlays on one of the output screens every cycle and do not want to waste any time.

I am just ignorant about the scope of the functions being executed. I will include the source for the program so it can be discussed.

Once created, the compiled shader can be retained for the lifetime of the program.

Yes.

OK, before I answer your specific questions, let me say this.

That example code you found? Never do anything it does. Wipe the entire thing from your mind. If you’re interested in doing text rendering with FreeType and OpenGL, look elsewhere.

In fact, as a general rule, if the code you’re looking at does a glTexImage call that is immediately followed by some form of rendering command (like glDrawArrays), abandon that tutorial and go elsewhere. There is nothing that you could learn there which you couldn’t learn somewhere else.

Yes, the tutorial immediately after the one you found (assuming that was what you were talking about) tells you the right way to handle it, but it’s generally not a good idea to introduce the wrong way first.

If you’re talking about what is done in “init_resources”, none of that should be done per-frame.

Not only could you do what you suggest, it is the proper way to handle it. The example code is doing things in pretty much the worst possible way, which again is why you should look elsewhere. You are smarter than the tutorial you read, which says nothing good about the quality of the tutorial you’re using, since you’re still a beginner.

On the plus side, it proves you have good instincts :wink:

Thank guys. I appreciate the quick responses. I will go and read the second tutorial and use it. :angel: