在 C++ 中的 SDL 编程中(我在 Ubuntu Linux 中编写代码),为了在屏幕上绘制文本,我创建了一个函数,它的第二个参数获取文本。它的类型是 char*。在主函数中,我应该将什么发送到上述函数的第二个参数。例如在这段代码中,我在编译时出错:(我想使用函数在屏幕上绘制文本(Player1 必须播放...))
#include<iostream>
#include"SDL/SDL.h"
#include<SDL/SDL_gfxPrimitives.h>
#include "SDL/SDL_ttf.h"
using namespace std;
void drawText(SDL_Surface* screen,char* strin1 ,int size,int x, int y,int fR, int fG, int fB,int bR, int bG, int bB)
{
TTF_Font*font = TTF_OpenFont("ARIAL.TTF", size);
SDL_Color foregroundColor = { fR, fG, fB };
SDL_Color backgroundColor = { bR, bG, bB };
SDL_Surface* textSurface = TTF_RenderText_Shaded(font, strin1,foregroundColor, backgroundColor);
SDL_Rect textLocation = { x, y, 0, 0 };
SDL_BlitSurface(textSurface, NULL, screen, &textLocation);
SDL_FreeSurface(textSurface);
TTF_CloseFont(font);
}
int main(){
SDL_Init( SDL_INIT_VIDEO);
TTF_Init();
SDL_Surface* screen = SDL_SetVideoMode(1200,800,32,0);
SDL_WM_SetCaption("Ping Pong", 0 );
SDL_Delay(500);
drawText(screen,"Player1 must play with ESCAPE & SPACE Keys and player2 must play with UP & DOWN Keys. . . Have Fun!!!",20,15,550,50,50,100,180,180,180);
return 0;
}