当前位置: 首页>>代码示例>>C++>>正文


C++ Font::GetDisplayListID方法代码示例

本文整理汇总了C++中Font::GetDisplayListID方法的典型用法代码示例。如果您正苦于以下问题:C++ Font::GetDisplayListID方法的具体用法?C++ Font::GetDisplayListID怎么用?C++ Font::GetDisplayListID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Font的用法示例。


在下文中一共展示了Font::GetDisplayListID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Print

void FontMan::Print(const char * fontName, float x, float y, const char *fmt, ...)  {
	// We want a coordinate system where things coresponding to window pixels.
	PushScreenCoordinateMatrix();

    char		OLDtext[256];							// Holds Our String
	va_list		ap;										// Pointer To List Of Arguments

	if (fmt == NULL)									// If There's No Text
		*OLDtext=0;											// Do Nothing
	else {
        va_start(ap, fmt);									// Parses The String For Variables
            vsprintf(OLDtext, fmt, ap);						// And Converts Symbols To Actual Numbers
        va_end(ap);											// Results Are Stored In Text
	}

    Font * font = fontMap[fontName];
    if(font == NULL)
    {
        fprintf(stderr, "Font with name %s doesn't exist. I can't print %s.\n", fontName, OLDtext);
        return;
    }
	GLuint listID = font->GetDisplayListID();
	float textHeihgt = font->GetHeight();
    float lineHeight = textHeihgt / 0.63f;
	//Here is some code to split the text that we have been
	//given into a set of lines.
	//This could be made much neater by using
	//a regular expression library such as the one avliable from
	//boost.org (I've only done it out by hand to avoid complicating
	//this tutorial with unnecessary library dependencies).

	wchar_t	* NEWtext;

	NEWtext = ToWChar(OLDtext);

	const wchar_t *start_line=NEWtext;
	vector<wstring> lines;

    wchar_t *c;

	for(c=NEWtext;*c;c++) { //puvodene const wchar_t *c=NEWtext
		if(*c=='\n') {
			wstring line;
			for(const wchar_t *n=start_line;n<c;n++) line.append(1,*n);
			lines.push_back(line);
			start_line=c+1;
		}
	}
	if(start_line) {
		wstring line;
		for(const wchar_t *n=start_line;n<c;n++) line.append(1,*n);
		lines.push_back(line);
	}

	/*
	for(c=NEWtext ;*c;c++) {
		if(*c=='\n') {
			wstring line;
			for(const int *n=start_line;n<c;n++) line.append(1,*n);
			lines.push_back(line);
			start_line=c+1;
		}
	}
	if(start_line) {
		wstring line;
		for(const int *n=start_line;n<c;n++) line.append(1,*n);
		lines.push_back(line);
	}*/

	glPushAttrib(GL_LIST_BIT | GL_CURRENT_BIT  | GL_ENABLE_BIT | GL_TRANSFORM_BIT);
	glMatrixMode(GL_MODELVIEW);
	glDisable(GL_LIGHTING);
	glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glListBase(listID);

	float modelview_matrix[16];
	glGetFloatv(GL_MODELVIEW_MATRIX, modelview_matrix);

	//This is where the text display actually happens.
	//For each line of text we reset the modelview matrix
	//so that the line's text will start in the correct position.
	//Notice that we need to reset the matrix, rather than just translating
	//down by h. This is because when each character is
	//draw it modifies the current matrix so that the next character
	//will be drawn immediatly after it.
    float dx = 0.0f, dy = 0.0f;

	for(unsigned int loop1 = 0; loop1 < lines.size(); loop1++) {
	    AlignTextCoord(dx, dy, GetTextWidth(fontName, lines[loop1].c_str()), lineHeight * (lines.size() - 1) + textHeihgt);

		glPushMatrix();
		glLoadIdentity();
		glTranslatef(x + dx, y + dy + (lineHeight * loop1) + textHeihgt, 0);
		glMultMatrixf(modelview_matrix);
		glCallLists(lines[loop1].length(), GL_UNSIGNED_SHORT, lines[loop1].c_str());//NEWCESTINA

//.........这里部分代码省略.........
开发者ID:houpcz,项目名称:Houp-s-level-editor,代码行数:101,代码来源:FontMan.cpp


注:本文中的Font::GetDisplayListID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。