Results 1 to 10 of 10

Thread: Generate Texture of window openGL context

  1. #1
    Senior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    150

    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

  2. #2
    Senior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    150

    Re: Generate Texture of window openGL context

    ..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

  3. #3
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Generate Texture of window openGL context

    First, one thing at a time.

    Now, there's another recent thread here explaining how to write to tga:
    http://www.opengl.org/discussion_boa...c;f=2;t=018209

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

  4. #4
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    Re: Generate Texture of window openGL context

    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?

  5. #5
    Senior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    150

    Re: Generate Texture of window openGL context

    Code :
     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, -> 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

  6. #6
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Generate Texture of window openGL context

    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.

  7. #7
    Senior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    150

    Re: Generate Texture of window openGL context

    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

  8. #8
    Senior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    150

    Re: Generate Texture of window openGL context

    it works..i have to use unsigned chars..thanks

  9. #9
    Senior Member OpenGL Pro
    Join Date
    Jul 2001
    Location
    France
    Posts
    1,662

    Re: Generate Texture of window openGL context

    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 changes
    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.

  10. #10
    Senior Member Regular Contributor
    Join Date
    Oct 2004
    Posts
    150

    Re: Generate Texture of window openGL context

    ahhhhh clear... thank you

Similar Threads

  1. Replies: 4
    Last Post: 04-20-2015, 02:31 PM
  2. Creating an OpenGL context on a hidden window
    By imported_JoshKlint in forum OpenGL: macOS
    Replies: 2
    Last Post: 03-20-2011, 12:43 AM
  3. OpenGL Context in a child window
    By imported_Harald in forum OpenGL: Linux
    Replies: 1
    Last Post: 03-05-2005, 06:46 PM
  4. bitblt to window with opengl context
    By blueskyday in forum OpenGL: Windows
    Replies: 3
    Last Post: 06-28-2004, 03:47 PM
  5. Multi-windows and GLUT: different OpenGL context for each window!
    By Mr.Freeze in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 08-17-2001, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean