Results 1 to 4 of 4

Thread: about render 32bit alpha tga format image!

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2005
    Location
    guangdong shaoguang china
    Posts
    4

    about render 32bit alpha tga format image!

    hi all!
    I write opengl demo, save tga images, my demo save is 24bit no alpha tga images, i want to my demo render 32bit alpha tga images, who can help me,how!
    thanks!

    environment: ms vc + mfc + opengl

    my demo a part source:
    //////////////////////////////////

    void CMainFrame::OnRendTga()
    {
    int nFrames=100; /*帧数*/
    GLubyte *FBuffer = NULL; /* Memory for the framebuffer */
    static GLubyte magic[12]= {0,0,2,0,0,0,0,0,0,0,0,0}; /* Targa header */
    GLubyte info[6]; /* Width and Height Targa header info */
    int WinW, WinH; /* Width and Height of the current window */
    FILE *Outfile; /* The file to be written to disk */
    char FileName[13]; /* Name of file: SCR#####.TGA */
    static int FileNum = 1; /* Number to fill in ##### in FileName above */

    #if (!defined(GL_BGR)) /* For compatibility with both NT and Suns */
    #define GL_BGR 0x80E0
    #endif
    GLView_Left_Up* pView=(GLView_Left_Up *)GetActiveView();
    int cx=0, cy=0;
    CRect rect;
    pView->GetClientRect(&rect);
    CSize size(rect.Width(), rect.Height());
    cx=(size.cx/2)*2;
    cy=(size.cy/2)*2;
    ////////////////////////////////////////////////
    // glReadBuffer(GL_FRONT); /* Be sure to read from the displayed window */
    glPixelStorei(GL_PACK_ALIGNMENT,1);
    WinW =cx; // glutGet((GLenum)GLUT_WINDOW_WIDTH); /* Get dimensions of window */
    WinH =cy; //glutGet((GLenum)GLUT_WINDOW_HEIGHT);
    /* Allocate space for the current window's framebuffer */
    if ((FBuffer = (GLubyte *)malloc(WinW * WinH * 3)) != NULL)
    {
    glReadBuffer(GL_BACK); //读背景缓冲
    for(int i=0;i<nFrames;i++)
    {
    pView->DrawGL();
    /* Set the name for the file and open it for writing*/
    sprintf(FileName,"SCR%05d.TGA",FileNum++);
    if ((Outfile = fopen(FileName,"wb")) == NULL)
    {
    fprintf(stderr,"Can't save to the file %s!\n",FileName);
    fflush(stderr); /* Make sure output shows up */
    }
    else
    {
    /* Read the image data from the framebuffer */
    glReadPixels(0,0,WinW,WinH,(GLenum)GL_RGB,GL_UNSIG NED_BYTE,FBuffer);

    /* Write the new BGR framebuffer data to the Targa file */
    fwrite(magic,1,sizeof(magic),Outfile); /* Header */
    info[0] = (GLubyte)(WinW % 256);
    info[1] = (GLubyte)(WinW / 256);
    info[2] = (GLubyte)(WinH % 256);
    info[3] = (GLubyte)(WinH / 256);
    info[4] = 24;
    info[5] = 0;
    fwrite(info,1,sizeof(info),Outfile); /* Width/Height header */
    fwrite(FBuffer,1,WinW*WinH*3,Outfile); /* Data */
    fclose(Outfile);
    }
    } //end nFrames

    free(FBuffer);
    }

    ////////////////end
    E-MAIL:ying7970@hotmail.com

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2005
    Posts
    145

    Re: about render 32bit alpha tga format image!

    http://www.wotsit.org/search.asp?page=9&s=graphics

    You can find TGA file format stuff with a quick search.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2005
    Location
    Pasadena, CA
    Posts
    6

    Re: about render 32bit alpha tga format image!

    Make sure you're reading and writing 32-bit data. GL_RGB will only give you 24 bits -- try GL_RGBA with glReadPixels() to get the alpha values. Then you'll have to play around with pixel formats to determine if you need to use ABGR or BGRA for writing your image.

  4. #4
    Junior Member Newbie
    Join Date
    Jun 2005
    Location
    guangdong shaoguang china
    Posts
    4

    Re: about render 32bit alpha tga format image!

    thanks two guy!

    I try modification under source succeed save 32bit alpha tga images. ~_~

    ////////////////////
    SetupPixelFormat()
    32 //Select Our Color Depth
    1 //No Alpha Buffer
    32 //Depth Buffe

    // Allocate space for the current window's framebuffer
    FBuffer = (GLubyte *)malloc(4*weidth*height);

    FBuffer = (GLubyte *)malloc(4*weidth*height);
    // Read the image data from the framebuffer
    glReadPixels(0,0,weidth,height,(GLenum)GL_RGBA,GL_ UNSIGNED_BYTE,FBuffer);

    fwrite(FBuffer,1,weidth*height*4,Outfile); // Data

Similar Threads

  1. Replies: 4
    Last Post: 08-24-2013, 08:42 AM
  2. Whats the best 32bit image format file?
    By blessman11 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-08-2011, 11:25 AM
  3. Own Image Format
    By H.Stony in forum OpenGL: Advanced Coding
    Replies: 12
    Last Post: 04-18-2005, 11:25 AM
  4. PNG image format
    By JanHH in forum OpenGL: Linux
    Replies: 3
    Last Post: 04-13-2003, 05:36 PM
  5. How to convert GL_RGB pixel data format (image) to GL_RGBA format
    By Coloro.cl in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 02-13-2002, 06:01 AM

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