LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-11-2006, 12:37 PM   #1
pda_h4x0r
Member
 
Registered: Feb 2006
Location: somewhere in cyberspace
Distribution: Debian, Familiar
Posts: 380

Rep: Reputation: 31
OpenGL and memory management


Hello everyone,

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?

For example...

void Init(void) {

//init stuff

glGenTextures(1, &my_texture);

}

void DrawSomething(void) {

glBindTexture(my_texture);

glTexImage2D(GL_TEXTURE_2D, 0, my_data_pix_format, my_width, my_height, 0, my_data_byte_format, my_pixels);

glBegin(GL_QUADS);

//render something

glEnd(GL_QUADS);

}

void Shutdown(void) {

//destory stuff

glDeleteTextures(1, &my_texture);

}

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?

Thank you.
 
Old 08-16-2006, 07:20 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Quote:
Originally Posted by pda_h4x0r
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]

Last edited by dmail; 08-16-2006 at 07:41 AM.
 
Old 08-18-2006, 03:46 AM   #3
pda_h4x0r
Member
 
Registered: Feb 2006
Location: somewhere in cyberspace
Distribution: Debian, Familiar
Posts: 380

Original Poster
Rep: Reputation: 31
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
 
Old 08-18-2006, 08:09 AM   #4
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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.

Last edited by dmail; 08-18-2006 at 08:21 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Memory management Mojojo Linux - Hardware 11 08-31-2003 10:29 AM
memory management exigent Linux - General 1 08-17-2003 08:28 PM
memory management? snow Linux - Software 7 02-12-2003 01:57 PM
Memory Management hhegab Linux - General 3 08-07-2002 10:20 PM
Memory Management mrsolo Linux - General 7 06-26-2002 12:55 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration