Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: file type

  1. #1
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    file type

    Hello,
    Is there a file format, that packs the data exactly the same as the buffer pixels, from glReadPixels() ?
    Because I want to make a screenshot and then stream the data to my file, without first compressing and indexing the data.
    Thanx Hylke

  2. #2
    Senior Member Regular Contributor
    Join Date
    Aug 2003
    Posts
    369

    Re: file type

    Well, you could try a bitmap. You only need a header. Google about it. I don't know if the .raw format would fit your description as well.

  3. #3
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: file type

    They both require an header.
    I want one that doesn't require an header.

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

    Re: file type

    Plain non-compressed SGI's RGB file format is what you might want. Take a look at Mesa's demo, they generally got one. If not, just tell me so that I can send you the source. But they use some headers.

    Otherwise, really simple, there's the TGA format. They use (very few) headers but they are really simple. Recent posts (about few months) talked about that.

    From what I know, there's no file format that do not have headers. Depending on what you'd like to do, you might simply put on a file what glReadPixels retrieved.

  5. #5
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: file type

    I have this code:
    Code :
    	GLint viewport[4];
    	unsigned char *pixels;
    	glGetIntegerv(GL_VIEWPORT, viewport);
    	pixels = new unsigned char [viewport[2]*viewport[3]*3];
    	glReadPixels(viewport[0], viewport[1], viewport[2], viewport[3], GL_RGB, GL_UNSIGNED_BYTE, pixels);
    	ofstream screenshot("Screenshot.tga", ios_base::binary | ios_base::out | ios_base::trunc);
     
    	//header
    	screenshot << 0; //There's no string after the header
    	screenshot << 0; //Color Map Type.
    	for(int i = 0;i < 5;i++) //this is all for index ****, we don't use an indext image
    		screenshot << 0;
    	screenshot << 2; // Uncompressed RGB
    	screenshot << 0; screenshot << 0; // x origin, pick from the first x pixel
    	screenshot << 0; screenshot << 0; //y origin, pick from the first y pixel
    	screenshot << (viewport[3]  & 0x00FF); //width
    	screenshot << (viewport[3]  & 0x00FF) / 256; //width
    	screenshot << (viewport[4]  & 0x00FF); //height
    	screenshot << (viewport[4]  & 0x00FF) / 256; //width
    	screenshot << 24; //24 bit image, we don't use the alpha value
    	screenshot << 0; //this byte is freeform.
    	//end of header
    	screenshot << *pixels;
    	delete [] pixels;
    	screenshot.close();
    But it doesn't seem to work.
    Could you help me in the right directrion to fix it?
    Thanx in advance,
    Hylke

  6. #6
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: file type

    try this:

    Code :
    void Screendump(char *tga_file, short W, short H) {
     FILE   *out = fopen(tga_file, "w");
     char   pixel_data[3*W*H];
     short  TGAhead[] = {0, 2, 0, 0, 0, 0, W, H, 24};
     
     glReadBuffer(GL_FRONT);
     glReadPixels(0, 0, W, H, GL_BGR, GL_UNSIGNED_BYTE, pixel_data);
     fwrite(&amp;TGAhead, sizeof(TGAhead), 1, out);
     fwrite(pixel_data, 3*W*H, 1, out);
     fclose(out); }

  7. #7
    Senior Member Regular Contributor
    Join Date
    May 2004
    Location
    Renkum
    Posts
    193

    Re: file type

    that code is giving a segmentation fault.

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

    Re: file type

    The code of RigidBody is not responsible of the segmentation fault. Check your code.

    For RGB files, here is how I do that:

    </font><blockquote><font size="1" face="Verdana, Arial">code:</font><hr /><pre style="font-size-small; font-family: monospace;">// rgb.h
    #include <cstdlib>
    #include <cstdio>
    #include <string>
    #include <GL/gl.h>
    #include <GL/glu.h>

    using namespace std;

    class RgbImage
    {
    public:
    unsigned short imagic;
    unsigned short type;
    unsigned short dim;
    unsigned short sizeX, sizeY, sizeZ;
    char name[128];
    unsigned char *data;
    };

    RgbImage* RgbLoad( char *);



    // rgb.cc

    #include "rgb.h"

    #define IMAGIC 0x01da
    #define IMAGIC_SWAP 0xda01

    #define SWAP_SHORT_BYTES(x) ((((x) & 0xff) << | (((x) & 0xff00) >> )
    #define SWAP_LONG_BYTES(x) (((((x) & 0xff) << 24) | (((x) & 0xff00) << ) | \
    ((((x) & 0xff0000) >> | (((x) & 0xff000000) >> 24)))

    class _RgbImage
    {
    public:
    unsigned short imagic;
    unsigned short type;
    unsigned short dim;
    unsigned short sizeX, sizeY, sizeZ;
    unsigned long min, max;
    unsigned long wasteBytes;
    char name[80];
    unsigned long colorMap;
    FILE *file;
    unsigned char *tmp[5];
    unsigned long rleEnd;
    unsigned long *rowStart;
    unsigned long *rowSize;
    };

    static _RgbImage *ImageOpen(char *fileName)
    {
    _RgbImage *image;
    unsigned long *rowStart, *rowSize, ulTmp;
    int x, i;

    image = (_RgbImage *)malloc(sizeof(_RgbImage));
    if (image == NULL)
    {
    fprintf(stderr, "Out of memory!\n");
    exit(-1);
    }
    if ((image->file = fopen(fileName, "rb")) == NULL)
    {
    perror(fileName);
    exit(-1);
    }
    /*
    * Read the image header
    */
    fread(image, 1, 12, image->file);
    /*
    * Check byte order
    */
    if (image->imagic == IMAGIC_SWAP)
    {
    image->type = SWAP_SHORT_BYTES(image->type);
    image->dim = SWAP_SHORT_BYTES(image->dim);
    image->sizeX = SWAP_SHORT_BYTES(image->sizeX);
    image->sizeY = SWAP_SHORT_BYTES(image->sizeY);
    image->sizeZ = SWAP_SHORT_BYTES(image->sizeZ);
    }

    for ( i = 0 ; i <= image->sizeZ ; i++ )
    {
    image->tmp[i] = (unsigned char *)malloc(image->sizeX*256);
    if (image->tmp[i] == NULL )
    {
    fprintf(stderr, "Out of memory!\n");
    exit(-1);
    }
    }

    if ((image->type & 0xFF00) == 0x0100) /* RLE image */
    {
    x = image->sizeY * image->sizeZ * sizeof(long);
    image->rowStart = (unsigned long *)malloc(x);
    image->rowSize = (unsigned long *)malloc(x);
    if (image->rowStart == NULL

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

    Re: file type

    Sorry, seems to have many problems on the network. I'll put the all code later.

  10. #10
    Senior Member Frequent Contributor
    Join Date
    Aug 2004
    Location
    munich, germany
    Posts
    659

    Re: file type

    well, i never had a segv with this, but there's
    a first time for everything.

    the question is: where does the segmentation fault
    occur? you should expand the code i posted with
    some printf("ok so far\n"); to see where exactly
    the problem is. maybe you are not allowed to
    create a file, so you should check if (out==NULL).

Page 1 of 3 123 LastLast

Similar Threads

  1. data type FILE in kernel
    By agmegharaj in forum OpenCL
    Replies: 2
    Last Post: 09-05-2011, 09:48 PM
  2. Where is the type FILE?
    By tiregarfio in forum OpenGL: Basic Coding
    Replies: 13
    Last Post: 07-28-2006, 09:35 AM
  3. Replies: 12
    Last Post: 05-25-2005, 12:42 PM
  4. bitmap-type in opengl to eps file
    By koko in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 04-24-2002, 02:54 PM
  5. Type 2 and Type 3 errors
    By in forum OpenGL: macOS
    Replies: 4
    Last Post: 09-09-2000, 06:55 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