Sign in to follow this  
zerolimited

glDeleteTexture

Recommended Posts

Hi! I've created two textures, which overwrite themselves every two seconds. Now I have to delete the textures every loop to clear the memory: UINT TextureArray1[1]; UINT TextureArray2[1]; ... JPEG_Texture(TextureArray1, "data/texture/Bild1.jpg", 0); JPEG_Texture(TextureArray2, "data/texture/Bild2.jpg", 0); ... glDeleteTextures(1, TextureArray1); glDeleteTextures(1, TextureArray2); But it didnt't work with these lines. Can anyone tell me my failure? Thx, Dave

Share this post


Link to post
Share on other sites
First of all you need to at least provide what errors you get, and if you don't mind a little more code too work with, like for instance how are you setting up the texture. Trying to find the error you made with what you gave is like trying to answear why i am wearing grey socks today...

Secondly, you say that you overwrite the textures every loop, and from what it looks like you create textures from an image file...every loop. This should be rather slow if you are reading the image and storing the texture every loop. Perhaps one idea to speed it up a bit would be to first read your texture into a buffer, and then dump the buffer into an empty texture every loop.

Share this post


Link to post
Share on other sites
Sorry, I thought the failure is easy to see.
How can I dump the buffer in an empty texture?
Here is the DrawGLScene-function I created:

int DrawGLScene(GLvoid)
{
static int colorstatus = 1;

glShadeModel(GL_SMOOTH);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_TEXTURE_2D);

JPEG_Texture(TextureArray1, "C:/MDRS/Bilderorig/StereokameraL/stereoL.jpg", 0);
JPEG_Texture(TextureArray2, "C:/MDRS/Bilderorig/StereokameraR/stereoR.jpg", 0);

if(keys['1'])
{
colorstatus=1;
}

if(keys['2'])
{
colorstatus=2;
}

if(colorstatus==1)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE);
}
else
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glColorMask(GL_FALSE, GL_TRUE, GL_FALSE, GL_FALSE);
}

glLoadIdentity();
glTranslatef(0,0,-5.5f);
glBindTexture(GL_TEXTURE_2D, TextureArray1[0]);
glScalef(1.0f, -1.0f, 1.0f);

glBegin(GL_QUADS);

glTexCoord2f(0.0f, 1.0f);
glVertex3f(-2, 2, 0);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-2, -2, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(2, -2, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(2, 2, 0);

glEnd();

glDisable(GL_DEPTH_TEST);

glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);

glBindTexture(GL_TEXTURE_2D, TextureArray2[0]);

glBegin(GL_QUADS);

glTexCoord2f(0.0f, 1.0f);
glVertex3f(-2, 2, 0);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-2, -2, 0);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(2, -2, 0);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(2, 2, 0);

glEnd();

JSAMPLE * image_buffer=new JSAMPLE[582*500*3];

glPixelStorei(GL_PACK_ALIGNMENT,1);
glReadPixels(0,0,582,500,GL_RGB,GL_UNSIGNED_BYTE,image_buffer);

write_JPEG_file ("C:/MDRS/Bilderorig/image3D/image3D.jpg",100,image_buffer,582,500);
delete image_buffer;

glDeleteTextures(1, TextureArray1);
glDeleteTextures(1, TextureArray2);

Sleep(2000);
return TRUE;
}


Thx, Dave

Share this post


Link to post
Share on other sites
Hmm, it would help if you could provide the error messages you get also. Learning how to read and understand those messages is essential to debugging and programming.

I'm having a little problem with understanding exactly what your program is meant to do, but if i'm correct you're trying to make it take two images and create one of those pictures...that you stare long enough at and it's looking like it's coming out of the paper, am i correct? (if so, cool stuff [grin])
What i meant with speeding it up shouldn't really be necessary in your case, because you just want to redner the image once. However if your planning to do this in realtime (lol, this would be awesome!) you really don't want to save an image to disc and then read/create a texture of it every loop.

Just to explain the theory. Consider this part-pseudo-code:

uint tex; // texture handle

void CreateZeroTexture(int &tex, int size)
{
// create an empty buffer
// remember size must be power-of-2, and base*height*number-of-channels(rgb = 3, rgba = 4)
UCHAR *buf = new UCHAR[size];
ZeroMemory(buf, size); // use memset if you like ;)

glGenTextures(1, &tex); // generate texture
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, tex);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, size, size, 0, GL_RGB, GL_UNSIGNED_BYTE, buf);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glBindTexture(GL_TEXTURE_2D, NULL); // sucky way of unbinding, but work

delete [] buf; // remove the temp data, we're done with it...
}

// there, you have a zeroed texture, it's just black...
// now render your scene, you might want to adjust the viewPort
// to your texture size to get better results.
// When you have drawn the scene you are ready to make a texture of it,
// and store it in your empty texture...

void RenderToTexture(UINT &tex, int size)
{
// bind the texture
glBindTexture(GL_TEXTURE_2D, tex);

// this handy function reads all GFX from the screen, and dump it into our texture
// be careful to set the same size as you did with the zero texture
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, size, size, 0);

// unbind
glBindTexture(GL_TEXTURE_2D, NULL);
}




When you want to look at the texture you just create a quad and use that zero texture on it. You shouldn't have to wipe the texture or reset it, glCopyTexImage2D() will simply overwrite the texture data stored in the zero texture with the new data from your scene.

This is one way of making this. There's many more methods, way more optimised...but this might give you an understanding of what i meant with how you can dump the scene into a temporary texture [smile]



Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this