示例#1
0
文件: gui.cpp 项目: COHRINT/cuTORCS
/** Add an image background to a screen.
    @ingroup	gui
    @param	scr		Screen
    @param	filename	file name of the bg image
    @return	None.
 */
void
GfuiScreenAddBgImg(void *scr, const char *filename)
{
	tGfuiScreen	*screen = (tGfuiScreen*)scr;
	void *handle;
	float screen_gamma;
	GLbyte *tex;
	int w,h;
	const int BUFSIZE = 1024;
	char buf[BUFSIZE];
	
	if (glIsTexture(screen->bgImage) == GL_TRUE) {
		glDeleteTextures(1, &screen->bgImage);
	}

	snprintf(buf, BUFSIZE, "%s%s", GetLocalDir(), GFSCR_CONF_FILE);
	handle = GfParmReadFile(buf, GFPARM_RMODE_STD | GFPARM_RMODE_CREAT);
	screen_gamma = (float)GfParmGetNum(handle, GFSCR_SECT_PROP, GFSCR_ATT_GAMMA, (char*)NULL, 2.0);
	tex = (GLbyte*)GfImgReadPng(filename, &w, &h, screen_gamma);
	if (!tex) {
		GfParmReleaseHandle(handle);
		return;
	}

	glGenTextures(1, &screen->bgImage);
	glBindTexture(GL_TEXTURE_2D, screen->bgImage);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, (GLvoid *)(tex));
	free(tex);
	GfParmReleaseHandle(handle);
}
示例#2
0
bool grLoadPngTexture (const char *fname, ssgTextureInfo* info)
{
	GLubyte *tex;
	int w, h;
	int mipmap = 1;

	TRACE_GL("Load: grLoadPngTexture start");

	tex = (GLubyte*)GfImgReadPng(fname, &w, &h, 2.0);
	if (!tex) {
		return false;
    }

	if (info) {
		info -> width  = w;
		info -> height = h;
		info -> depth  = 4;
		info -> alpha  = true;
    }

	TRACE_GL("Load: grLoadPngTexture stop");

	// TODO: Check if tex is freed.
	// 		 Check/fix potential problems related to malloc/delete mixture
	//       (instead of malloc/free or new/delete).

	mipmap = doMipMap(fname, mipmap);

	GLubyte* tex2 = new GLubyte[w*h*4];
	memcpy(tex2, tex, w*h*4);
	free(tex);
	tex = tex2;
	
	return grMakeMipMaps(tex, w, h, 4, mipmap);
}