Giter VIP home page Giter VIP logo

Comments (15)

DannyDan avatar DannyDan commented on June 7, 2024

Hmmm.

It seems that this is not the right function to change the texture on a model. Now I'm setting the material instead of adding a texture, and it works.

Danny

from rajawali.

DannyDan avatar DannyDan commented on June 7, 2024

Sorry to bring this up again, but is this really the right method to change the texture on a model? What is the normal workflow for that?
I change the material in the onDrawFrame method to change it rapiditly but it only changes once.

Danny

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

This is the right way to do this:

mTextureManager.updateTexture(texInfo.getTextureId(), myNewBitmap);

from rajawali.

markdeaton avatar markdeaton commented on June 7, 2024

I had the same question as DD above. I apologize for having a discussion in a bug log--I'm new to GitHub (and Rajawali and OpenGL). If there's a better place to talk about this, please direct me there.

I am able to overlay a world image on a sphere using addTexture, with a fine result:
http://i1254.photobucket.com/albums/hh618/CatCarson84/sphere-imagery.png
Or I can overlay a different image instead, in the same way, with a fine result:
http://i1254.photobucket.com/albums/hh618/CatCarson84/sphere-gray.png

But if I add the first image, then call updateTexture with the second image, I get a weird mishmash of the two:
http://i1254.photobucket.com/albums/hh618/CatCarson84/sphere-hybrid.png

My renderer code (snippet from initScene()) is:

    mLight = new DirectionalLight(1f, 0.2f, 1.0f); // set the direction
    mLight.setColor(1.0f, 1.0f, 1.0f);
    mLight.setPower(1.0f);

// createBasemapSpheres();
mBasemapSphere = new Sphere(1.0f, 40, 40);
mBasemapSphere.setTransparent(false);

    DiffuseMaterial dm = new DiffuseMaterial();
    mBasemapSphere.setMaterial(dm);
    mBasemapSphere.addLight(mLight);
    Bitmap bg = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.world_imagery_2048);
    TextureInfo mBasemapTextureInfo = mTextureManager.addTexture(bg);
    mBasemapSphere.addTexture(mBasemapTextureInfo);
    addChild(mBasemapSphere);

    Bitmap bg2 = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.canvas_gray_2048);
    mTextureManager.updateTexture(mBasemapTextureInfo.getTextureId(), bg2);

from rajawali.

DannyDan avatar DannyDan commented on June 7, 2024

Thanks Dennis for your response.

Ive added

mTextureManager.updateTexture(texInfo[i].getTextureId(), tex[i]);

to my onDrawFrame fkt. and now it cycles through the images mapped on the cube.

@markdeaton
Try using a material and map the material to your object.

Danny

from rajawali.

markdeaton avatar markdeaton commented on June 7, 2024

Sorry again if this is the wrong place for a follow-up; it doesn't seem right to open a new issue for it. I attempted to set up multiple materials, each with its own texture; but there's something strange going on in the addTexture() routines that causes the textures to trample on one another and ultimately crash the app after about 7 material changes.

But I revisited my original approach (above), and found that everything works, providing I pass in the mipmap=false flag when I call mTextureManager.addTexture() on the one material I'm now using.

from rajawali.

 avatar commented on June 7, 2024

mTextureManager.updateTexture(Models[0].model.getTextureInfoList().get(0).getTextureId(), mTextureBrown);

I tried this but not working.

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

I've just committed a fix for this. Updating texture didn't work for mipmapped textures. I've deprecated the old method. The new method has a slightly different signature:

public void updateTexture(TextureInfo textureInfo, Bitmap texture) { ...

from rajawali.

markdeaton avatar markdeaton commented on June 7, 2024

Thanks, Dennis!

from rajawali.

 avatar commented on June 7, 2024

its now working, but the textureCoords not the some..the texture just slipping on the object...why?

from rajawali.

 avatar commented on June 7, 2024
public void updateTexture(TextureInfo textureInfo, Bitmap texture) {
    int bitmapFormat = texture.getConfig() == Config.ARGB_8888 ? GLES20.GL_RGBA : GLES20.GL_RGB;
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureInfo.getTextureId());

    if (textureInfo.isMipmap())
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR_MIPMAP_LINEAR);
    else
        GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);

    GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_REPEAT);
    GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_REPEAT);
    GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapFormat, texture, 0);

    if (textureInfo.isMipmap()) GLES20.glGenerateMipmap(GLES20.GL_TEXTURE_2D);
    textureInfo.setTexture(texture);

    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
}

here is the working code, BUT when I have 4-5 objects (clones), and when I am just change one's tetxure, then the all object's texture changes

i am using this code

mTextureManager.updateTexture(model.getTextureInfoList().get(0), mTextureGreen)

0 is the BASE texture
1 is the BUMP right?

from rajawali.

 avatar commented on June 7, 2024

maybe need a function to update only the DIFFUSE or only the BUMP texture on the modell.
at the moment the textures are mixing away

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

Well, it uses the texture id, so there's no need to distinguish between diffuse or bump.

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

Yes, cloned objects share materials. If you don't want a cloned material then you'll have to manually create new materials. Using shaders & textures on mobile devices is a costly operation. That's why materials aren't cloned automatically.

from rajawali.

defHLT avatar defHLT commented on June 7, 2024

I've run in the same problem.

@MasDennis

This is the right way to do this:
mTextureManager.updateTexture(texInfo.getTextureId(), myNewBitmap);

What whould be the way to update a Etc1 texture?
There is addEtc1Texture methods but no suitable updateTexture.

from rajawali.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.