예제 #1
0
void CFontDisplay::drawCNString(const char* str)
{
	int len, i;
	wchar_t* wstring;
	HDC hDC = wglGetCurrentDC();
	GLuint list = glGenLists(1);

	// 计算字符的个数
	// 如果是双字节字符的(比如中文字符),两个字节才算一个字符
	// 否则一个字节算一个字符
	len = 0;
	for(i=0; str[i]!='\0'; ++i)
	{
		if( IsDBCSLeadByte(str[i]) )
			++i;
		++len;
	}

	// 将混合字符转化为宽字符
	wstring = (wchar_t*)malloc((len+1) * sizeof(wchar_t));
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, -1, wstring, len);
	wstring[len] = L'\0';

	// 逐个输出字符
	for(i=0; i<len; ++i)
	{
		wglUseFontBitmapsW(hDC, wstring[i], 1, list);
		glCallList(list);
	}

	// 回收所有临时资源
	free(wstring);
	glDeleteLists(list, 1);
}
예제 #2
0
void Window::drawString(string str) {
	int len = 0;
	wchar_t* wstring;
	HDC hDC = wglGetCurrentDC();

	for (int i = 0; str[i] != '\0'; ++i)
	{
		if (IsDBCSLeadByte(str[i]))
			++i;
		++len;
	}

	GLuint list = glGenLists(1);

	// 将混合字符转化为宽字符
	wstring = (wchar_t*)malloc((len + 1) * sizeof(wchar_t));
	MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str.c_str(), -1, wstring, len);
	wstring[len] = L'\0';

	// 逐个输出字符
	for (int i = 0; i < len; ++i)
	{
		wglUseFontBitmapsW(hDC, wstring[i], 1, list);
		glCallList(list);
	}

	// 回收所有临时资源
	free(wstring);
	glDeleteLists(list, 1);
}
예제 #3
0
//-----------------------------------------------------------------------------
//! ワイド文字列の描画
//-----------------------------------------------------------------------------
void  GLFont::DrawStringW(s32 x, s32 y, s32 z, wchar_t* format, ...)
{
	SelectObject(Hdc, Hfont);
	wchar_t buf[256];
	va_list ap;
	int	Length = 0;
	_list = 0;

	// ポインタがNULLの場合は終了
	if( format == NULL )
	{
		return;
	}

	// 文字列変換
	va_start(ap, format);
	vswprintf_s(buf, format, ap);
	va_end(ap);
	
	Length = wcslen(buf);
	_list   = glGenLists(Length);


	

	for( s32 i=0; i<Length; i++ )
	{
		// 文字のビットマップをディスプレイリストとして作成
		wglUseFontBitmapsW(Hdc, buf[i], 1, _list + (DWORD)i );
		/*glNewList(_list + i, GL_COMPILE);
		
		glEndList();*/
	}

	
	glDisable(GL_LIGHTING);		// 文字色を出すために光源を無効化
	// 描画位置の設定
	glRasterPos3i(x, y, z);
	// ディスプレイリストで描画
	for( s32 i=0; i<Length; i++ )
	{
		glCallList( _list+i);
	}
	glEnable(GL_LIGHTING);		// 光源を有効化
	// ディスプレイリスト破棄
	glDeleteLists(_list, Length);
	_list   = 0;
	//Length  = 0;
}
예제 #4
0
파일: Font.cpp 프로젝트: kudolf/Game
//ワイド文字列の描画
void Font::draw(int x,int y,wchar_t *format, ...)
{
	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(0, getWindowWidth(), getWindowHeight(), 0);
	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	glColor4f(color.r, color.g, color.b, color.a);

	wchar_t buf[256];
	va_list ap;
	int Length=0;
	int list=0;
  
	//ポインタがNULLの場合は終了
	if ( format == NULL ) return;

	//文字列変換
	va_start(ap, format);
	vswprintf_s(buf, format, ap);
	va_end(ap);

	Length = wcslen(buf);
	list = glGenLists(Length);
	for( int i=0; i<Length; i++ ) {
		wglUseFontBitmapsW(Hdc, buf[i], 1, list + (DWORD)i);
	}

	glDisable(GL_LIGHTING);
	glRasterPos2i(x, y);
	//ディスプレイリストで描画
	for( int i=0; i<Length; i++ ) {
		glCallList(list + i);
	}
	glEnable(GL_LIGHTING);
	//ディスプレイリスト破棄
	glDeleteLists(list, Length);
	list = 0;
	Length = 0;
	glPopMatrix();
	glLoadIdentity();
	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
}
예제 #5
0
void CLineComputeView::glDrawCnString(CString str, GLfloat *position) {
    int len = str.GetLength();
    HDC hDC = wglGetCurrentDC();
    GLuint list = glGenLists(1);

    // 逐个输出字符
    glTranslatef(position[0], position[1], position[2]);
    glRasterPos2f(0.0f, 0.05f);
    for(int i=0; i<len; ++i)
    {
        wglUseFontBitmapsW(hDC, str[i], 1, list);
        glCallList(list);
    }
    glTranslatef(-position[0], -position[1], -position[2]);
    glDeleteLists(list, 1);
}
예제 #6
0
static int
test_function(HDC hdc)
{
    bool pass = true;
    HGLRC ctx;
    GLuint dlist[2] = {100, 101};
    const char *string = "some string";

    ctx = wglCreateContext(hdc);
    if (!ctx) {
        fprintf(stderr, "Failed to create wgl context\n");
        return 1;
    }
    if (!wglMakeCurrent(hdc, ctx)) {
        fprintf(stderr, "Failed to make context current\n");
        return 1;
    }

    /* First, use the #ifdeffed variant of the function */
    wglUseFontBitmaps(hdc, 0, 255, dlist[1]);
    glListBase(dlist[1]);
    glCallLists(strlen(string), GL_UNSIGNED_BYTE, string);

    /* Now, use the specific version, manually. */
#ifdef UNICODE
    wglUseFontBitmapsW(hdc, 0, 255, dlist[2]);
#else
    wglUseFontBitmapsA(hdc, 0, 255, dlist[2]);
#endif
    glListBase(dlist[2]);
    glCallLists(strlen(string), GL_UNSIGNED_BYTE, string);

    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(ctx);

    return !pass;
}
예제 #7
0
void KH::TextDrawer::Out(const char * str)
{ 
	//DrawEngString(str);return;

	int len=0, i=0; wchar_t * wstring; 
	HDC hDC=wglGetCurrentDC(); 
	GLuint list=glGenLists( 1 ); //计算字符的个数 
								// 如果是双字节字符的(比如中文字符),两个字节才算一个字符     
								// 否则一个字节算一个字符 
	for( i=0; str[i]!='\0'; i++ ) {    //判断字符str[i]是否由两个字节组成    
		if( IsDBCSLeadByte( str[i] ))     
			i++;    
		len++; 
	} //将混合字符转化为宽字符 
	wstring=(wchar_t*)malloc((len+1)*sizeof(wchar_t)); 
	MultiByteToWideChar( CP_ACP, MB_PRECOMPOSED, str, -1, wstring, len ); 
	wstring[len]=L'\0'; //逐个输出字符 
	for( i=0; i<len; i++ ) {    
		wglUseFontBitmapsW( hDC, wstring[i], 1, list );    
		glCallList( list ); 
	} //资源回收 
	free( wstring ); 
	glDeleteLists( list, 1 ); 
}
예제 #8
0
int glPrintf(const char *format, ...)
{
	DWORD fdwCharSet = CHINESEBIG5_CHARSET;
	char szFace[] = "Courier New";
	int nHeight = 16;


	char buffer[65536];
	va_list args;
	va_start(args, format);
	vsprintf_s(buffer, format, args);
	va_end(args);

	static GLuint base = 0;
	static bool loaded[65536] = { 0 };
	static HFONT hFont;
	if (base == 0)
	{
		base = glGenLists(65536);
		hFont = CreateFont(nHeight, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, fdwCharSet,
			OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, ANTIALIASED_QUALITY,
			FF_DONTCARE | DEFAULT_PITCH, (LPCWSTR)szFace);
	}

	float p0[4], p1[4], c0[2][4] = { { 0, 0, 0, 1 }, { 1, 1, 1, 1 } };
	int i, j, len, offset[2] = { 1, 0 };
	wchar_t *wstr;
	GLint viewport[4];
	HDC hdc = 0;

	glGetIntegerv(GL_VIEWPORT, viewport);
	glGetFloatv(GL_CURRENT_RASTER_POSITION, p0);

	glPushAttrib(GL_LIGHTING_BIT | GL_DEPTH_BUFFER_BIT);
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);

	glMatrixMode(GL_PROJECTION);
	glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(0, viewport[2], 0, viewport[3]);

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();
	glLoadIdentity();

	static int x0 = 0, y0 = 0;
	if (memcmp(buffer, ">>glut", 6) == 0)
	{
		sscanf_s(buffer, ">>glut(%i,%i)", &x0, &y0);
		glRasterPos2f(4, viewport[3] - nHeight);
		glRasterPos2f(4, viewport[3] - nHeight);
	}
	else if (strcmp(buffer, ">>free") == 0)
	{
		glDeleteLists(base, 65536); base = 0;
		memset(loaded, 0, 65536 * sizeof(bool));
		DeleteObject(hFont);
	}
	else
	{
		glRasterPos2f(p0[0], p0[1]);
		glGetFloatv(GL_CURRENT_RASTER_COLOR, c0[1]);
		len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buffer, -1, 0, 0);
		wstr = (wchar_t*)malloc(len*sizeof(wchar_t));
		MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buffer, -1, wstr, len);
		for (j = 0; j<2; j++)
		{
			glColor4fv(c0[j]);
			glRasterPos2f(p0[0] + offset[j], p0[1] - offset[j]);
			for (i = 0; i<len - 1; i++)
			{
				if (wstr[i] == '\n')
				{
					glGetFloatv(GL_CURRENT_RASTER_POSITION, (float*)&p1);
					glRasterPos2f(4 + x0 + offset[j], p1[1] - (nHeight + 2));
				}
				else
				{
					if (!loaded[wstr[i]])
					{
						if (hdc == 0)
						{
							hdc = wglGetCurrentDC();
							SelectObject(hdc, hFont);
						}
						wglUseFontBitmapsW(hdc, wstr[i], 1, base + wstr[i]);
						loaded[wstr[i]] = true;
					}
					glCallList(base + wstr[i]);
				}
			}
		}
		free(wstr);
	}

	glMatrixMode(GL_PROJECTION);
	glPopMatrix();
	glMatrixMode(GL_MODELVIEW);
	glPopMatrix();
	glPopAttrib();

	return 0;
}