Hi, currently I’m trying to use GLUT and glDrawPixels to draw out an image captured from my webcam. The image I saved it as my own format at 640x480x24bit color in a format like RGBRGBRGB… up to 921600 elements and each element is 1 byte of unsigned char ( ie 8-bit level of that component )
My program is like trying to read in a frame of 640x480 from the file and display it in a window using OpenGL thru GLUT. Below is a short code of my method, but it only display a black screen window. I’m using MS VC++ 6.0 to compile. May I know what goes wrong here? I can verify that my image data is correct cuz I can read in the same file and write it out as a bmp file, which displays alrite.
unsigned char *buffer;
glDrawPixels(640, 480, GL_RGB, GL_UNSIGNED_BYTE, buffer);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); glShadeModel(GL_SMOOTH); sav = fopen ("RGB.raw","rb"); fseek (sav , 0 , SEEK_END); lSize = ftell (sav); rewind (sav); printf("Total size of file is %d bytes
buffer = (unsigned char*) malloc (921600); wrt=fread(buffer,1,921600,sav);
reshape(int w, int h)
glViewport(0, 0, w, h);
gluOrtho2D(0, w, h, 0);
int main(int argc, char **argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
BTW, I will be eventually trying to read in a big file of many frames of RGB data, and displaying it like a video stream, ala a WMP using opengl. Later I will extend it to displaying it realtime on the live capture from my webcam. So I need to get this right on this simple code of reading in only one frame and displaying it. ( which I couldn’t =p from the above code)
Thanks for ur help.