我正在使用 SDL 2.0 编写一个 OpenGL 游戏。现在我有一个问题。我将在屏幕上绘制图像。现在我创建窗口并初始化所有内容。图像确实加载没有错误,但没有显示在屏幕上。下面是一些代码示例。绘制位图需要所有这些代码。没有显示其他代码。我得到一个带有此代码的黑色窗口。而且没有图像:(。(将代码更新为 main 和一个函数)
void Bitmap(const tstring& nameRef, int xPos, int yPos, int width, int height)
{
SDL_Surface* image;
SDL_Rect rect;
rect.x = xPos;
rect.y = yPos;
rect.h = height;
rect.w = width;
image = SDL_LoadBMP(("./GameData/Bitmap/" + m_FileName).c_str());
SDL_BlitSurface(image , NULL , SDL_GetWindowSurface(GAME_ENGINE->GetMainWindow()) , &rect);
}
int main(int argc, char** argv)
{
SDL_Window * m_MainWindowPtr =nullpr;
//Initialize SDL
if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
{
return false;
}
//Create Window
if(m_Fullscreen == false)
{
m_MainWindowPtr = SDL_CreateWindow(m_WindowName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_ScreenWidth, m_ScreenHeight, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
}
else if(m_Fullscreen == true)
{
m_MainWindowPtr = SDL_CreateWindow(m_WindowName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_ScreenWidth, m_ScreenHeight, SDL_WINDOW_FULLSCREEN | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
}
//check if the window is made, else quit the game
if(m_MainWindowPtr == nullptr)
{
return false;
}
//Enable unicode
//SDL_EnableUNICODE( SDL_TRUE );
// NEEDED TO DRAW OPENGL
SDL_GLContext glcontext = SDL_GL_CreateContext(m_MainWindowPtr);
//LIKE THE OLD SWAP BUUFERS FUNCTION
SDL_GL_SwapWindow(m_MainWindowPtr);
Bitmap("test.bmp", 500, 500, 247, 360);
}