I made all working (after a lot of attemps). I used setCulling(false) and now the flat ground appears.
Thank you!
Thank you!
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts Menu
package com.android.math_curve;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;
import com.threed.jpct.*;
import com.threed.jpct.util.BitmapHelper;
import com.threed.jpct.util.MemoryHelper;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.graphics.drawable.BitmapDrawable;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.Renderer;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class MathMainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GLSurfaceView 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 renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.math_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
class MyRenderer implements Renderer
{
boolean bCalled = false;
FrameBuffer fb = null;
World world = null;
Light sun = null;
Object3D ground = null;
@Override
public void onDrawFrame(GL10 arg0) {
// TODO Auto-generated method stub
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
}
public void Main3D()
{
world = new World();
world.setAmbientLight(150, 150, 150);
sun = new Light(world);
sun.setIntensity(250, 250, 250);
sun.setPosition(new SimpleVector(50, 20, 50));
ground = new Object3D(100);
TextureMgr.bitmap_as_texture_ex(getApplicationContext(), R.drawable.untitled, TextureManager.getInstance(), "mytexture", 1024, 1024);
int texture_id = TextureManager.getInstance().getTextureID("mytexture");
ground.addTriangle(
new SimpleVector(0, 0, 0),
0,
0,
new SimpleVector(100, 0, 0),
1024,
0,
new SimpleVector(0, 0, 100),
0,
1024,
texture_id);
ground.addTriangle(
new SimpleVector(100, 0, 0),
1024,
0,
new SimpleVector(100, 0, 100),
1024,
1024,
new SimpleVector(0, 0, 100),
0,
1024,
texture_id);
world.addObject(ground);
world.getCamera().setPosition(new SimpleVector(70, 35, 40));
ground.build();
ground.compile();
ground.setOrigin(new SimpleVector(0, 0, 0));
world.getCamera().lookAt(ground.getTransformedCenter());
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
if( fb != null )
fb.dispose();
fb = new FrameBuffer(gl, width, height);
if( !bCalled )
{
bCalled = true;
Main3D();
}
}
@Override
public void onSurfaceCreated(GL10 arg0, EGLConfig arg1) {}
}
}
package com.android.math_curve;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.util.BitmapHelper;
public class TextureMgr {
public static boolean is_2_pow(int n)
{
int x = n;
if( x < 0 ) return false;
while( x % 2 == 0 )
{
x /= 2;
if( x == 1 )
{
return true;
}
}
return false;
}
public static void bitmap_as_texture_ex(Context app_context, int resource_id, TextureManager tm, String texture_name, int w, int h) throws IllegalArgumentException
{
if( TextureMgr.is_2_pow(w) == false || TextureMgr.is_2_pow(h) == false )
{
throw new IllegalArgumentException("FATAL EXCEPTION: width or height of texture is not a power of 2 in TextureMgr.bitmap_as_texture_ex()");
}
Bitmap bmp = TextureMgr.get_bitmap(app_context, resource_id);
if( bmp.getHeight() != h || bmp.getWidth() != w )
{
bmp = BitmapHelper.rescale(bmp, w, h);
}
TextureMgr.add_texture(tm, texture_name, bmp);
}
public static void bitmap_as_texture(Context app_context, int resource_id, TextureManager tm, String texture_name)
{
TextureMgr.add_texture(tm, texture_name, TextureMgr.get_bitmap(app_context, resource_id));
}
@SuppressWarnings("deprecation")
public static Bitmap get_bitmap(Context app_context, int resource_id)
{
return (new BitmapDrawable(app_context.getResources().openRawResource(resource_id))).getBitmap();
}
public static void add_texture(TextureManager tm, String texture_name, Bitmap bmp)
{
tm.addTexture(texture_name, TextureMgr.new_texture(bmp));
}
public static Texture new_texture(Bitmap bmp)
{
return new Texture(bmp);
}
}
Page created in 0.038 seconds with 13 queries.