SDL2 Rendering API combined with Surfaces

Hello everyone!

I am creating a game engine with SDL2.0, but I hit a strange problem. When I use the rendering API, create a renderer and start doing stuff, it works fine. When I create surfaces and blit them onto the screen, it works fine. But when I try to do both at te same time, it only applies the last thing I do. To clarify:
1
2
3
4
5
6
7
SDL_RenderPresent(Renderer);
SDL_UpdateWindowSurface(Window);
//Only updates things that I did with surfaces

SDL_UpdateWindowSurface(Window);
SDL_RenderPresent(Renderer);
//Only updates the stuff I did with the renderer 


I could obviously do all the surface stuff with the renderer, but I would like to know why this isn't possible, of what I am doing wrong.
My guess would be that using functions such as SDL_LowerBlit() with the surface returned by SDL_GetWindowSurface() writes to a texture maintained by the SDL_Window, and that calling SDL_UpdateWindowSurface() calls SDL_RenderPresent() indirectly.
So I have found out that I cannot use both together, so I chose for the rendering method. But now I don't get my text drawn on the screen. Here is my function:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void OutlineFont::draw(const char* text, int x, int y, int r, int g, int b, int a, Graphics* gfx)
{
	if (mFont == nullptr)
		return;
		
	SDL_Surface* renderedText = nullptr;
	
	Uint8 aR = r, aG = g, aB = b, aA = a;
	
	SDL_Color color = {aR, aG, aB, aA};
	
	renderedText = TTF_RenderText_Solid(mFont, text, color);
	
	if (renderedText == nullptr)
	{
		std::cerr << "Failed to render text!\n TTF Error: " << TTF_GetError() << "\n";
		return;
	}
	
	SDL_Rect pos;
	pos.x = x;
	pos.y = y;
	
	SDL_Texture* textTexture = SDL_CreateTextureFromSurface(gfx->getRenderer(), renderedText);
	
	SDL_RenderCopy(gfx->getRenderer(), textTexture, nullptr, &pos);
		
	SDL_FreeSurface(renderedText);
	renderedText = nullptr;
	
	SDL_DestroyTexture(textTexture);
	textTexture = nullptr;
}
I've solved the problem now, thanks helios for your time.
Topic archived. No new replies allowed.