ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a few questions about OpenGL that I could not find (direct) answers to with Google regarding memory allocation.
First, from what I've read, the function glTexImage2D() seems to be the function that allocates VRAM for textures. Is this correct?
Second, do I need to free this memory manually, or does OpenGL automatically do this? If I need to free it manually, which function(s) do I use?
Third, will glTexImage2D() allow me to alter a texture image that already exists in VRAM (providing I bind the appropriate texture and use the same dimensions)? Or do I need to first delete the texture and create a new one before attempting this?
If DrawSomething() were to be called multiple times (i.e. every frame), and if the only thing that were to change would be my_pixels, would there be a memory leak?
Hello everyone,
First, from what I've read, the function glTexImage2D() seems to be the function that allocates VRAM for textures. Is this correct?
Yes.
Quote:
Second, do I need to free this memory manually, or does OpenGL automatically do this? If I need to free it manually, which function(s) do I use?
No you do not need to free the memory.
Quote:
Third, will glTexImage2D() allow me to alter a texture image that already exists in VRAM (providing I bind the appropriate texture and use the same dimensions)? Or do I need to first delete the texture and create a new one before attempting this?
Why you would want to do this? Creating a texture every frame is really slow, its far better to create textures in the load up phase and just bind the correct one, or ones to create an effect.
[edit]if you really wanted to do this there are better ways[/edit]
I need to dynamically draw strings using OpenGL. The problem is that the string contents are arbitrary--I can't pre-render them
Fortunately, I only need to regenerate the texture every 50-ish frames. You see, I'm developing a game, and was confronted with the need to render HUD elements that included potentially arbitrary strings.
Thank you for your responses!
PS Could you direct me to the "better ways" you mentioned? Thanks
For the drawing of text you may want to look at nehe's lesson 13 (one of the linux ports at the bottom). Basically You load in a font and place the letters into a display list(which are quick) and draw from there.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.