@Override
public void create() {
rotationSpeed = 0.5f;
mesh = new Mesh(true, 4, 6,
new VertexAttribute(VertexAttributes.Usage.Position, 3,"attr_Position"),
new VertexAttribute(Usage.TextureCoordinates, 2, "attr_texCoords"));
texture = new Texture(Gdx.files.internal("data/Jellyfish.jpg"));
mesh.setVertices(new float[] {
-1024f, -1024f, 0, 0, 1,
1024f, -1024f, 0, 1, 1,
1024f, 1024f, 0, 1, 0,
-1024f, 1024f, 0, 0, 0
});
mesh.setIndices(new short[] { 0, 1, 2, 2, 3, 0 });
cam = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
xScale = Gdx.graphics.getWidth()/(float)TARGET_WIDTH;
yScale = Gdx.graphics.getHeight()/(float)TARGET_HEIGHT;
font = loadBitmapFont("default.fnt", "default.png");
scale = Math.min(xScale, yScale);
cam.zoom = 1/scale;
// cam.project(start_position);
cam.position.set(0, 0, 0);
batch = new SpriteBatch();
}
java类com.badlogic.gdx.graphics.VertexAttributes.Usage的实例源码
TestCamera.java 文件源码
项目:GDX-Engine
阅读 20
收藏 0
点赞 0
评论 0
ShaderEffect.java 文件源码
项目:gdx-gfx
阅读 19
收藏 0
点赞 0
评论 0
/**
* Instantiates a new ShaderEffect. The ShaderEffect will NOT own shader
* program, so it will not dispose it either!
*
* @param program
* the ShaderProgram to use for this effect
*/
public ShaderEffect(ShaderProgram program) {
this.program = program;
if (meshRefCount++ <= 0) {
mesh = new Mesh(VertexDataType.VertexArray, true, 4, 0,
new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE),
new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
// @formatter:off
float[] verts = {
// vertex texture
-1, -1, 0f, 0f,
1, -1, 1f, 0f,
1, 1, 1f, 1f,
-1, 1, 0f, 1f,
};
// @formatter:on
mesh.setVertices(verts);
}
}
StrategyGame.java 文件源码
项目:Planetbase
阅读 17
收藏 0
点赞 0
评论 0
@Deprecated //Only for creating the first one
private void createEntity(float f, float g, float h) {
Vector3 position=new Vector3(f,g,h);
List<EntityStatic> collidingEntities=space.getWithin(position, 0.03);
if(collidingEntities.size() == 0) {
EntityStatic entity=new EntityStatic(new ModelInstance(
Assets.modelBuilder.createBox(0.03f, 0.03f, 0.06f,
new Material(StrategyGame.blueAttr),
Usage.Normal | Usage.Position)),
position);
space.addEntity(entity);
} else {
for(EntityStatic e:collidingEntities){
e.damage(2);
}
}
}
PositionalLight.java 文件源码
项目:fabulae
阅读 19
收藏 0
点赞 0
评论 0
public PositionalLight (RayHandler rayHandler, int rays, Color color, float distance, float x, float y, float directionDegree) {
super(rayHandler, rays, color, directionDegree, distance);
start.x = x;
start.y = y;
sin = new float[rays];
cos = new float[rays];
endX = new float[rays];
endY = new float[rays];
lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0, new VertexAttribute(Usage.Position, 2,
"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0, new VertexAttribute(Usage.Position, 2,
"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
setMesh();
}
DirectionalLight.java 文件源码
项目:fabulae
阅读 18
收藏 0
点赞 0
评论 0
/** Directional lights simulate light source that locations is at infinite distance. Direction and intensity is same everywhere.
* -90 direction is straight from up.
*
* @param rayHandler
* @param rays
* @param color
* @param directionDegree */
public DirectionalLight (RayHandler rayHandler, int rays, Color color, float directionDegree) {
super(rayHandler, rays, color, directionDegree, Float.POSITIVE_INFINITY);
vertexNum = (vertexNum - 1) * 2;
start = new Vector2[rayNum];
end = new Vector2[rayNum];
for (int i = 0; i < rayNum; i++) {
start[i] = new Vector2();
end[i] = new Vector2();
}
setDirection(direction);
lightMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2,
"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
softShadowMesh = new Mesh(VertexDataType.VertexArray, staticLight, vertexNum, 0, new VertexAttribute(Usage.Position, 2,
"vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
update();
}
RavChainLight.java 文件源码
项目:RavTech
阅读 19
收藏 0
点赞 0
评论 0
/** Creates chain light from specified vertices
*
* @param rayHandler not {@code null} instance of RayHandler
* @param rays number of rays - more rays make light to look more realistic but will decrease performance, can't be less than
* MIN_RAYS
* @param color color, set to {@code null} to use the default color
* @param distance distance of light
* @param rayDirection direction of rays
* <ul>
* <li>1 = left</li>
* <li>-1 = right</li>
* </ul>
* @param chain float array of (x, y) vertices from which rays will be evenly distributed */
public RavChainLight (RayHandler rayHandler, int rays, Color color, float distance, int rayDirection, float[] chain) {
super(rayHandler, rays, color, distance, 0f);
rayStartOffset = ChainLight.defaultRayStartOffset;
this.rayDirection = rayDirection;
vertexNum = (vertexNum - 1) * 2;
endX = new float[rays];
endY = new float[rays];
startX = new float[rays];
startY = new float[rays];
this.chain = (chain != null) ? new FloatArray(chain) : new FloatArray();
lightMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum, 0,
new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
softShadowMesh = new Mesh(VertexDataType.VertexArray, false, vertexNum * 2, 0,
new VertexAttribute(Usage.Position, 2, "vertex_positions"), new VertexAttribute(Usage.ColorPacked, 4, "quad_colors"),
new VertexAttribute(Usage.Generic, 1, "s"));
setMesh();
}
UsefulMeshs.java 文件源码
项目:Mundus
阅读 18
收藏 0
点赞 0
评论 0
public static Model createAxes() {
final float GRID_MIN = -10f;
final float GRID_MAX = 10f;
final float GRID_STEP = 1f;
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES,
VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material());
builder.setColor(Color.LIGHT_GRAY);
for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
}
builder = modelBuilder.part("axes", GL20.GL_LINES,
VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorUnpacked, new Material());
builder.setColor(Color.RED);
builder.line(0, 0, 0, 100, 0, 0);
builder.setColor(Color.GREEN);
builder.line(0, 0, 0, 0, 100, 0);
builder.setColor(Color.BLUE);
builder.line(0, 0, 0, 0, 0, 100);
return modelBuilder.end();
}
DepthShader.java 文件源码
项目:libgdxcn
阅读 21
收藏 0
点赞 0
评论 0
@Override
public boolean canRender (Renderable renderable) {
if (renderable.material.has(BlendingAttribute.Type)) {
if ((materialMask & BlendingAttribute.Type) != BlendingAttribute.Type)
return false;
if (renderable.material.has(TextureAttribute.Diffuse) != ((materialMask & TextureAttribute.Diffuse) == TextureAttribute.Diffuse))
return false;
}
final boolean skinned = ((renderable.mesh.getVertexAttributes().getMask() & Usage.BoneWeight) == Usage.BoneWeight);
if (skinned != (numBones > 0)) return false;
if (!skinned) return true;
int w = 0;
final int n = renderable.mesh.getVertexAttributes().size();
for (int i = 0; i < n; i++) {
final VertexAttribute attr = renderable.mesh.getVertexAttributes().get(i);
if (attr.usage == Usage.BoneWeight) w |= (1 << attr.unit);
}
return w == weights;
}
MeshBuilder.java 文件源码
项目:libgdxcn
阅读 20
收藏 0
点赞 0
评论 0
/** @param usage bitwise mask of the {@link com.badlogic.gdx.graphics.VertexAttributes.Usage}, only Position, Color, Normal and
* TextureCoordinates is supported. */
public static VertexAttributes createAttributes (long usage) {
final Array<VertexAttribute> attrs = new Array<VertexAttribute>();
if ((usage & Usage.Position) == Usage.Position)
attrs.add(new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE));
if ((usage & Usage.Color) == Usage.Color) attrs.add(new VertexAttribute(Usage.Color, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.ColorPacked) == Usage.ColorPacked)
attrs.add(new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE));
if ((usage & Usage.Normal) == Usage.Normal)
attrs.add(new VertexAttribute(Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
if ((usage & Usage.TextureCoordinates) == Usage.TextureCoordinates)
attrs.add(new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
final VertexAttribute attributes[] = new VertexAttribute[attrs.size];
for (int i = 0; i < attributes.length; i++)
attributes[i] = attrs.get(i);
return new VertexAttributes(attributes);
}
UnweightedMeshSpawnShapeValue.java 文件源码
项目:libgdxcn
阅读 19
收藏 0
点赞 0
评论 0
@Override
public void setMesh(Mesh mesh, Model model){
super.setMesh(mesh, model);
vertexSize = mesh.getVertexSize()/4;
positionOffset = mesh.getVertexAttribute(Usage.Position).offset/4;
int indicesCount = mesh.getNumIndices();
if(indicesCount >0){
indices = new short[indicesCount];
mesh.getIndices(indices);
triangleCount = indices.length/3;
}
else indices = null;
vertexCount = mesh.getNumVertices();
vertices = new float[ vertexCount* vertexSize];
mesh.getVertices(vertices);
}
FogTest.java 文件源码
项目:amatsukaze
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void create () {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(30f, 10f, 30f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 45f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position
| Usage.Normal);
instance = new ModelInstance(model);
Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
PolygonSpriteBatch.java 文件源码
项目:libgdxcn
阅读 18
收藏 0
点赞 0
评论 0
/** Constructs a new PolygonSpriteBatch. Sets the projection matrix to an orthographic projection with y-axis point upwards,
* x-axis point to the right and the origin being in the bottom left corner of the screen. The projection will be pixel perfect
* with respect to the current screen resolution.
* <p>
* The defaultShader specifies the shader to use. Note that the names for uniforms for this default shader are different than
* the ones expect for shaders set with {@link #setShader(ShaderProgram)}. See {@link SpriteBatch#createDefaultShader()}.
* @param size The max number of vertices and number of triangles in a single batch. Max of 10920.
* @param defaultShader The default shader to use. This is not owned by the PolygonSpriteBatch and must be disposed separately. */
public PolygonSpriteBatch (int size, ShaderProgram defaultShader) {
// 32767 is max index, so 32767 / 3 - (32767 / 3 % 3) = 10920.
if (size > 10920) throw new IllegalArgumentException("Can't have more than 10920 triangles per batch: " + size);
mesh = new Mesh(VertexDataType.VertexArray, false, size, size * 3, new VertexAttribute(Usage.Position, 2,
ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE),
new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
vertices = new float[size * VERTEX_SIZE];
triangles = new short[size * 3];
if (defaultShader == null) {
shader = SpriteBatch.createDefaultShader();
ownsShader = true;
} else
shader = defaultShader;
projectionMatrix.setToOrtho2D(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
}
ShaderTest.java 文件源码
项目:amatsukaze
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void create () {
modelBatch = new ModelBatch(new BaseShaderProvider() {
@Override
protected Shader createShader (Renderable renderable) {
return new TestShader();
}
});
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
Material material = new Material(new TestAttribute(1f));
ModelBuilder builder = new ModelBuilder();
model = builder.createCone(5, 5, 5, 20, material, Usage.Position);
instance = new ModelInstance(model);
testAttribute = (TestAttribute)instance.materials.get(0).get(TestAttribute.ID);
}
Basic3DTest.java 文件源码
项目:amatsukaze
阅读 19
收藏 0
点赞 0
评论 0
@Override
public void create () {
modelBatch = new ModelBatch(new DefaultShaderProvider());
// modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position
| Usage.Normal);
instance = new ModelInstance(model);
// model = new G3dModelLoader(new UBJsonReader()).loadModel(Gdx.files.internal("data/g3d/knight.g3db"));
// instance = new ModelInstance(model);
Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
Basic3D.java 文件源码
项目:amatsukaze
阅读 22
收藏 0
点赞 0
评论 0
@Override
public void create() {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f,
new Material(ColorAttribute.createDiffuse(Color.GREEN)),
Usage.Position | Usage.Normal);
instance = new ModelInstance(model);
}
ShaderTest.java 文件源码
项目:libgdxcn
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void create () {
modelBatch = new ModelBatch(new BaseShaderProvider() {
@Override
protected Shader createShader (Renderable renderable) {
return new TestShader();
}
});
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
camController = new CameraInputController(cam);
Gdx.input.setInputProcessor(camController);
Material material = new Material(new TestAttribute(1f));
ModelBuilder builder = new ModelBuilder();
model = builder.createCone(5, 5, 5, 20, material, Usage.Position);
instance = new ModelInstance(model);
testAttribute = (TestAttribute)instance.materials.get(0).get(TestAttribute.ID);
}
FogTest.java 文件源码
项目:libgdxcn
阅读 17
收藏 0
点赞 0
评论 0
@Override
public void create () {
modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1.f));
environment.set(new ColorAttribute(ColorAttribute.Fog, 0.13f, 0.13f, 0.13f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(30f, 10f, 30f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 45f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position
| Usage.Normal);
instance = new ModelInstance(model);
Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
BaseG3dTest.java 文件源码
项目:libgdxcn
阅读 19
收藏 0
点赞 0
评论 0
private void createAxes () {
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
builder.setColor(Color.LIGHT_GRAY);
for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
}
builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
builder.setColor(Color.RED);
builder.line(0, 0, 0, 100, 0, 0);
builder.setColor(Color.GREEN);
builder.line(0, 0, 0, 0, 100, 0);
builder.setColor(Color.BLUE);
builder.line(0, 0, 0, 0, 0, 100);
axesModel = modelBuilder.end();
axesInstance = new ModelInstance(axesModel);
}
Basic3DTest.java 文件源码
项目:libgdxcn
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void create () {
modelBatch = new ModelBatch(new DefaultShaderProvider());
// modelBatch = new ModelBatch();
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, .4f, .4f, .4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(10f, 10f, 10f);
cam.lookAt(0, 0, 0);
cam.near = 0.1f;
cam.far = 300f;
cam.update();
ModelBuilder modelBuilder = new ModelBuilder();
model = modelBuilder.createBox(5f, 5f, 5f, new Material(ColorAttribute.createDiffuse(Color.GREEN)), Usage.Position
| Usage.Normal);
instance = new ModelInstance(model);
// model = new G3dModelLoader(new UBJsonReader()).loadModel(Gdx.files.internal("data/g3d/knight.g3db"));
// instance = new ModelInstance(model);
Gdx.input.setInputProcessor(new InputMultiplexer(this, inputController = new CameraInputController(cam)));
}
ProjectiveTextureTest.java 文件源码
项目:libgdxcn
阅读 19
收藏 0
点赞 0
评论 0
public void setupScene () {
plane = new Mesh(true, 4, 6, new VertexAttribute(Usage.Position, 3, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(
Usage.Normal, 3, ShaderProgram.NORMAL_ATTRIBUTE));
plane.setVertices(new float[] {-10, -1, 10, 0, 1, 0, 10, -1, 10, 0, 1, 0, 10, -1, -10, 0, 1, 0, -10, -1, -10, 0, 1, 0});
plane.setIndices(new short[] {3, 2, 1, 1, 0, 3});
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"), Format.RGB565, true);
texture.setFilter(TextureFilter.MipMap, TextureFilter.Nearest);
cam = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam.position.set(0, 5, 10);
cam.lookAt(0, 0, 0);
cam.update();
controller = new PerspectiveCamController(cam);
projector = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
projector.position.set(2, 3, 2);
projector.lookAt(0, 0, 0);
projector.normalizeUp();
projector.update();
}
FrameBufferTest.java 文件源码
项目:libgdxcn
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void create () {
mesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(Usage.ColorPacked, 4,
"a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
float c1 = Color.toFloatBits(255, 0, 0, 255);
float c2 = Color.toFloatBits(255, 0, 0, 255);
float c3 = Color.toFloatBits(0, 0, 255, 255);
mesh.setVertices(new float[] {-0.5f, -0.5f, 0, c1, 0, 0, 0.5f, -0.5f, 0, c2, 1, 0, 0, 0.5f, 0, c3, 0.5f, 1});
stencilMesh = new Mesh(true, 3, 0, new VertexAttribute(Usage.Position, 3, "a_Position"), new VertexAttribute(
Usage.ColorPacked, 4, "a_Color"), new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoords"));
stencilMesh.setVertices(new float[] {-0.5f, 0.5f, 0, c1, 0, 0, 0.5f, 0.5f, 0, c2, 1, 0, 0, -0.5f, 0, c3, 0.5f, 1});
texture = new Texture(Gdx.files.internal("data/badlogic.jpg"));
spriteBatch = new SpriteBatch();
frameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false);
stencilFrameBuffer = new FrameBuffer(Format.RGB565, 128, 128, false, true);
createShader(Gdx.graphics);
}
CullTest.java 文件源码
项目:libgdxcn
阅读 16
收藏 0
点赞 0
评论 0
@Override
public void create () {
ModelBuilder builder = new ModelBuilder();
sphere = builder.createSphere(2f, 2f, 2f, 16, 16, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.WHITE)),
Usage.Position | Usage.Normal);
// cam = new PerspectiveCamera(45, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
cam = new OrthographicCamera(45, 45 * (Gdx.graphics.getWidth() / (float)Gdx.graphics.getHeight()));
cam.near = 1;
cam.far = 200;
Random rand = new Random();
for (int i = 0; i < instances.length; i++) {
pos.set(rand.nextFloat() * 100 - rand.nextFloat() * 100, rand.nextFloat() * 100 - rand.nextFloat() * 100,
rand.nextFloat() * -100 - 3);
instances[i] = new ModelInstance(sphere, pos);
}
modelBatch = new ModelBatch();
batch = new SpriteBatch();
font = new BitmapFont();
// Gdx.graphics.setVSync(true);
// Gdx.app.log("CullTest", "" + Gdx.graphics.getBufferFormat().toString());
}
BaseG3dTest.java 文件源码
项目:amatsukaze
阅读 17
收藏 0
点赞 0
评论 0
private void createAxes () {
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
builder.setColor(Color.LIGHT_GRAY);
for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
}
builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
builder.setColor(Color.RED);
builder.line(0, 0, 0, 100, 0, 0);
builder.setColor(Color.GREEN);
builder.line(0, 0, 0, 0, 100, 0);
builder.setColor(Color.BLUE);
builder.line(0, 0, 0, 0, 0, 100);
axesModel = modelBuilder.end();
axesInstance = new ModelInstance(axesModel);
}
AxisModelGenerator.java 文件源码
项目:amatsukaze
阅读 17
收藏 0
点赞 0
评论 0
public ModelInstance createAxes () {
ModelBuilder modelBuilder = new ModelBuilder();
modelBuilder.begin();
MeshPartBuilder builder = modelBuilder.part("grid", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
builder.setColor(Color.LIGHT_GRAY);
for (float t = GRID_MIN; t <= GRID_MAX; t += GRID_STEP) {
builder.line(t, 0, GRID_MIN, t, 0, GRID_MAX);
builder.line(GRID_MIN, 0, t, GRID_MAX, 0, t);
}
builder = modelBuilder.part("axes", GL20.GL_LINES, Usage.Position | Usage.Color, new Material());
builder.setColor(Color.RED);
builder.line(0, 0, 0, 100, 0, 0);
builder.setColor(Color.GREEN);
builder.line(0, 0, 0, 0, 100, 0);
builder.setColor(Color.BLUE);
builder.line(0, 0, 0, 0, 0, 100);
Model axesModel = modelBuilder.end();
ModelInstance axesInstance = new ModelInstance(axesModel);
return axesInstance;
}
Renderer20.java 文件源码
项目:fluid-simulator-v2
阅读 21
收藏 0
点赞 0
评论 0
public Renderer20 (int maxVertices, boolean hasNormals, boolean hasColors, int numTexCoords, ShaderProgram shader) {
this.maxVertices = maxVertices;
this.numTexCoords = numTexCoords;
this.shader = shader;
VertexAttribute[] attribs = buildVertexAttributes(hasNormals, hasColors, numTexCoords);
mesh = new Mesh(false, maxVertices, 0, attribs);
vertices = new float[maxVertices * (mesh.getVertexAttributes().vertexSize / 4)];
vertexSize = mesh.getVertexAttributes().vertexSize / 4;
normalOffset = mesh.getVertexAttribute(Usage.Normal) != null ? mesh.getVertexAttribute(Usage.Normal).offset / 4 : 0;
colorOffset = mesh.getVertexAttribute(Usage.ColorPacked) != null ? mesh.getVertexAttribute(Usage.ColorPacked).offset / 4
: 0;
texCoordOffset = mesh.getVertexAttribute(Usage.TextureCoordinates) != null ? mesh
.getVertexAttribute(Usage.TextureCoordinates).offset / 4 : 0;
}
Game3d.java 文件源码
项目:GdxStudio
阅读 21
收藏 0
点赞 0
评论 0
public Game3d(){
ship = Asset.loadModelObj("ship");//loads an obj model
ship.scale(3f);
skydome = Asset.loadModel("skydome"); //loads a g3db model
builder = new ModelBuilder();
builder.begin();
MeshPartBuilder part = builder.part("floor", GL20.GL_TRIANGLES, Usage.Position |
Usage.TextureCoordinates | Usage.Normal, new Material());
for (float x = -200f; x < 200f; x += 10f) {
for (float z = -200f; z < 200f; z += 10f) {
part.rect(x, 0, z + 10f, x + 10f, 0, z + 10f, x + 10f, 0, z, x, 0, z, 0, 1, 0);
}
}
floor = new Actor3d(builder.end());
floor.materials.get(0).set(TextureAttribute.createDiffuse(Asset.tex("concrete").getTexture()));
knight = Asset.loadModel("knight");
knight.setPosition(-20f, 18f, 0f);
knight.setPitch(-90f);
addActor3d(floor);
addActor3d(skydome);
addActor3d(ship);
addActor3d(knight);
stage3d.getCamera().position.set(knight.getX()+ 13f, knight.getY() + 24f, knight.getZ() + 45f);
//Camera3d.followOffset(20f, 20f, -20f);
// Camera3d.followActor3d(knight, false);
}
SimpleRoom.java 文件源码
项目:gdx-vr
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void create() {
assets = new AssetManager();
String model = "Bambo_House.g3db";
assets.load(model, Model.class);
assets.finishLoading();
modelInstance = new ModelInstance(assets.get(model, Model.class), new Matrix4().setToScaling(0.6f, 0.6f, 0.6f));
DefaultShader.Config config = new Config();
config.defaultCullFace = GL20.GL_NONE;
ShaderProvider shaderProvider = new DefaultShaderProvider(config);
modelBatch = new ModelBatch(shaderProvider);
ModelBuilder builder = new ModelBuilder();
float groundSize = 1000f;
ground = new ModelInstance(builder.createRect(-groundSize, 0, groundSize, groundSize, 0, groundSize, groundSize, 0, -groundSize, -groundSize, 0, -groundSize, 0,
1, 0, new Material(), Usage.Position | Usage.Normal), new Matrix4().setToTranslation(0, -0.01f, 0));
environment = new Environment();
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.4f, 0.4f, 0.4f, 1f));
environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f));
VirtualReality.renderer.listeners.add(this);
// VirtualReality.head.setCyclops(true);
}
LibraryTest.java 文件源码
项目:libgdx-opencl
阅读 18
收藏 0
点赞 0
评论 0
@Override
public void create ()
{
// Init camera
this.camera = new PerspectiveCamera(70, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
this.camera.position.set(0,0,-20);
this.camera.lookAt(0,0,0);
this.camera.near = 0.05f;
this.camera.far = 600.0f;
this.camera.update();
// Init test shader
this.testShader = ShaderLoader.loadShader("test");
// Init test buffer
this.testBufferObject = new DynamicVertexBufferObject(3, new VertexAttributes(new VertexAttribute(Usage.Position, 4, "a_position")));
float[] vertices = new float[]
{
-10,0,0,1,0,2.5f,0,1,10,0,0,1
};
this.testBufferObject.setVertices(vertices, 0, vertices.length);
}
BillboardStarRenderSystem.java 文件源码
项目:gaiasky
阅读 25
收藏 0
点赞 0
评论 0
private void init(String tex0, float w, float h) {
setTexture0(tex0);
// Init comparator
comp = new DistToCameraComparator<IRenderable>();
// Init vertices
float[] vertices = new float[20];
fillVertices(vertices, w, h);
// We wont need indices if we use GL_TRIANGLE_FAN to draw our quad
// TRIANGLE_FAN will draw the verts in this order: 0, 1, 2; 0, 2, 3
mesh = new Mesh(VertexDataType.VertexArray, true, 4, 6, new VertexAttribute(Usage.Position, 2, ShaderProgram.POSITION_ATTRIBUTE), new VertexAttribute(Usage.ColorPacked, 4, ShaderProgram.COLOR_ATTRIBUTE), new VertexAttribute(Usage.TextureCoordinates, 2, ShaderProgram.TEXCOORD_ATTRIBUTE + "0"));
mesh.setVertices(vertices, 0, vertices.length);
mesh.getIndicesBuffer().position(0);
mesh.getIndicesBuffer().limit(6);
short[] indices = new short[] { 0, 1, 2, 0, 2, 3 };
mesh.setIndices(indices);
quaternion = new Quaternion();
aux = new Vector3();
}
LineRenderSystem.java 文件源码
项目:gaiasky
阅读 18
收藏 0
点赞 0
评论 0
@Override
protected void initVertices() {
meshes = new MeshData[2];
maxVertices = MAX_VERTICES;
// ORIGINAL LINES
curr = new MeshData();
meshes[0] = curr;
VertexAttribute[] attribs = buildVertexAttributes();
curr.mesh = new Mesh(false, maxVertices, 0, attribs);
curr.vertices = new float[maxVertices * (curr.mesh.getVertexAttributes().vertexSize / 4)];
curr.vertexSize = curr.mesh.getVertexAttributes().vertexSize / 4;
curr.colorOffset = curr.mesh.getVertexAttribute(Usage.ColorPacked) != null ? curr.mesh.getVertexAttribute(Usage.ColorPacked).offset / 4 : 0;
}