Skip navigation

battletac_hud_gunmounted_02
I’ve been experimenting with the proper way to put a 2D UI over a 3D scene for a while and I’ve finally gotten it working (using JPCT-AE as the 3D rendering engine)– behold!

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
am = this.getAssets();

ll = new LinearLayout(this);
hsv = new HorizontalScrollView(this);
img = (ImageButton) findViewById(R.id.tux_view);
img2 = new ImageButton(this);
img2.setImageResource(R.drawable.tux);
Logger.log(“onCreate”);

if (master != null) {
copy(master);
}

ui = new View(getApplication());
button = new Button(getApplication());
button.setText(“Hello!”);
//button.draw(canvas)
mGLView = new GLSurfaceView(getApplication());

mGLView.setEGLConfigChooser(new GLSurfaceView.EGLConfigChooser() {
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
// Ensure that we get a 16bit framebuffer. Otherwise, we’ll fall
// back to Pixelflinger on some device (read: Samsung I7500)
int[] attributes = new int[] { EGL10.EGL_DEPTH_SIZE, 16, EGL10.EGL_NONE };
EGLConfig[] configs = new EGLConfig[1];
int[] result = new int[1];
egl.eglChooseConfig(display, attributes, configs, 1, result);
return configs[0];
}
});

renderer = new MyRenderer();
mGLView.setRenderer(renderer);
ll.addView(button);
ll.addView(img2);
hsv.addView(ll);
setContentView(mGLView);
addContentView(hsv, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

}

This overlays 2D button and 2D imagebutton widgets over a 3D GLSurfaceView… awesome!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: