PDA

View Full Version : Generate Texture of window openGL context



H.Stony
03-26-2005, 04:35 AM
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

H.Stony
03-26-2005, 05:21 AM
..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 :-(

thanks h.stony

jide
03-26-2005, 07:22 AM
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.

t3jem
03-26-2005, 06:44 PM
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?

H.Stony
03-27-2005, 03:28 AM
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

jide
03-27-2005, 03:36 AM
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.

H.Stony
03-27-2005, 03:48 AM
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

H.Stony
03-27-2005, 04:37 AM
it works..i have to use unsigned chars..thanks

jide
03-27-2005, 06:32 AM
Originally posted by H.Stony:
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 changesI use double buffer. It depends on when you call it. If the buffer is empty, you won't get anything at all, of course.

H.Stony
03-27-2005, 07:12 AM
ahhhhh clear... thank you