help on glTexSubImage2d(), urgent!1

Can you help to tell me how to let glTexSubImage2d() work, I have tried by having the .bmp file texture mapped on the screen, but when I use glTexSubImage2d() to
get the video image from the camera to update the display, there is no change, how to do it?

Oh good thing someone also has this problem! I was just about to post the very same question

Ummm…so…any ideas?

Hi folks,
if I understand your question correctly you have a live video stream from a video camera and want to use that as a texture.
The data from the video camera has to be converted into a format suitable for texture download (e.g. from YUV to RGB).
I’m not familiar with video capture drivers and multimedia functions under Windows, but as long as the video is just shown in a video overlay plane on the monitor you probably won’t get the data. It’s encoded in some offscreen buffer known to the display driver only, and in a typical video format like YUV.
So if you have a piece of code which constantly decodes the video into an RGB format for you, you could feed it into the texture.
With AVI files this is rather easy. There is a Windows Multimedia API function to read a DIB-Bitmap from an AVI file, but I have to look up the name at this moment
If you find a function which gives you access to the live video stream, please post it

Yes, I think I do have changed to RGBA format,the problem is the glError code give me GL_INVALID_OPERATION , I thinks it may because of the texture array was not defined by the previous glTexImage2D operation, do you know what this sentence mean exactly about the texture array?

THanks for your comments

Oh I made a library that reads an AVI file. It gives you the ability to extract a certain frame’s buffer.Now,after I have a pointer to the buffer,what next? I initialy created texture objects in OpenGL for EACH frame and (needless to say) this took up WAY too much memory.My system crashes after I’ve loaded 74 frames into memory.I was told to use glTexSubImage2D.It’s not working for me.I truly believe that it’s because I’m using the function wrong.So if any one could post some source code (that loads say 2 or 3 BMP’s and play them as textures on a polygon) that would be great.Just to show us how exactly the function is used.My book (the OpenGL Super Bible doesn’t say much about this function )

You may want to have a look at my CGLTexture class. It can be used only for very simple texture mapping, but is designed to ‘always work’ . http://shiptech.tuniv.szczecin.pl/~weyna/OpenGL/

Hi,Relic:
Can you help to tell me the name of the application that can read a DIB-Bitmap from an AVI , I would like try the easier one first.

Thanks

Originally posted by TheGecko:
So if any one could post some source code (that loads say 2 or 3 BMP’s and play them as textures on a polygon) that would be great.Just to show us how exactly the function is used.My book (the OpenGL Super Bible doesn’t say much about this function )

I suggest you get your self the RedBook… OpenGL Porgrammers Guide (Third Edition) ISBN 0-201-60458-2.

ok hope this source helps you some

// draw a standard texture polygon
glBindTexture(GL_TEXTURE_2D, texTextels);
drawPolygon(…)


// draw a textured polygon with sub image
glBindTexture(GL_TEXTURE_2D, texTexels);
glTexSubImage2D(GL_TEXTURE_2D, subImageLevel, subImageOffsetX, subImageOffsetY, subImageWidth, subImageHeight, GL_RGBA, GL_UNSIGNED_BYTE, subImageTexels);
drawPolygons();

here is the function definition

void glTexSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width, GLsizei height, GLenum format, GLenum type, const GLvoid *texels);

target - must be GL_TEXTURE_2D
level, format and type - are similar to those used in gltexImage2D()
width and height - are the dimensions of the subregion that is replacing all or part of the texture.
xoffset and yoffset - are the texel offset in the x and y directions (0,0) is the lower left corner of the original texture.

Its pretty simple really. Just imagine your placing a small sticker (the subImage) on a larger poster (background texture). Or you can replace the whole texture with a much larger sticker.

Hope this helps

/originally posted by Dans/
target - must be GL_TEXTURE_2D
level, format and type - are similar to those used in gltexImage2D()
width and height - are the dimensions of the subregion that is replacing all or part of the texture.
xoffset and yoffset - are the texel offset in the x and y directions (0,0) is the lower left corner of the original texture.

ask a stupid Q:
it is possible thate the parameters of glTexSubImage2D is different from glTexImag2D(), e.g. gl_RGBA in glTexSubImage2D () but
gl_RGA in glTexImag2D()?

Thanks

WOOOHOOOO!!! It works! Finally! I am unstopable! MUWAHAHAH!!!

Dans,you’re a genius! Thanx for that little bit of source code.No wonder my app wasn’t working! I got it all sorted out and it works like a charm! Thanx all!

Originally posted by ming:
is it is possible that the parameters of glTexSubImage2D is different from glTexImage2D(), e.g. gl_RGBA in glTexSubImage2D () but
gl_RGB in glTexImage2D()?
Thanks


I edited the quote - you originally had gl_RGA as a parameter to glTexImage2D() Im making the following comments based on that assumption.

Redbook says they are similar but i didnt find information on the diferences.

If you want that to work with RGB only change to

glTexSubImage2D(GL_TEXTURE_2D, subImageLevel, subImageOffsetX, subImageOffsetY, subImageWidth, subImageHeight, GL_RGB, GL_UNSIGNED_BYTE, subImageTexels);

Im not quite sure i interpereted your question correctly.

hope this helps somehow :slight_smile:

Originally posted by ming:
[b]Hi,Relic:
Can you help to tell me the name of the application that can read a DIB-Bitmap from an AVI , I would like try the easier one first.

Thanks

[/b]

Here is a code snippet with the necessary functions from one of my colleagues. This has been ripped from a larger routine, so no guarantee that this compiles.
Hope that helps to get the data into the textures Watch out for the GL_BGR_EXT.

PAVIFILE aviFile;
AVIFILEINFO aviInfo;
PAVISTREAM aviStream;
PGETFRAME aviFrame;
char * pBits;

AVIFileInit();
AVIFileOpen( &aviFile, lpszFileName, OF_SHARE_DENY_WRITE, NULL );
AVIFileInfo( aviFile, &aviInfo, sizeof( aviInfo ) );
AVIFileGetStream( aviFile, &aviStream, streamtypeVIDEO, 0 );
aviFrame = AVIStreamGetFrameOpen( aviStream, NULL );
for ( int index = 0 ; index < aviInfo.dwLength; index++ )
{
pBits = (char *) AVIStreamGetFrame( aviFrame, index ) + sizeof( BITMAPINFOHEADER );
// Removed some matrix and rasterpos things here…
glDrawPixels( aviInfo.dwWidth, aviInfo.dwHeight, GL_BGR_EXT, GL_UNSIGNED_BYTE, pBits );
}
AVIStreamGetFrameClose( aviFrame );
AVIStreamRelease( aviStream );
AVIFileRelease( aviFile );
AVIExit();