The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Android: draw a cube with transparent background
void


Joined: 05 Oct 2016
Posts: 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
GameCodingNinja


Joined: 29 Aug 2014
Posts: 32
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.

Code:

// 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.