I have been using sdl_gfx ( sdl2 extension library https://github.com/ferzkopp/SDL_gfx ) to make Android games, I have always noticed that rendering primitives is so slow.
So I was rendering it once to a texture then drawing the texture on each frame to the screen, but now I'm working on a game project in which that method is not possible.

I am looking for an alternative, is there a way to render primitives ( with alpha ) on Android using SDL2? A crossplatform method (not GLES). sdl_gfx is fine but soooo slow (double slow on Android but even under Windows so slow) I think that's because it is using the SDL2 renderer to render to the screen, by calculating the pixels of the primitive and draw each pixel to the screen, so it is using the CPU not GPU (software rendering), that makes it so slow.


1 Answer 1


You can render a quad image directly to the screen using OpenGL.


void RenderTests::RenderQuad()
    static GLuint quadVAO = 0;
    static GLuint quadVBO;

    if (quadVAO == 0)
        GLfloat quadVertices[] = {
            // Positions        // Texture Coords
            -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
            -1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
            1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
            1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
        // Setup plane VAO
        glGenVertexArrays(1, &quadVAO);
        glGenBuffers(1, &quadVBO);
        glBindBuffer(GL_ARRAY_BUFFER, quadVBO);
        glBufferData(GL_ARRAY_BUFFER, sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)0);
        glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(GLfloat), (GLvoid*)(3 * sizeof(GLfloat)));
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

You will have to start by initializing OpenGL and have quite a few steps to go before you can actually just draw an image, but the tutorials cover all that as well, just start from the beginning with hello triangle tutorial.


  • \$\begingroup\$ thanks , an other alternative is sdl_gpu i was using but now i just have to build it to android, but thanks the tutorial is awesome , i will read it all ofr sure \$\endgroup\$ Sep 17, 2016 at 7:23
  • \$\begingroup\$ This approach however means that you can't use SDL_Renderer anymore for anything, and that you have to spend time implementing your own rendering pipeline. \$\endgroup\$
    – user35344
    Sep 17, 2016 at 8:44
  • \$\begingroup\$ First off that's not true. Second off it's wholly inappropriate to use it for sprites etc. and this is the proper way to make a 2D game with SDL. \$\endgroup\$
    – Yudrist
    Sep 17, 2016 at 9:04
  • \$\begingroup\$ yeah , i still can used SDL_Renderer , i just need to create the gl_context before the render and then create the render using opengl driver , ( there is how forums.libsdl.org/… ) but one thing , the driver's name there is "opengl" but i think it is not the case for android , i think it won't work that way and i have to change to something else like "gles" , any ideas ? \$\endgroup\$ Sep 17, 2016 at 9:51
  • \$\begingroup\$ That's just not true. Using OpenGL and SDL_Renderer at the same time is not possible (or very hard and more hacky), as SDL_Renderer might use DX behind the scenes. Secondly, it is not wholly inappropriate to use SDL_Renderer for sprites etc. This is definitely not the way to make a 2D game with SDL. SDL_Renderer is the way to make a 2D game with SDL. \$\endgroup\$
    – user35344
    Sep 17, 2016 at 13:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .