SDL2 - Functionality usable before SDL_Init

Hello,

i’m in the process of building an object oriented wrapper on top of SDL2 for C++.

I couldn’t find any informations about this on the wiki pages, expect on the version functions so i wanted to ask here:
Which functions are available before SDL_Init is called?

A couple.
SDL_ShowSimpleMessageBox()?

You don’t really have any reason to worry about it. I can imagine an OO
wrapper interface that doesn’t make you need to worry about that.On Mon, Jan 20, 2014 at 11:38 PM, HorridoJoho <b.christian88 at web.de> wrote:

Hello,

i’m in the process of building an object oriented wrapper on top of SDL2
for C++.

I couldn’t find any informations about this on the wiki pages, expect on
the version functions so i wanted to ask here:
Which functions are available before SDL_Init is called?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Ivan Rubinson wrote:

You don’t really have any reason to worry about it. I can imagine an OO wrapper interface that doesn’t make you need to worry about that.

I have the following design.

The wrapper is an include only wrapper.
Everything resides in namespace SDL. Now i want to place all functions which can be used before SDL_Init in that namespace.
The functions which needs initialization are placed into a SDL::Root(singleton) class(first retrival calls SDL_Init).
SDL::Root provides methods like CreateWindow which return a SDL::Window shared pointer.
SDL::Window provides methods like GlCreateContext which returns SDL::GlContext shared pointer.
SDL::GlContext provides methods like MakeCurrent.

A small example of all this:

Code:
int main(int argc, char** argv)
{
try
{
SDL::SetMainReady();
SDL::Root::SetInitSubsystems(SDL_INIT_EVERYTHING);
SDL::Root::RawPtr root = SDL::Root::Singleton();

	// version specifications
	root->GlSetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
	root->GlSetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
	root->GlSetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);

	// force acceleration
	root->GlSetAttribute(SDL_GL_ACCELERATED_VISUAL, 1);

	// buffer specifications
	root->GlSetAttribute(SDL_GL_RED_SIZE, 8);
	root->GlSetAttribute(SDL_GL_GREEN_SIZE, 8);
	root->GlSetAttribute(SDL_GL_BLUE_SIZE, 8);
	root->GlSetAttribute(SDL_GL_ALPHA_SIZE, 8);
	root->GlSetAttribute(SDL_GL_BUFFER_SIZE, 32);
	root->GlSetAttribute(SDL_GL_DEPTH_SIZE, 24);
	root->GlSetAttribute(SDL_GL_STENCIL_SIZE, 8);
	root->GlSetAttribute(SDL_GL_DOUBLEBUFFER, 1);

	SDL::Window::SharedPtr wnd = root->CreateNewWindow("Test", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640, 480, SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE);
	SDL::GlContext::SharedPtr gl = wnd->GlCreateContext();

	while (true)
	{
		SDL::Event evt;
		if (root->PollEvent(evt))
		{
			SDL::Bool close = SDL_FALSE;

			switch (evt.type)
			{
			case SDL_WINDOWEVENT:
				switch (evt.window.event)
				{
				case SDL_WINDOWEVENT_CLOSE:
					close = SDL_TRUE;
					break;
				case SDL_WINDOWEVENT_RESIZED:
					glViewport(0, 0, evt.window.data1, evt.window.data2);
					break;
				}

				break;
			}

			if (close)
			{
				break;
			}
		}

		// clear the screen
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
		// rotate a little
		glRotatef(1, 1, 1, 1);
		// Triangle
		glBegin(GL_TRIANGLES);
		glColor3f(1.0f, 0.0f, 0.0f);
		glVertex3f(0.0f, 0.5f, 0.0f);
		glColor3f(0.0f, 1.0f, 0.0f);
		glVertex3f(-0.5f, -0.5f, 0.0f);
		glColor3f(0.0f, 0.0f, 1.0f);
		glVertex3f(0.5f, -0.5f, 0.0f);
		glEnd();

		wnd->GlSwap();
	}
}
catch (SDL::Exception &e)
{
	std::cout << e.what() << std::endl;
	std::cin.get();
	return 1;
}

return 0;

}

Now, since i have that singleton at the root of all functionallity which needs initialization, i want to put the functions without initialization
just inside the SDL namespace, and that’s the reason why i care about functionallity which don’t need initialization.

Which functions are available before SDL_Init is called?

Very few of them: the message box ones and SDL_GetError(), so you can do
something if SDL_Init() fails.

I’m not sure we have an official policy for this: lots of them don’t
need SDL_Init() to work, but I think we still frown upon you calling
them before a successful SDL_Init() call.

–ryan.