loading an image file?

i want to load an image file and make a few simple changes to it. im not sure if opengl is the easiest method (for a beginner), but since i have it all set up on my computer and i am pretty good with c++, i thought id give it a shot.
however, while ive seen tutes on drawing to a screen and using text files, i havent found anything dealing with the manipulation of image files.

if someone knows a link to anything explaining this, or better yet, here is a list of what i need (maybe just tell me the gl command that does each)

-open an image file (dont care what format)
-copy a portion of the screen
-duplicate, move, rotate, reflect copy
-save a portion to another file

im sure this isnt that hard for someone with experience

thanks in advance

Ryan (atleast i assume that’s your name),

OpenGL is a good API to do stuff like this. To open a file you will have to use the functions that the API for your OS gives you. Like for windows there are some functions to load bitmaps. For JPEGS, there is a library by intel you can get.

To copy stuff from the screen, you use the glReadPixels(…) procedure (i think). Essentially, once you draw the picture to the screen, you can copy the frame buffer again.

To do all the duplication, rotation, etc., you will need to probably use your own math OR you can use that image as a texture map on a square/rectangle and rotate the polygon.

Finally the saving is much like the opening the file. You will have to use the API functions from your OS, or the library you used to open the first image. I’ll post some links a bit later.

thanks for the reply. i think i found a way to load bitmaps as textures, but the code i found, applied the texture to a 3d object, and when i removed the object, i couldnt get it to display. this is the code i found to load a bitmap:

unsigned char *LoadBitmapFile(char *file, BITMAPINFOHEADER *bitmapInfoHeader)
// Bitmaps are made up of 3 parts, the file header, info header, and
// the image. Once we load in the file and info headers we can then
// load the image into our unsigned char variable called bitmapData.

FILE *pFile; // Need this to open a file.
BITMAPFILEHEADER header; // This will hold the bitmap header information.

unsigned char *textureData;   // This will hold the bitmap image itself.

// This will be used to swap the image colors from BGR to RGB.
unsigned char textureColors;

pFile = fopen(file, "rb");    // Open the file.

if(pFile == NULL) return NULL;// Check and make sure there are no errors.

// Read in the bitmap header info into the BITMAPFILEHEADER variable.
fread(&header, sizeof(BITMAPFILEHEADER), 1, pFile);

// Make sure this is a real bitmap by checking the ID.
if(header.bfType != BITMAP_ID)
	   return NULL;

// Read in the second header info into the BITMAPINFOHEADER variable.
fread(bitmapInfoHeader, sizeof(BITMAPINFOHEADER), 1, pFile);

// Place the pointer in front of where the image data starts.
fseek(pFile, header.bfOffBits, SEEK_SET);

// Dynamically create enough memory for the image.
textureData = (unsigned char*)malloc(bitmapInfoHeader->biSizeImage);

// Error checking.  Make sure the memory was allocated.
	   return NULL;
// Read in the image.
fread(textureData, 1, bitmapInfoHeader->biSizeImage, pFile);

// Error checking.  Make sure an image was loaded.
if(textureData == NULL)
	   return NULL;

// Bitmaps are saved in BGR format so we will make the image RGB by...
for(unsigned index = 0; index < bitmapInfoHeader->biSizeImage; index+=3)
	   textureColors = textureData[index];
	   textureData[index] = textureData[index + 2];
	   textureData[index + 2] = textureColors;

fclose(pFile);     // We are done with the file so close it.
return textureData;  // Send the image to the function that called this.



i then tried displaying the bitmap using (the code i found used glGenTexture or something and it didnt show anything):

glBitmap(192, 128, 0, 0, 0, 0, bitmapData);

it shows a black and white image that is unrecognizable as originating from the input image.

what am i doing wrong?

thanks again

First OpenGL is a 3D drawing API, is has not load or save functions for 2D bitmaps.
But you will find that they are lot’s of tutors on how to load a bitmap and also save the images.

They are two ways to put a image on the screen you can do a 2D pixel operation, slow not the prefered way.
Or you can apply a image to a quad as a texture the best way for your application.

Once the image is loaded as a textured quad you can use the scale, rotate, Alpha and blending functions to change the image and create diffrent effects.

Note you can not use the above functions if you load the image to the screen useing the glbitmap function, you have to be using a textured quad!!!

On my website I have a gane called black jack in which I apply a image to a quad object. http://www.angelfire.com/linux/nexusone/

[This message has been edited by nexusone (edited 01-27-2003).]