Just wandering about sdl SDL_RenderPresent()

So, i was trying to undestand how it works, and checking the code gave me this:
1
2
3
4
/**
 *  \brief Update the screen with rendering performed.
 */
extern DECLSPEC void SDLCALL SDL_RenderPresent(SDL_Renderer * renderer);


so i think DECLSPEC is something to open a dll, and then in dll is the routine sdlcall, is that right? Where i can find it's implementation?
You won't find what you're looking for like that.

extern -> You don't have the source: The compiled file is in a library.
DECLSPEC -> You shouldn't care about this at the moment.
SDLCALL -> Unified SDL Calling Convention

To look at the implementation, download the SDL's source code and search for SDL_RenderPresent in all the .h and .cpp files.

You'll match one .h and one .cpp file.
The .cpp file has what you're looking for.
So basically it calls a lib file like .a or .so?

AND THE implementation of this
1
2
3
4
5
#define CHECK_RENDERER_MAGIC(renderer, retval) \
    if (!renderer || renderer->magic != &renderer_magic) { \
        SDL_SetError("Invalid renderer"); \
        return retval; \
    } 
Last edited on
A .lib file is the Windows equivalent of a Linux .a file. A .dll file is the Windows equivalent of a Linux .so file. Loosely speaking...
I'm trying to understand this:
1
2
3
4
5
6
7
8
9
SDL_RenderPresent(SDL_Renderer * renderer)
{
    CHECK_RENDERER_MAGIC(renderer, );

    /* Don't draw while we're hidden */
    if (renderer->hidden) {
        return;
    }
    renderer->RenderPresent(renderer);

I don't understand where this function is implemented and what does:

This extracted from the header of the structure.
 
 void (*RenderPresent) (SDL_Renderer * renderer);


What MAGIC does, is it normal?
1
2
3
4
5
#define CHECK_RENDERER_MAGIC(renderer, retval) \
    if (!renderer || renderer->magic != &renderer_magic) { \
        SDL_SetError("Invalid renderer"); \
        return retval; \
    }  
Last edited on
It is.
It checks the renderer is a valid pointer.
You should look into SDL_Renderer::RenderPresent.
Maybe i'm mad or something but in the source i find this
src/render/SDL_render.c

1
2
3
4
5
6
7
8
9
10
11
void
SDL_RenderPresent(SDL_Renderer * renderer)
{
    CHECK_RENDERER_MAGIC(renderer, );

    /* Don't draw while we're hidden */
    if (renderer->hidden) {
        return;
    }
    renderer->RenderPresent(renderer);
}


I just cant get how it works.
When you call SDL_RenderPresent(render) it updates the screen, but how?
where is the actual code, i mean the directx or opengl stuff
I wrote:
You should look into SDL_Renderer::RenderPresent.
Last edited on
MikeyBoy wrote:
A .lib file is the Windows equivalent of a Linux .a file. A .dll file is the Windows equivalent of a Linux .so file. Loosely speaking...

Windows has .lib, .a, and .dll and Linux has .a and .so (shared object) for libraries. I felt that needed to be pointed out because Allegro, for example, when compiled will name the files .lib or .a (even then I think it is dependant on the compiler because I think MSVC is .lib and MinGW is .a).
extension is irrelevalt. I can create lib file with .code extension and it will work fine.
lib and dll is extension adopted in Windows
As MinGW is windows port of linux facilities, it just didn't bother with renaming and lef everything as it was there.
Where i can find it?
I've checked into SDL_Render.c/h and sysrender.h
But i can't find SDL_Renderer::RenderPresent
It's not in a .c file, I believe it's in a .cpp file.
AFAIK there is no C++ in SDL. It's a C lib.

So there isn't going to be a SDL_Renderer::RenderPresent

Instead... RenderPresent is likely a function pointer which points to a implementation-specific function. There is no way to tell what that function is named from just the code you posted.


Some options are:

1) Step into the function call with a debugger and see where it takes you

2) Search the source for "RenderPresent =" and see what is being assigned to that pointer.


EDIT:

actually... it's extremely likely that the function pointer would be assigned in SDL_CreateRenderer.
Last edited on
MiiNiPaa wrote:
extension is irrelevalt. I can create lib file with .code extension and it will work fine.

I don't think that is true, at least not in Linux with GCC, so I'd imagine it would be the same for MinGW. Last I knew, the linkers were designed to look for specific extensions. I even tested this under Linux using your example. I made a quick simple library and named it both libmean.a and then named it libmans.code. Then tried linking a simple program against each. libmean.a linked with no trouble, but trying to link against libmans.code it gives a linker error that it can't find it.
Last edited on
@Disch, maybe it's a C++ library with a C interface...
But after all it's SDL_Render.c it's being called from. My fault.
That and SDL_Render is an exposed struct, so if it had member functions it couldn't be exposed as a C API. ;P

But yes I didn't check all the SDL source code so there might be some C++ in there somewhere. I'm kind of doubtful though.
Disch wrote:
But yes I didn't check all the SDL source code so there might be some C++ in there somewhere. I'm kind of doubtful though.

Yeah, Ryan Gordon (occulus) said the library is C with bindings for other languages. That it is written in C, but should work with C++ with no problem.
Last edited on
could someone explain me how sld_renderpresent() works?
I think it updates the window with a surface in the renderpresent function.
is that right?
Wiki page for SDL_RenderPresent: http://wiki.libsdl.org/SDL_RenderPresent
Use this function to update the screen with rendering performed.

Think that is as clear as you can get for how it works.
Topic archived. No new replies allowed.