Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.fbsp.tt.main.game;
- import com.badlogic.gdx.ApplicationListener;
- import com.badlogic.gdx.Gdx;
- import com.badlogic.gdx.files.FileHandle;
- import com.badlogic.gdx.graphics.GL20;
- import com.badlogic.gdx.graphics.Mesh;
- import com.badlogic.gdx.graphics.Texture;
- import com.badlogic.gdx.graphics.VertexAttribute;
- import com.badlogic.gdx.graphics.VertexAttributes.Usage;
- import com.badlogic.gdx.graphics.g3d.loaders.obj.ObjLoader;
- import com.badlogic.gdx.graphics.glutils.ShaderProgram;
- import com.badlogic.gdx.math.Matrix4;
- import com.badlogic.gdx.math.Vector3;
- public class Game implements ApplicationListener {
- Matrix4 model,view,project,mvp,mvm;
- float angle;
- Mesh mesh;
- Mesh tmesh;
- ShaderProgram s;
- Texture t;
- public void create() {
- angle = 0;
- model = new Matrix4();
- view = new Matrix4();
- project = new Matrix4();
- mvp = new Matrix4();
- mvm = new Matrix4();
- mesh = ObjLoader.loadObj(Gdx.files.internal("Mesh/cube2.obj").read());
- tmesh = new Mesh(true, 4, 6, /*...*/
- new VertexAttribute(Usage.Position, 3, "a_position"),
- new VertexAttribute(Usage.Normal, 3, "a_normal"),
- new VertexAttribute(Usage.TextureCoordinates, 2, "a_texCoord"));
- tmesh.setVertices(new float[] {
- -1,-1,0,0,0,1,0,0,
- 1,-1,0,0,0,1,1,0,
- -1,1,0,0,0,1,0,1,
- 1,1,0,0,0,1,1,1
- });
- tmesh.setIndices(new short[] {
- 0,1,2,1,2,3
- });
- FileHandle vs = Gdx.files.internal("Shader/std.vs");
- FileHandle fs = Gdx.files.internal("Shader/std.fs");
- t = new Texture(Gdx.files.internal("Image/r2.png"));
- s = new ShaderProgram(vs, fs);
- if(!s.isCompiled()){
- Gdx.app.log("Shader Probs:", s.getLog());
- }
- mesh.getVertexAttribute(Usage.Position).alias = "a_position";
- mesh.getVertexAttribute(Usage.Normal).alias = "a_normal";
- mesh.getVertexAttribute(Usage.TextureCoordinates).alias = "a_texCoord";
- }
- public void dispose() {
- }
- public void pause() {
- }
- public void render() {
- Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
- angle++;
- model.setToRotation(0, 0, 1, angle);
- mvm.set(view);
- mvm.mul(model);
- mvp.set(project.getValues());
- mvp.mul(view);
- mvp.mul(model);
- t.bind();
- s.begin();
- s.setUniformMatrix("mvp", mvp, false);
- s.setUniformi("tex", 0);
- tmesh.render(s, GL20.GL_TRIANGLES);
- //mesh.render(s, GL20.GL_TRIANGLES);
- }
- public void resize(int width, int height) {
- Gdx.gl.glViewport(0, 0, width, height);
- Gdx.gl.glClearColor(0.3f, 0.3f, 0.3f, 1);
- float ratio = (float)width/(float)height;
- project.setToProjection(0.1f, 20, 65, ratio);
- view.setToLookAt(new Vector3(0,0,-5), new Vector3(0,0,0), new Vector3(0,1,0));
- }
- public void resume() {
- // TODO Auto-generated method stub
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment