Main Menu
Menu

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.

Show posts Menu

Messages - idanh

#1
Wow, It WORKED!
I'm posting my code here to help anyone who like to add background from an image that does not comply with the texture factory policy.


Quote

// open the background as input stream
InputStream inputStream = getAssets().open("background.jpg");

// create a bitmap
final Bitmap bitmap = BitmapFactory.decodeStream(inputStream);

// create an NPOT texture
final NPOTTexture npotTexture = new NPOTTexture(bitmap.getWidth(),
            bitmap.getHeight(), RGBColor.BLACK);

// set the effect
npotTexture.setEffect(new ITextureEffect() {

   @Override
   public void init(Texture texture) {
   }

   @Override
   public boolean containsAlpha() {
      return false;
   }

   @Override
   public void apply(int[] dest, int[] source) {
                // we apply the effect, but really all we do is copying the ARGB from the bitmap to "dest"
      bitmap.getPixels(dest, 0, bitmap.getWidth(), 0, 0,
            bitmap.getWidth(), bitmap.getHeight());
   }
});

// apply the effect
npotTexture.applyEffect();

// now render everything..
frameBuffer.clear(..)
frameBuffer.blit(npotTexture, 0, 0, 0, 0,
         bitmap.getWidth(), bitmap.getHeight(),
         FrameBuffer.OPAQUE_BLITTING);

world.renderScene(frameBuffer);
world.draw(frameBuffer);
frameBuffer.display();


Hope it helps. Thanks EgonOlsen for helping to figure this out!
#2
Hi Egon,

I've tried hard to understand and code it myself. I'm using the NPOTTexture class.
Here is what I did:

NPOTTexture npotTexture = new NPOTTexture(130, 130, RGBColor.BLACK);
      try {
         npotTexture.add(new Texture(getAssets().open("background.jpg")), 0);
      } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
      }

But I'm still getting the exception about unsupported texture.
I'm not sure how to load the background.jpg onto the NPOTTexture..

Could you please advise where and what I'm doing wrong?
Thank you for your help
#3
Hi, bumping in case you could help me with NPOT texture :)
i'm looking to start working on it.


thanks
#4
Thank you both KittenKoder and EgonOlsen.
About rotations - thanks for those points. I'm going to use them right now.

About NPOT - I'm not exactly sure I understand the concept of all those things.
While I browse the wiki and checking those - any chance you could provide me with a sample or even links to java docs (the alpha version) on where I need to look?
Do I create a regular texture? (wont it throw exception without a special flag?)

Sorry if that's too much, and thanks again for your responses you've been very helpful!

(also- I think I started to get the hang of the camera and move out, if I move the camera out in 50, i have -50/+50 coords to work with- depending on my screen orientation, and about 50/2 to work on the other axis, for example 50 on y and 25 on x, hope I did not get it wrong)

Thanks
#5
EgonOlsen, Thanks for the reply!

About NPOT - Could you please point me on how to use NPOT textures feature? I think that's what I was looking for!

About the object - Thanks for the help. I think I got it. One thing I did not fully understand is why when I load the .obj it loads it where it is upside-down. Meaning - I need to rotate it by PI (180 degrees) to see the face of my object. Is this normal? Or i'm doing something wrong?

The point of the application is to put a 3d object onto a photo - then render it to a picture (which I have no idea how to do currently, as I need to render it to the raw image and should not crop it - or not crop it that much) so I'd love for an advice if possible.

Again, thank you for providing this useful information which I will use
Idan
#6
Hey,

I've just started with 3d but have some knowledge in Java.
My problem which I'm trying to solve (and hopefully you could help me) is:

1. Getting a picture from the library (this step is done, but) putting it as a background image - The problem here is that i'm trying to use the picture as texture - but this requires me to make it power of 2. Is it possible to just use the image as background?

2. Loading a 3d object (this step is done) and moving it around. Here, I can load the object but I dont get why I cant see it. when the origin is 0,0,0. Also, I need to rotate it by PI to rotate to the front. Is this a problem with the camera or the object it self? And also - Why is 0,0,0 or 0,50,0 does not seems to display anything? (my frame buffer is created in onSurfaceChanged(GL10 gl, int w, int h) and using w,h as params)

Hopefully you could see what i'm thinking/doing wrong here and give me some tips.
I've got some code done, but I cant overcome those problems.


Thank you!