Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Boops

Textures in video memory

This topic is 5281 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

How can I put all my textures in video memory? Everytime I have to draw something with a different texture, I use:
GLuint texture; //you can only make one of those and it's a sort of dummy right?
glGenTextures( 1, &texture );
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D,0,3,64,64,0,GL_RGB,GL_UNSIGNED_BYTE,image[num]); 
and image[num] is just an array of images in the computer's memory (at least I didn't do anything special to put it in video memory that I know of). image was declared as
BYTE image[1024][64][64][3] 
and filled with images at initialization Are there some of these commands that I can do while initializing instead of every frame? [edited by - Boops on March 6, 2004 6:11:29 AM]

Share this post


Link to post
Share on other sites
Advertisement
You can''t put textures in video memory manually. Everything is automatically handled by the driver. It will upload them into video memory, if it needs them there.

Of course, you have to correctly use texture objects, in order to make it work. You don''t want to specify a texture image every frame. You do that once at startup, and bind the object everytime you want to use it:

startup:

const int maxtex = maximum number of textures;
GLuint *textures = new GLuint[maxtex];
glGenTextures(maxtex, textures );
for( int t = 0; t < maxtex; t++ ) {
glBindTexture(GL_TEXTURE_2D, textures[t]);
glTexImage2D(GL_TEXTURE_2D,0,3,64,64,0,GL_RGB,GL_UNSIGNED_BYTE,image[t]);
}


Every frame:

int tex = the texture you want to use now
glBindTexture(GL_TEXTURE_2D, textures[tex]);
// now you can use it


Don''t forget to clean it up before exiting your program.

Share this post


Link to post
Share on other sites
quote:
Original post by ALX
You can't put textures in video memory manually. Everything is automatically handled by the driver. It will upload them into video memory, if it needs them there.

Of course, you have to correctly use texture objects, in order to make it work. You don't want to specify a texture image every frame. You do that once at startup, and bind the object everytime you want to use it:

startup:

const int maxtex = maximum number of textures;
GLuint *textures = new GLuint[maxtex];
glGenTextures(maxtex, textures );
for( int t = 0; t < maxtex; t++ ) {
glBindTexture(GL_TEXTURE_2D, textures[t]);
glTexImage2D(GL_TEXTURE_2D,0,3,64,64,0,GL_RGB,GL_UNSIGNED_BYTE,image[t]);
}


Every frame:

int tex = the texture you want to use now
glBindTexture(GL_TEXTURE_2D, textures[tex]);
// now you can use it


Don't forget to clean it up before exiting your program.



Not working, it becomes white

It only works if I turn textures into a single variable instead of an array

[edited by - Boops on March 6, 2004 8:24:09 AM]

Share this post


Link to post
Share on other sites
quote:
Original post by Boops
Not working, it becomes white

It only works if I turn textures into a single variable instead of an array


Bug in your code, use your debugger. Or post the relevant parts of your source here.

Also read the OpenGL Redbook, chapter 9, "texture objects".

Share this post


Link to post
Share on other sites
Do you know what it was?

I had to do

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);

for each of the textures too

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!