return getValues(out, color.r, color.g, color.b, color.a);
}
+ private Color tmpC = new Color();
@Override
public void render (final Renderable renderable) {
+ tmpC.set(1,1,1,1);
+ boolean hasColor = false;
if (currentMaterial != renderable.material) {
currentMaterial = renderable.material;
if (!currentMaterial.has(BlendingAttribute.Type))
Gdx.gl10.glDisable(GL10.GL_TEXTURE_2D);
int cullFace = defaultCullFace;
for (final Attribute attribute : currentMaterial) {
- if (attribute.type == BlendingAttribute.Type)
+ if (attribute.type == BlendingAttribute.Type) {
context.setBlending(true, ((BlendingAttribute)attribute).sourceFunction, ((BlendingAttribute)attribute).destFunction);
+ hasColor = true;
+ tmpC.a = ((BlendingAttribute)attribute).opacity;
+ }
else if (attribute.type == ColorAttribute.Diffuse) {
- Gdx.gl10.glColor4f(((ColorAttribute)attribute).color.r, ((ColorAttribute)attribute).color.g, ((ColorAttribute)attribute).color.b, ((ColorAttribute)attribute).color.a);
- if (renderable.environment != null) {
- Gdx.gl10.glEnable(GL10.GL_COLOR_MATERIAL);
- Gdx.gl10.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, getValues(lightVal, ((ColorAttribute)attribute).color), 0);
- Gdx.gl10.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, getValues(lightVal, ((ColorAttribute)attribute).color), 0);
- }
+ float a = tmpC.a;
+ tmpC.set(((ColorAttribute)attribute).color);
+ tmpC.a = a;
+ hasColor = true;
} else if (attribute.type == TextureAttribute.Diffuse) {
TextureDescriptor textureDesc = ((TextureAttribute)attribute).textureDescription;
if (currentTexture0 != textureDesc.texture)
}
context.setCullFace(cullFace);
}
+ if (hasColor) {
+ Gdx.gl10.glColor4f(tmpC.r, tmpC.g, tmpC.b, tmpC.a);
+ if (renderable.environment != null) {
+ Gdx.gl10.glEnable(GL10.GL_COLOR_MATERIAL);
+ Gdx.gl10.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_AMBIENT, getValues(lightVal, tmpC), 0);
+ Gdx.gl10.glMaterialfv(GL10.GL_FRONT_AND_BACK, GL10.GL_DIFFUSE, getValues(lightVal, tmpC), 0);
+ }
+ }
if (currentTransform != renderable.worldTransform) { // FIXME mul localtransform
if (currentTransform != null)
Gdx.gl10.glPopMatrix();
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
import com.badlogic.gdx.graphics.g3d.attributes.TextureAttribute;
import com.badlogic.gdx.graphics.g3d.loader.ObjLoader;
+import com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder;
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
import com.badlogic.gdx.math.MathUtils;
import com.badlogic.gdx.math.Vector3;
float angleY = 0;
- Model model;
+ Model model, backModel;
ModelInstance modelInstance;
+ ModelInstance background;
ModelBatch modelBatch;
TextureAttribute textureAttribute;
public void create () {
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), true);
+ // Create material attributes. Each material can contain x-number of attributes.
+ textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture);
+ colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE);
+ blendingAttribute = new BlendingAttribute(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
+
+
ModelBuilder builder = new ModelBuilder();
model = builder.createBox(1, 1, 1, new Material(), Usage.Position | Usage.Normal | Usage.TextureCoordinates);
model.manageDisposable(texture);
modelInstance = new ModelInstance(model);
+ modelInstance.transform.rotate(Vector3.X, 45);
- // Create material attributes. Each material can contain x-number of attributes.
- textureAttribute = new TextureAttribute(TextureAttribute.Diffuse, texture);
- colorAttribute = new ColorAttribute(ColorAttribute.Diffuse, Color.ORANGE);
- blendingAttribute = new BlendingAttribute(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
-
material = modelInstance.materials.get(0);
+ builder.begin();
+ MeshPartBuilder mpb = builder.part("back", GL10.GL_TRIANGLES,
+ Usage.Position | Usage.TextureCoordinates, new Material(textureAttribute));
+ mpb.rect(-2, -2, -2, 2, -2, -2, 2, 2, -2, -2, 2, -2, 0, 0, 1);
+ backModel = builder.end();
+ background = new ModelInstance(backModel);
+
modelBatch = new ModelBatch();
camera = new PerspectiveCamera(45, 4, 4);
- camera.position.set(3, 3, 3);
- camera.direction.set(-1, -1, -1);
+ camera.position.set(0, 0, 3);
+ camera.direction.set(0, 0, -1);
+ camera.update();
Gdx.input.setInputProcessor(this);
}
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
-
- camera.update();
modelInstance.transform.rotate(Vector3.Y, 30 * Gdx.graphics.getDeltaTime());
modelBatch.begin(camera);
+ modelBatch.render(background);
modelBatch.render(modelInstance);
modelBatch.end();
}
@Override
public void dispose () {
model.dispose();
+ backModel.dispose();
modelBatch.dispose();
}
@Override
public boolean needsGL20 () {
- return true;
+ return false;
}
}
\ No newline at end of file