Results 1 to 2 of 2

Thread: png Programme

  1. #1
    Senior Member Regular Contributor
    Join Date
    Apr 2009
    Posts
    171

    png Programme

    i am working on OpenGL programme
    to load a PNG image on square plate

    1st:i worked on console programme to test a png image of validity by signature test be png file which passed

    2nd:this will more good then 1st it not only test but also give information about image file like

    Dimension:
    bit-depth:
    compression value:
    color type RGB/RGBA:

    3rd:it is final one but here i got message
    ./pngtest xxxx segmentation fault
    and i give code and part which pressence affect programme

    The code to load png:
    Code :
    str = png_create_read_struct(PNG_LIBPNG_VER_STRING,NULL,NULL,NULL);
    if(!pstr)
    {printf("can't create read struct");
    exit(0);
    }
    pinfo = png_create_info_struct(pstr);
    if(!pinfo)
    {png_destroy_read_struct(&pstr,&pinfo,NULL);
    printf("info struct creation failed");
    exit(0);
    }
    if(setjmp(pstr->jmpbuf))
    {printf("Something goes wrong\n");
    png_destroy_read_struct(&pstr,&pinfo,NULL);
    exit(0);
    }
    png_init_io(pstr,fp);
    png_set_sig_bytes(pstr, 8);
        png_read_info(pstr, pinfo);
    printf("image dimension %i x %i\n",pinfo->width,pinfo->height);
    if(pinfo->color_type = 2){flag = GL_RGB;
    }
    else if(pinfo->color_type = 4){flag = GL_RGBA;
    }
    else {
    exit(0);
    }
    data = (unsigned char *)malloc(pinfo->rowbytes*pinfo->height);
    png_destroy_read_struct(&pstr,&pinfo,NULL);
    exit(0);
    }
     
    for(int i = 0;i < pstr->height;++i)
    pinfo->row_pointers[i] = data + i*pinfo->rowbytes;
    png_read_image(pstr,pinfo->row_pointers);
    png_read_end(pstr,NULL);
    and code fraction presence which affect:
    for(int i = 0;i < pstr->height;++i)
    pinfo->row_pointers[i] = data + i*pinfo->rowbytes;
    png_read_image(pstr,pinfo->row_pointers);
    png_read_end(pstr,NULL);
    if code fraction note there then whole programme work but object not wrapped up

    if it present then that of sagmentation fault
    comes on output window

    lil pocced of pro:
    open file
    signature check
    read struct job
    info struct job
    png file io job
    signature setting job
    initialising unsigned char * data via file's
    component
    and placing data at end corner
    of
    gluBuild2DMipmaps()
    haven't made a game [img]<<GRAEMLIN_URL>>/frown.gif[/img]

  2. #2
    Junior Member Newbie
    Join Date
    Aug 2008
    Location
    Hungary
    Posts
    8

    Re: png Programme

    It's easier to use a library for texture loading.
    e.g.
    SOIL: http://www.lonesock.net/soil.html
    DevIL: http://openil.sourceforge.net/
    etc..

Similar Threads

  1. shader programme does not link
    By _Julian_ in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-03-2015, 05:47 AM
  2. How to make tray programme?
    By piggyyang in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 06-18-2010, 04:11 AM
  3. Replies: 2
    Last Post: 10-14-2004, 10:48 PM
  4. Run a OpenGL programme in VC++ .NET
    By Rain in forum OpenGL: Windows
    Replies: 2
    Last Post: 03-17-2004, 05:26 PM
  5. How to Add a Compass in My Programme
    By zjkw in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 05-21-2002, 09:08 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