Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access screen from ITCODSDLRenderer::render #143

Closed
nataraj-hates-MS-for-stealing-github opened this issue Jan 8, 2023 · 2 comments
Labels

Comments

@nataraj-hates-MS-for-stealing-github
Copy link
Contributor

Hi!
I am working with software that uses quite old version of TCOD (1.5.0).
In that version render method of ITCODSDLRenderer had screen option, that as I gess, would allow to put something on the screen while rendering.

void render(void *sdlSurface, void*sdlScreen);

The code did some processing and finally copied tile to the screen.

SDL_BlitSurface((mapSurface.get(), &srcRect, screen, &dstRect);

https://gitlab.com/dhyannataraj/goblin-camp/-/blob/master/game/src/tileRenderer/sdl/SDLTilesetRenderer.cpp#L178

While initial porting I commented out all SDL-related code that does not work. But now I am trying to get graphical tiles back.

Do you have any idea, how I can port this code? May be there is some global variable simiular to screen, or something... Where I can get it in modern TCOD API?

@HexDecimal
Copy link
Collaborator

The old methods make inefficient copies of the screen across the RAM/VRAM boundaries. Libtcod's new methods keep everything in VRAM while also letting you render as many consoles you want to anywhere on the screen while letting you use SDL's renderer like normal.

Look at TCOD_sdl2_atlas_new, TCOD_sdl2_render_texture, and TCOD_sdl2_render_texture_setup documented in this header. I talk about these more in issue #18. How you access the SDL renderer depends on how modernized your program is, but you can get it from a libtcod context or from libtcod's old internals:

TCOD_context_get_sdl_renderer to get it from a context.
TCOD_sys_get_sdl_renderer to get it from the internals.

Or get it from SDL itself. You don't need a context at all to use this method for console rendering.

@nataraj-hates-MS-for-stealing-github
Copy link
Contributor Author

I finally did

	TCOD_Context* context = TCOD_sys_get_internal_context();
	SDL_Window* window = context->get_sdl_window();
	SDL_Surface *screen = SDL_GetWindowSurface(window);

At least this works... Will deal with porting it to new API later...

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants