• R/O
  • SSH
  • HTTPS

Commit

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

X operations(XOPS)に非常に近いFPSゲームを制作・リメイクし、成果物をオープンソースとして公開することを目的としたプロジェクトです。


Commit MetaInfo

Revision144 (tree)
Time2016-08-27 08:35:52
Authorxops-mikan

Log Message

OpenGLにてシステムフォントによる文字列がうまく出ない問題を改善

Change Summary

Incremental Difference

--- trunk/d3dgraphics-opengl.cpp (revision 143)
+++ trunk/d3dgraphics-opengl.cpp (revision 144)
@@ -58,6 +58,7 @@
5858 now_SystemFontUStr[0] = NULL;
5959 SystemFontListIdx = 0;
6060 SystemFontListIdxSize = 0;
61+ SystemFont_posz = 1.0f;
6162 now_textureid = -1;
6263
6364 camera_x = 0.0f;
@@ -1161,6 +1162,9 @@
11611162 glAlphaFunc(GL_GREATER, 0.0f);
11621163 glEnable(GL_ALPHA_TEST);
11631164
1165+ //2DシステムフォントZ座標初期化
1166+ SystemFont_posz = 1.0f;
1167+
11641168 return 0;
11651169 }
11661170
@@ -1707,15 +1711,43 @@
17071711 glDisableClientState(GL_COLOR_ARRAY);
17081712 }
17091713
1714+//! @brief 最も長い行の文字数を取得
1715+//! @param str 文字列 (改行コード:可)
1716+//! @return 文字数
1717+//! @attention マルチバイト文字は 1文字あたり 2 としてカウントされます。
1718+int D3DGraphics::StrMaxLineLen(char *str)
1719+{
1720+ int maxlen = 0;
1721+ int cnt = 0;
1722+
1723+ for(int i=0; i<strlen(str); i++){
1724+ if( str[i] == '\n' ){
1725+ if( maxlen < cnt ){
1726+ maxlen = cnt;
1727+ }
1728+ cnt = 0;
1729+ }
1730+ else{
1731+ cnt += 1;
1732+ }
1733+ }
1734+
1735+ if( maxlen < cnt ){
1736+ maxlen = cnt;
1737+ }
1738+
1739+ return maxlen;
1740+}
1741+
17101742 //! @brief 文字を描画(システムフォント使用)
17111743 //! @param x x座標
17121744 //! @param y y座標
17131745 //! @param str 文字列 (改行コード:可)
17141746 //! @param color 色
1747+//! @warning 本関数は1フレーム間で100回までしか呼び出せません。(OpenGLコアのみ)
17151748 //! @warning <b>描画は非常に低速です。</b>画面内で何度も呼び出すとパフォーマンスに影響します。
17161749 //! @warning「改行コードを活用し一度に描画する」「日本語が必要ない文字はテクスチャフォントを活用する」などの対応を講じてください。
17171750 //! @attention フォントの種類やサイズは固定です。 文字を二重に重ねて立体感を出さないと見にくくなります。
1718-//! @todo 文字を二重に重ねると、上下関係が正しく処理されない。
17191751 //! @todo 1文字目が欠ける場合がある。
17201752 void D3DGraphics::Draw2DMSFontText(int x, int y, char *str, int color)
17211753 {
@@ -1722,7 +1754,10 @@
17221754 int len = strlen(str);
17231755 WCHAR *ustr;
17241756
1757+ y += 18;
1758+
17251759 Start2DRender();
1760+ glEnable(GL_DEPTH_TEST);
17261761
17271762 //テクスチャ無効
17281763 glDisable(GL_TEXTURE_2D);
@@ -1764,7 +1799,7 @@
17641799
17651800 //座標と色を設定
17661801 glBitmap(0, 0, 0, 0, 10, 0, NULL);
1767- glRasterPos2i(x, y);
1802+ glRasterPos3f((float)x, (float)y, SystemFont_posz);
17681803 glColor4ub((color>>24)&0xFF, (color>>16)&0xFF, (color>>8)&0xFF, color&0xFF);
17691804
17701805 for(int i=0; i<lstrlenW(ustr); i++){
@@ -1771,7 +1806,7 @@
17711806 if( ustr[i] == '\n' ){
17721807 //改行する
17731808 y += 19;
1774- glRasterPos2i(x, y);
1809+ glRasterPos3f((float)x, (float)y, SystemFont_posz);
17751810 }
17761811 else{
17771812 //ディスプレイリスト描画
@@ -1779,9 +1814,12 @@
17791814 }
17801815 }
17811816
1817+ SystemFont_posz -= 0.01f;
1818+
17821819 //Unicode文字列の廃棄
17831820 delete [] ustr;
17841821
1822+ //glDisable(GL_DEPTH_TEST);
17851823 End2DRender();
17861824 }
17871825
@@ -1792,10 +1830,9 @@
17921830 //! @param h 縦の大きさ
17931831 //! @param str 文字列 (改行コード:可)
17941832 //! @param color 色
1795-//! @warning <b>正しく中央揃えになりません。</b>
17961833 void D3DGraphics::Draw2DMSFontTextCenter(int x, int y, int w, int h, char *str, int color)
17971834 {
1798- Draw2DMSFontText(x, y, str, color);
1835+ Draw2DMSFontText(x + (SCREEN_WIDTH/2 - (StrMaxLineLen(str)*9/2)), y, str, color);
17991836 }
18001837
18011838 //! @brief 2D描画用設定
--- trunk/d3dgraphics.h (revision 143)
+++ trunk/d3dgraphics.h (revision 144)
@@ -208,6 +208,7 @@
208208 WCHAR *now_SystemFontUStr; //!< 現在表示中のシステムフォントによる文字列(Unicode)
209209 GLuint SystemFontListIdx; //!< システムフォントのディスプレイリスト
210210 int SystemFontListIdxSize; //!< システムフォントのディスプレイリストのサイズ
211+ float SystemFont_posz; //!< システムフォントのZ座標
211212 int now_textureid; //!< 現在設定中のテクスチャ番号
212213
213214 float camera_x; //!< カメラ座標
@@ -236,6 +237,7 @@
236237 bool LoadJPEGTexture(char* filename, bool BlackTransparent, TEXTUREDATA *ptexture);
237238 bool LoadPNGTexture(char* filename, bool BlackTransparent, TEXTUREDATA *ptexture);
238239 void SetTexture(int TextureID);
240+ int StrMaxLineLen(char *str);
239241 void Start2DRender();
240242 void End2DRender();
241243