Generate Texture of window openGL context

i would need to generate for a mirror on a vehicle. i found some examples but the are blown up and i can’t find the essential parts for this! do you know good tuts for generating textures of a “viewport”?

thanks H.Stony

…and how do i write the ogl context into a bitmap file?

GLubyte *pixels;
glReadPixels(0,0,8,8,GL_RGB,GL_BITMAP,pixels);
-> is this the right idea? how do i write it down?
fwrite(pixels,sizeof(pixels),1,outputfile);
–> doesn’t work :frowning:

thanks h.stony

First, one thing at a time.

Now, there’s another recent thread here explaining how to write to tga:
http://www.opengl.org/discussion_boards/cgi_directory/ultimatebb.cgi?ubb=get_topic;f=2;t=018209

Normally you effectivly need to map a texture for making what you want.

I tried to use that fuction to write to a tga file but when I try to compile I end with three errors

here are the errors. when go to the errors they all point to the first line

syntax error : missing ‘)’ before ‘constant’
syntax error : missing ‘;’ before ‘constant’
syntax error : missing ‘;’ before ‘constant’

am I missing a header file or did the post have a mistake I am not seeing?

 void ScreenToTGA(int W, int H) {
 FILE           *out = fopen("screenshot.tga", "w");
 short              TGAhead[] = {0, 2, 0, 0, 0, 0, W, H, 24};
 char          pixel_data[3*W*H];

 fwrite(&TGAhead, sizeof(TGAhead), 1, out);
 glReadBuffer(GL_FRONT);
 glReadPixels(0, 0, W, H, GL_BGR, GL_UNSIGNED_BYTE, pixel_data);
 fwrite(pixel_data, 3*W*H, 1, out);
 fclose(out); }

a glGetError returns 0 -> opengl part should be ok
ScreenToTGA(8,8) -> no error but a corrupt tga file
ScreenToTGA(800,600) -> size of the window but a program crasch
ScreenToTGA(799,599) -> also crasch

? i don’t understand this…my app is using double buffering - is this a problem?

sorry… thanks

This code works very fine with me. I just replaced W and H with my window width and height respectively. Put attention that you have integers as the function arguments and that this is short that is used inside the tga headers. I think that might be your problem.

Terminatore3, be really careful of what you’re writting. And you effectively might miss stdio.h.

H.Stony, the created tga file is not corrupted on my machine.

For other steps for what you wanted, I cannot help you more.

mode is initially GL_FRONT in single-buffered configurations, and GL_BACK in double-buffered configurations.

in double buffermode i have to change to glReadBuffer(GL_BACK);

any other changes

it works…i have to use unsigned chars…thanks

Originally posted by H.Stony:
[b]mode is initially GL_FRONT in single-buffered configurations, and GL_BACK in double-buffered configurations.

in double buffermode i have to change to glReadBuffer(GL_BACK);

any other changes[/b]
I use double buffer. It depends on when you call it. If the buffer is empty, you won’t get anything at all, of course.

ahhhhh clear… thank you