Hello,
I have a C program (using OpenGL) that compiles and runs quite well with gcc. Now, to expand it I need to use a library that's written in C++, of which I know nothing.
I tried simply compiling my code with g++, to see if I could "fake" the C++, i.e. not change my existing code and simply use it when I need to call this new library.
I got only one error. If I comment out the function where the error is, everything seems to compile and run quite well. The thing is I do not understand the error, so I hope someone could give me a hint.
First and foremost, do you guys see any risk in doing what I intend to do?
Second, I put g++ instead of gcc in my Makefile, and changed my code to *.cpp. When I make it, I get this error:
visuals.c:465: error: invalid conversion from 'void*' to 'unsigned char*'
The code with the error is below. The line 465 of the error is
Code:
pixels = malloc(3*width*height);
Function with the error
Code:
int capture_to_ppm(void)
{
int width, height, colorDepth, maxColorValue,y;
unsigned char *pixels;
int fd;
char sbuf[256]; /* for sprintf() */
/* open output file: you can name it as you like */
fd = open(picfile,O_CREAT|O_TRUNC|O_WRONLY,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH);
if(fd == -1) return -1;
/* width & height of the window */
width = glutGet(GLUT_WINDOW_WIDTH);
height = glutGet(GLUT_WINDOW_HEIGHT);
/* maxColorValue is 255 in most cases... */
colorDepth = glutGet(GLUT_WINDOW_RED_SIZE);
maxColorValue = (1 << colorDepth) - 1;
/* allocate pixels[]: 3 is for RGB */
pixels = malloc(3*width*height);
if( !pixels ) return -2;
/* get RGB values from the frame buffer into pixels[] */
glReadBuffer(GL_FRONT); /* if you are using "double buffer" */
glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,pixels);
/* write ppm file header */
sprintf(sbuf,"P6 %d %d %d\n",width,height,maxColorValue);
write(fd,sbuf,strlen(sbuf));
/* write ppm RGB data: we must invert upside down */
for(y = height-1; y >= 0; --y) {
write(fd, pixels+3*width*y, 3*width);
}
close(fd);
free(pixels);
return 0;
}
Thank you very much for any help,
mc61