I'm writing a OpenGl Game using SDL 2.0. Now I have one problem. I will draw a image on the screen. Now I create the window and initialize everything. The image does load without errors but does not show on the screen. Below are a few code samples. All this code is needed for drawing a bitmap. No other code is shown. I get an black window with this code. And no image :(. (Update the code to main and a function)
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);
}