Android: draw a cube with transparent background


#1

Hi all

This may be a stupid question, i am not able to get a rotating 3d cube render with transparent background to see the underlying ‘android:theme="@style/SplashScreen"’ i have made

i am using the SDLActivity.java and jni

in java part of the source file i have done ‘getHolder().setFormat(PixelFormat.RGBA_8888);’ to get an Surface with alpha channel

in jni c source code i am doing this:

SDL_CreateWindow

SDL_GL_CreateContext

SDL_CreateRGBSurface -> 32bit

Render:

glClear(GL_COLOR_BUFFER_BIT);

glClearColor(0.0f, 0.0f, 0.0f, 0.0f); -> i have tried both, 1.0f and 0.0f to clear the background with the alpha channel -> it stays always black ( cube renders perfectly )

glBindBuffer

glVertexAttribPointer

glEnableVertexAttribArray

glDrawArrays

SDL_GL_SwapWindow

my question is, do i have to create a window and surface in jni, thought it’s already created in SDLActivity and is this what i was trying technicaly possible ? I mean render an 3d surface on top of an 2d surface with transparent background ?

RG


#2

Normally you would do your SDL_Init, set your OpenGL version and then SDL_CreateWindow. There’s a “test” folder with all the SDL files. Take a look at testgl2.c to see if you have everything setup correctly. Getting your first thing running with OpenGL can be a bit of a pain because you might be missing something.

Be sure to enable alpha blending.

// Enable alpha blending
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Also, a transparent background doesn’t make a lot of sense. All you’re doing is blending with what ever color you’ve wiped your back buffer with.