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.
#include <assert.h>
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <sys/timeb.h>
#include <GL/glut.h>
#include <GL/gl.h>
char fn[32];
int i,j;
FILE* sav;
unsigned char *buffer;
long lSize;
int wrt;
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos3f(0.0,0.0,-20.0);
glDrawPixels(640, 480, GL_RGB, GL_UNSIGNED_BYTE, buffer);
glFlush();
free(buffer);
}
void init(){
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
", lSize);
buffer = (unsigned char*) malloc (921600);
wrt=fread(buffer,1,921600,sav);
}
void
reshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0, w, h, 0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize(640, 480);
glutCreateWindow(“Testing”);
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
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.