⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 makestar.cpp

📁 空战游戏flacon源码
💻 CPP
字号:
#include "..\..\3Dlib\inline.h"
#include "..\..\3Dlib\image.h"
#include "..\..\3Dlib\filemem.h"
#include <stdlib.h>

GLint glLoadTextureBitmap (char *texname, GLtexture *texture);

void main (int argc, char *argv[])
{
	printf ("\nMakeStar v1.0 by Erick Jap\n\n");
	if (argc < 3) {
		puts ("Usage: MakeStar bitmapfile output");
		puts ("where bitmapfile is the star bitmap (LBM, GIF, PCX, BMP)");
		exit (1);
	}

	FILE *out = fopen (argv[2], "w");
	if (!out) {
		printf ("Can not open output file %s\n", argv[2]);
		exit (1);
	}

	GLtexture texture;
	if (glLoadTextureBitmap (argv[1], &texture)) {
		printf ("Can not load input file %s\n", argv[1]);
		fclose (out);
		exit (1);
	}

	fprintf (out, "STAR\t%s\n", argv[1]);
	fprintf (out, "COLOR\t1.0\t1.0\t1.0\n");
	GLfloat latitude, longitude;
	GLint centerx = texture.width >> 1;
	GLint centery = texture.height >> 1;
	GLint i, j, k;
	GLint *ptr = (GLint *) texture.textureData;
	for (i=0; i < texture.height;i++) {
		for (j=0; j < texture.width;j++) {
			k = *ptr++;
			if (k & 0xffffff) {
				GLfloat x = (GLfloat) (j - centerx);
				GLfloat y = (GLfloat) (centery - i);
				longitude = x / centerx;
				if (longitude > 1.0f) longitude = 1.0f;
				else if (longitude < -1.0f) longitude = -1.0f;

				latitude = y / centery;
				if (latitude > 1.0f) latitude = 1.0f;
				else if (latitude < -1.0f) latitude = -1.0f;

				fprintf (out, "POSITION\t%f\t%f\n", longitude, latitude);
			}
		}
	}
	fprintf (out, "ZZZZ\n");
	fclose (out);
	glReleaseMemory ((char *) texture.textureData);
}

GLint glLoadTextureBitmap (char *texname, GLtexture *texture)
{
	CTextureFileMemory 	fi;
	GLint i = fi.glOpenFileMem ((GLbyte *) texname);
	if (i != 1) return 1;
	fi.imageType = CheckImageType ((GLbyte *) texname);
	if (fi.imageType == IMAGE_TYPE_UNKNOWN) {
		fi.glCloseFileMem ();
		return 1;
	}
	fi.glReadFileMem ();
	i = ReadTextureImage (&fi);
	if (i != GOOD_READ) {
		fi.glCloseFileMem ();
		return 1;
	}
	GLint chromakey;
	GLbyte *ptr = ConvertImage (&fi.image, COLOR_16M, &chromakey);
	glReleaseMemory ((char *) fi.image.palette);
	glReleaseMemory ((char *) fi.image.image);
	if (!ptr) {
		fi.glCloseFileMem ();
		return 1;
	}
	texture -> width = fi.image.width;
	texture -> height = fi.image.height;
	texture -> textureChromaKey = chromakey;
	texture -> textureData = ptr;
	fi.glCloseFileMem ();
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -