jPCT-AE - a 3d engine for Android > Support
How to draw a simple 2D line onto my jPCT Framebuffer?
EgonOlsen:
Sounds like either a driver or an engine bug. Which OpenGL ES version are you using? 1.1 or 2.0? Can you provide a test case that shows the problem?
HammerNL:
Hi Egon,
Yes of course: Here it is:
--- Code: ---package com.example.line2don3d;
import java.lang.reflect.Field;
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 android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.view.MotionEvent;
import com.threed.jpct.*;
import com.threed.jpct.util.MemoryHelper;
public class HelloWorld extends Activity {
public final static float PI = (float)Math.PI;
public final static SimpleVector XAXIS = new SimpleVector(1,0,0);
public final static SimpleVector YAXIS = new SimpleVector(0,1,0);
public final static SimpleVector ZAXIS = new SimpleVector(0,0,1);
public final static float DEGtoRAD = PI/180;
// Used to handle pause and resume...
private static HelloWorld master = null;
private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;
private World meterWorld = null;
private RGBColor back = new RGBColor(0xaa,0xaa,0xaa);
private float touchTurn = 0;
private float touchTurnUp = 0;
private float xpos = -1;
private float ypos = -1;
private Camera cam = null;
private float camX = 100;
private float camY = 0;
private Camera mCam = null;
private float mCamX = 10;
private float mCamY = 0;
private Polyline fuelLine = null;
private Texture fuelMeter = null;
protected void onCreate(Bundle savedInstanceState) {
Logger.log("onCreate");
if (master != null) {
copy(master);
}
super.onCreate(savedInstanceState);
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);
setContentView(mGLView);
}
@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}
@Override
protected void onStop() {
super.onStop();
}
private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
public boolean onTouchEvent(MotionEvent me) {
if (me.getAction() == MotionEvent.ACTION_DOWN) {
xpos = me.getX();
ypos = me.getY();
return true;
}
if (me.getAction() == MotionEvent.ACTION_UP) {
xpos = -1;
ypos = -1;
touchTurn = 0;
touchTurnUp = 0;
return true;
}
if (me.getAction() == MotionEvent.ACTION_MOVE) {
float xd = me.getX() - xpos;
float yd = me.getY() - ypos;
xpos = me.getX();
ypos = me.getY();
touchTurn = xd / -100f;
touchTurnUp = yd / -100f;
return true;
}
try {
Thread.sleep(15);
} catch (Exception e) {
// No need for this...
}
return super.onTouchEvent(me);
}
protected boolean isFullscreenOpaque() {
return true;
}
class MyRenderer implements GLSurfaceView.Renderer {
public MyRenderer() {
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(gl, w, h);
if (master == null) {
world = new World();
world.setAmbientLight(100, 100, 100);
Light sun = new Light(world);
sun.setIntensity(255,255,255);
sun.setPosition(new SimpleVector(-100,0,50));
cam = world.getCamera();
cam.setPosition(camX,camY,0);
cam.setOrientation(new SimpleVector(-1,0,0),ZAXIS);
Object3D cube = Primitives.getCube(10);
cube.setAdditionalColor(0xff,0xff,0);
cube.setOrigin(SimpleVector.ORIGIN);
cube.build();
world.addObject(cube);
MemoryHelper.compact();
world.compileAllObjects();
meterWorld = new World();
meterWorld.setAmbientLight(100, 100, 100);
mCam = meterWorld.getCamera();
mCam.setPosition(mCamX,mCamY,0);
mCam.setOrientation(new SimpleVector(-1,0,0),ZAXIS);
fuelLine = new Polyline(new SimpleVector[] { new SimpleVector(-20,0,20), new SimpleVector(20,20,20) }, RGBColor.RED);
fuelLine.setWidth(5);
meterWorld.addPolyline(fuelLine);
meterWorld.compileAllObjects();
fuelMeter = new Texture(getResources().openRawResource(R.raw.fuelmeter_256),true);
fuelMeter.setMipmap(false);
if (master == null) {
Logger.log("Saving master Activity!");
master = HelloWorld.this;
}
}
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}
private float fuel = 0;
public void onDrawFrame(GL10 gl) {
if (touchTurn != 0)
{
camY += touchTurn*10;
cam.setPosition(camX,camY,0);
cam.setOrientation(new SimpleVector(-1,0,0),ZAXIS);
touchTurn = 0;
}
if (touchTurnUp != 0)
{
camX += touchTurnUp*10;
cam.setPosition(camX,camY,0);
cam.setOrientation(new SimpleVector(-1,0,0),ZAXIS);
touchTurnUp = 0;
}
fuel += 0.01;
float angle = (-60+fuel*120)*DEGtoRAD;
int x = 200;
int y = 200;
float r = 100;
SimpleVector v1 = Interact2D.reproject2D3DWS(mCam,fb,x,y);
v1.add(new SimpleVector(mCamX,mCamY,0));
SimpleVector v2 = Interact2D.reproject2D3DWS(mCam,fb,(int)(x+Math.sin(angle)*r+0.5),(int)(y-Math.cos(angle)*r+0.5));
v2.add(new SimpleVector(mCamX,mCamY,0));
SimpleVector[] vectors = new SimpleVector[] { v1, v2 };
fuelLine.update(vectors);
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.blit(fuelMeter,0,0,0,0,256,256,200,200,100,false);
meterWorld.renderScene(fb);
meterWorld.draw(fb);
fb.display();
}
}
}
--- End code ---
I have no idea which version of GL I'm using. I'm running this on an Android 2.3.5 and an Android 4.0.3 device.
Hope you can find anything. Tanx!
[attachment deleted by admin]
EgonOlsen:
It's OpenGL ES 1.1 then. BTW: Which version of jPCT-AE are you using?
HammerNL:
I'm using the latest I could find: 1.27
EgonOlsen:
Please try this version, it should fix the problem: http://jpct.de/download/beta/jpct_ae.jar
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version