1

だから私は周りを見回しましたが、SDLとOpenGLでこれを実際に実装する最良の方法を見つけていません. 現時点では、TTF を使用して画面にテキストを表示できますが、実際にはテキストが本来の方法で表示されません。テキストを表示するときのエンジンの様子のスクリーン ショットを添付します。基本的に、コードで確認できることから、ウィンドウとして使用しているメインの SDL_Surface でテキスト テクスチャをブリットしていないことが原因だと思います。写真では、自分のキャラクターの周りに赤い衝突ボックスがあり、テキストをレンダリングしているテキスト テクスチャで覆われているためです。私にできることのアイデアはありますか?

私のゲーム ループでは、すべてを画面に描画する前後に beginDraw() と endDraw() を呼び出します。

写真: http://public.gamedev.net/uploads/monthly_07_2012/post-200874-0-25909300-1342404845_thumb.png

すべてのエンジン コードは、https ://github.com/Jevi/SDL_GL_ENGINE にあります。

PS: これについては別の記事を作成する予定ですが、私のコードを既に見ている場合は、これも質問することをお勧めします。エンジンにいくつかのメモリの問題があることに気付きました。タスクマネージャーでは、プログラムに割り当てられたメモリは、約 11000 K で開始されて以来、常に増加しています。

void graphics::SDL_GL_RenderText(float x1, float y1, int width, int height, const char* text, int ptsize, const char* ttfLoc, int r, int g, int b){
SDL_Surface* temp;
SDL_Surface* temp2;
SDL_Rect rect;
TTF_Font* font;
SDL_Color textColor;
unsigned int texture;

font = TTF_OpenFont( ttfLoc , ptsize );
textColor.r = r;
textColor.g = g;
textColor.b = b;

temp = TTF_RenderText_Blended( font, text, textColor );

// width = nextpoweroftwo(width);
// height = nextpoweroftwo(height);

temp2 = SDL_CreateRGBSurface(0, width, height, 32, r, g, b, 0);
SDL_BlitSurface(temp, 0, temp2, 0);

glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, temp2->w, temp2->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, temp2->pixels);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

/* prepare to render our texture */
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
glColor3f(1.0f, 1.0f, 1.0f);

/* Draw a quad at location */
glBegin(GL_QUADS);
glTexCoord2d(0,0);
glVertex2f(x1, y1);
glTexCoord2d(1,0);
glVertex2f(x1 + temp2->w, y1);
glTexCoord2d(1,1);
glVertex2f(x1 + temp2->w, y1 + temp2->h);
glTexCoord2d(0,1);
glVertex2f(x1, y1 + temp2->h);
glEnd();
glFinish();
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);

SDL_FreeSurface(temp);
SDL_FreeSurface(temp2);
TTF_CloseFont(font);
glDeleteTextures(1, &texture);

}

void graphics::GL_BeginDraw(){
glClear(GL_COLOR_BUFFER_BIT);
glPushMatrix(); //Start rendering phase
glOrtho(0,width,height,0,-1,1); //Set the matrix

}

void graphics::GL_EndDraw(){
glPopMatrix(); //End rendering phase
SDL_GL_SwapBuffers();
glFinish();

}

4

0 に答える 0