Пример #1
0
// takes a screen shot and saves it to a TGA image
int tgaGrabScreenSeries(char *filename, int x, int y, int w, int h) {

	unsigned char *imageData;

	// allocate memory for the pixels
	imageData = (unsigned char *)malloc(sizeof(unsigned char)* w * h * 4);

	// read the pixels from the frame buffer
	glReadPixels(x, y, w, h, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)imageData);

	// save the image 
	return(tgaSaveSeries(filename, w, h, 32, imageData));
}
Пример #2
0
// takes a screen shot and saves it to a TGA image
int tgaGrabScreenSeries(char *filename, int xmin, int ymin, int xmax, int ymax) {

	int w, h;
	unsigned char *imageData;

	// compute width and heidth of the image
	w = xmax - xmin;
	h = ymax - ymin;

	// allocate memory for the pixels
	imageData = (unsigned char *)malloc(sizeof(unsigned char)* w * h * 4);

	// read the pixels from the frame buffer
	glReadPixels(xmin, ymin, xmax, ymax, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *) imageData);

	// save the image 
	return(tgaSaveSeries(filename, w, h, 32, imageData));
}
Пример #3
0
int terrainSaveAsTGA(char *filename) {
	
	unsigned char *imageData,point;
	int totalPoints,status,mode,i;
	float min,max;

	if (terrainHeights == NULL)
		return TERRAIN_ERROR_NOT_INITIALISED;



	if (terrainColors == NULL)
		mode = 1;
	else 
		mode = 4;

	totalPoints = terrainGridWidth * terrainGridLength;
	min = terrainHeights[0];
	max = terrainHeights[0];
	for(i=1;i < totalPoints ; i++) {
		if (terrainHeights[i] > max)
			max = terrainHeights[i];
		if (terrainHeights[i] < min)
			min = terrainHeights[i];
	}

	imageData = (unsigned char *)malloc(sizeof(unsigned char) * totalPoints*mode);

	for(i=0;i < totalPoints; i++) {
		if (mode > 1) {
			imageData[i*mode] = (unsigned char)(terrainColors[i*(mode-1)])*256;
			imageData[i*mode+1] = (unsigned char)(terrainColors[i*(mode-1)+1])*256;
			imageData[i*mode+2]   = (unsigned char)(terrainColors[i*(mode-1)+2])*256;
		}
		point = (unsigned char)((terrainHeights[i] - min) / (max-min) * 255.0);
		imageData[i*mode + mode-1] = point;
	}
	status = tgaSaveSeries(filename,terrainGridWidth,terrainGridLength, mode*8, imageData);

	if (status==TGA_OK)
		return(TERRAIN_OK);
	else
		return(TERRAIN_ERROR_NOT_SAVED);
}