Show Posts

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.


Topics - Polomease

Pages: [1]
1
Bugs / Scaled Blit Problem
« on: March 04, 2011, 07:03:23 am »
I noticed something weird when using a scaled blit to render some UI images to the screen.
It seems that part of the blitted image is repeating even though the src x, Y, Width and Height match the source texture.

At first I thought that the problem was with my code or image and I checked everything I could think of but it all seems to be correct.

I created a fresh Android app using the HelloWorld AE demo from the wiki and I loaded the texture and did a scaled blit to the screen and the problem still occurs.
I changed the background color to white so that it was easier to see the problem.

I have messed around with changing 'src' values but if I make them smaller then the image gets cut off.
And it just doesn't happen with this one image it happens with many different images that I have loaded as textures.
I'm also using raft's TexturePack class and the same thing happens if I blit am image from a packed texture.
It also only seems to happen if I'm scaling a texture up in size and not down in size.

I'm not sure if this is a problem with the jPCT library or something on my end, maybe I'm just missing something.

Here is a screen shot of what is happening:


Here is the source for the texture:


Here is the code I used:
Code: [Select]
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.Camera;
import com.threed.jpct.Config;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Logger;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.TextureManager;
import com.threed.jpct.World;
import com.threed.jpct.util.BitmapHelper;
import com.threed.jpct.util.MemoryHelper;

public class HelloWorld extends Activity {

// 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 RGBColor back = new RGBColor(50, 50, 100);

private float touchTurn = 0;
private float touchTurnUp = 0;

private float xpos = -1;
private float ypos = -1;

private Object3D cube = null;
private int fps = 0;

private Light sun = 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();
}

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 {

private long time = System.currentTimeMillis();
private boolean stop = false;

public MyRenderer() {
}

public void stop() {
stop = true;
}

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(20, 20, 20);

sun = new Light(world);
sun.setIntensity(250, 250, 250);

// Create a texture out of the icon...:-)
Texture texture = new Texture(BitmapHelper.rescale(BitmapHelper.convert(getResources().getDrawable(R.drawable.icon)), 64, 64));
TextureManager.getInstance().addTexture("texture", texture);

Texture turnleft = new Texture(getResources().openRawResource (R.raw.turnleft), true);
TextureManager.getInstance().addTexture("turnleft", turnleft);

cube = Primitives.getCube(10);
cube.calcTextureWrapSpherical();
cube.setTexture("texture");
cube.strip();
cube.build();

world.addObject(cube);

Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 50);
cam.lookAt(cube.getTransformedCenter());

SimpleVector sv = new SimpleVector();
sv.set(cube.getTransformedCenter());
sv.y -= 100;
sv.z -= 100;
sun.setPosition(sv);
MemoryHelper.compact();

if (master == null) {
Logger.log("Saving master Activity!");
master = HelloWorld.this;
}
}
}

public void onSurfaceCreated(GL10 gl, EGLConfig config) {
}

public void onDrawFrame(GL10 gl) {

try {
if (!stop) {
if (touchTurn != 0) {
cube.rotateY(touchTurn);
touchTurn = 0;
}

if (touchTurnUp != 0) {
cube.rotateX(touchTurnUp);
touchTurnUp = 0;
}

fb.clear(RGBColor.WHITE);
world.renderScene(fb);
world.draw(fb);

Texture turnleft = TextureManager.getInstance().getTexture("turnleft");
fb.blit(turnleft, 0, 0, 0, 0, turnleft.getWidth(), turnleft.getHeight(), 128, 128, 100, false, null);


fb.display();


if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
}
fps++;
} else {
if (fb != null) {
fb.dispose();
fb = null;
}
}
} catch (Exception e) {
Logger.log(e, Logger.MESSAGE);
}
}
}
}



2
Support / Overlay Example
« on: January 23, 2011, 09:57:18 am »
Is there an example of how to use the Overlay class anywhere?
I've done a lot of searching and can't find one.

I've been trying to get it to work and I just can't seem to figure it out.

From the java docs it sounds like you can just create an instance of the class and it should take care of itself from there.

Below is a snippet of what I am trying to do in the onSurfaceChanged() event.
Code: [Select]
        private Overlay MapFrame = null;

        @Override
public void onSurfaceChanged(GL10 gl, int w, int h) {

              fb = new FrameBuffer(gl, w, h);
      world = new World();
      world.setAmbientLight(200, 200, 200);
              /* the rest of the initialization code left out for brevity, it just loads a bunch of objects and textures*/

              //"minimapframe" is a known texture in the texture manager
              MapFrame = new Overlay(world, 0, 0, 128, 128, "minimapframe");

              // I've been trying different combinations of this code
              //MapFrame = new Overlay(world, fb, "minimapframe");
              //MapFrame .setSourceCoordinates(0, 0, objTextureManager.getTexture("minimapframe").getWidth(), objTextureManager.getTexture("minimapframe").getHeight());
              //MapFrame .setVisibility(true);
              //MapFrame .setDepth(10.0F); // have tried different values here

         }

From my understanding this should display the "minimapframe" texture in the upper left of the screen.

I am missing something?


3
Support / Partial Screen Rendering
« on: December 18, 2010, 04:21:31 am »

Hello, I'm new to the jPCT-AE framework and I been trying to figure out how to render a 3D scene to only part of the screen.

I would like to have a 3d view port surrounded by a 2d gui and not a 2d gui on top of a 3d scene.

I started with the Hello World demo found on the wiki - http://www.jpct.net/wiki/index.php/Hello_World_for_Android
And i have been trying to get it to render to only a part of the screen but i haven't been successful.

I have been looking through the docs and on this forum but haven't been able to figure out how to do this.

I found these two posts about rendering with different cameras and onto textures but i can't seem to get either one of these methods to work.

How to get a texture from a FrameBuffer
http://www.jpct.net/forum2/index.php/topic,1589.0.html

rearview mirror
http://www.jpct.net/forum2/index.php/topic,682.0.html

any help or "pointing in the right direction" would be appreciated.

Thanks.



Pages: [1]