Search in sources :

Example 16 with AssetManager

use of com.badlogic.gdx.assets.AssetManager in project libgdx by libgdx.

the class MultipleRenderTargetTest method create.

@Override
public void create() {
    //use default prepend shader code for batch, some gpu drivers are less forgiving
    batch = new SpriteBatch();
    //depth texture not currently sampled
    ShaderProgram.pedantic = false;
    modelCache = new ModelCache();
    ShaderProgram.prependVertexCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_ARB_explicit_attrib_location : enable\n" : "#version 300 es\n";
    ShaderProgram.prependFragmentCode = Gdx.app.getType().equals(Application.ApplicationType.Desktop) ? "#version 140\n #extension GL_ARB_explicit_attrib_location : enable\n" : "#version 300 es\n";
    renderContext = new RenderContext(new DefaultTextureBinder(DefaultTextureBinder.ROUNDROBIN));
    shaderProvider = new BaseShaderProvider() {

        @Override
        protected Shader createShader(Renderable renderable) {
            return new MRTShader(renderable);
        }
    };
    renderableSorter = new DefaultRenderableSorter() {

        @Override
        public int compare(Renderable o1, Renderable o2) {
            return o1.shader.compareTo(o2.shader);
        }
    };
    mrtSceneShader = new ShaderProgram(Gdx.files.internal("data/g3d/shaders/mrtscene.vert"), Gdx.files.internal("data/g3d/shaders/mrtscene.frag"));
    if (!mrtSceneShader.isCompiled()) {
        System.out.println(mrtSceneShader.getLog());
    }
    quad = createFullScreenQuad();
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.near = 1f;
    camera.far = 100f;
    camera.position.set(3, 5, 10);
    camera.lookAt(0, 2, 0);
    camera.up.set(0, 1, 0);
    camera.update();
    cameraController = new FirstPersonCameraController(camera);
    cameraController.setVelocity(50);
    Gdx.input.setInputProcessor(cameraController);
    frameBuffer = new MRTFrameBuffer(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), 3);
    AssetManager assetManager = new AssetManager();
    assetManager.load("data/g3d/materials/cannon.g3db", Model.class);
    assetManager.finishLoading();
    Model scene = assetManager.get("data/g3d/materials/cannon.g3db");
    cannon = new ModelInstance(scene, "Cannon_LP");
    cannon.transform.setToTranslationAndScaling(0, 0, 0, 0.001f, 0.001f, 0.001f);
    ModelBuilder modelBuilder = new ModelBuilder();
    for (int i = 0; i < NUM_LIGHTS; i++) {
        modelBuilder.begin();
        Light light = new Light();
        light.color.set(MathUtils.random(1f), MathUtils.random(1f), MathUtils.random(1f));
        light.position.set(MathUtils.random(-10f, 10f), MathUtils.random(10f, 15f), MathUtils.random(-10f, 10f));
        light.vy = MathUtils.random(10f, 20f);
        light.vx = MathUtils.random(-10f, 10f);
        light.vz = MathUtils.random(-10f, 10f);
        MeshPartBuilder meshPartBuilder = modelBuilder.part("light", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, new Material());
        meshPartBuilder.setColor(light.color.x, light.color.y, light.color.z, 1f);
        meshPartBuilder.sphere(0.2f, 0.2f, 0.2f, 10, 10);
        light.lightInstance = new ModelInstance(modelBuilder.end());
        lights.add(light);
    }
    modelBuilder.begin();
    MeshPartBuilder meshPartBuilder = modelBuilder.part("floor", GL20.GL_TRIANGLES, VertexAttributes.Usage.Position | VertexAttributes.Usage.ColorPacked | VertexAttributes.Usage.Normal, new Material());
    meshPartBuilder.setColor(0.2f, 0.2f, 0.2f, 1f);
    meshPartBuilder.box(0, -0.1f, 0f, 20f, 0.1f, 20f);
    floorInstance = new ModelInstance(modelBuilder.end());
    Gdx.input.setInputProcessor(new InputMultiplexer(this, cameraController));
}
Also used : RenderContext(com.badlogic.gdx.graphics.g3d.utils.RenderContext) AssetManager(com.badlogic.gdx.assets.AssetManager) Material(com.badlogic.gdx.graphics.g3d.Material) DefaultRenderableSorter(com.badlogic.gdx.graphics.g3d.utils.DefaultRenderableSorter) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) MeshPartBuilder(com.badlogic.gdx.graphics.g3d.utils.MeshPartBuilder) Shader(com.badlogic.gdx.graphics.g3d.Shader) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BaseShaderProvider(com.badlogic.gdx.graphics.g3d.utils.BaseShaderProvider) ModelCache(com.badlogic.gdx.graphics.g3d.ModelCache) ModelInstance(com.badlogic.gdx.graphics.g3d.ModelInstance) ModelBuilder(com.badlogic.gdx.graphics.g3d.utils.ModelBuilder) InputMultiplexer(com.badlogic.gdx.InputMultiplexer) Renderable(com.badlogic.gdx.graphics.g3d.Renderable) ShaderProgram(com.badlogic.gdx.graphics.glutils.ShaderProgram) Model(com.badlogic.gdx.graphics.g3d.Model) FirstPersonCameraController(com.badlogic.gdx.graphics.g3d.utils.FirstPersonCameraController) DefaultTextureBinder(com.badlogic.gdx.graphics.g3d.utils.DefaultTextureBinder)

Example 17 with AssetManager

use of com.badlogic.gdx.assets.AssetManager in project libgdx by libgdx.

the class ModelLoaderTest method create.

@Override
public void create() {
    camera = new PerspectiveCamera(67, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.position.set(0, 0, 5);
    camera.near = 1;
    camera.far = 100;
    camera.update();
    assets = new AssetManager();
    assets.load("data/g3d/cube.g3dj", Model.class);
    spriteBatch = new SpriteBatch();
    modelBatch = new ModelBatch();
// assets.getLogger().setLevel(Logger.DEBUG);
}
Also used : AssetManager(com.badlogic.gdx.assets.AssetManager) ModelBatch(com.badlogic.gdx.graphics.g3d.ModelBatch) PerspectiveCamera(com.badlogic.gdx.graphics.PerspectiveCamera) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch)

Example 18 with AssetManager

use of com.badlogic.gdx.assets.AssetManager in project RubeLoader by tescott.

the class RubeLoaderTest method initiateSceneLoad.

/**
    * Kicks off asset manager if selected... 
    * 
    */
private void initiateSceneLoad() {
    if (mUseAssetManager) {
        // kick off asset manager operations...
        mAssetManager = new AssetManager();
        mAssetManager.setLoader(RubeScene.class, new RubeSceneAsyncLoader(new InternalFileHandleResolver()));
        // kick things off..
        mAssetManager.load(RUBE_SCENE_FILE_LIST[mRubeFileList][mRubeFileIndex], RubeScene.class);
    }
    mNextState = GAME_STATE.LOADING;
}
Also used : AssetManager(com.badlogic.gdx.assets.AssetManager) InternalFileHandleResolver(com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver) RubeSceneAsyncLoader(com.gushikustudios.rube.loader.RubeSceneAsyncLoader)

Example 19 with AssetManager

use of com.badlogic.gdx.assets.AssetManager in project Alkahest-Coffee by AlkahestDev.

the class MainGame method create.

@Override
public void create() {
    Gdx.graphics.setCursor(Gdx.graphics.newCursor(new Pixmap(Gdx.files.internal("mouseCursorTemp.png")), 0, 0));
    assetManager = new AssetManager();
    queueLoading();
    camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camera.translate(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    camera.update();
    //viewport = new FitViewport(1920, 1080, camera);
    fontCaches = new Array<BitmapFontCache>();
    BitmapFont dagger20 = new BitmapFont(Gdx.files.internal("fonts/dagger20.fnt"));
    BitmapFont dagger30 = new BitmapFont(Gdx.files.internal("fonts/dagger30.fnt"));
    BitmapFont dagger40 = new BitmapFont(Gdx.files.internal("fonts/dagger40.fnt"));
    BitmapFont dagger50 = new BitmapFont(Gdx.files.internal("fonts/dagger50.fnt"));
    dagger20.getData().markupEnabled = true;
    dagger30.getData().markupEnabled = true;
    dagger40.getData().markupEnabled = true;
    dagger50.getData().markupEnabled = true;
    fontCaches.add(new BitmapFontCache(dagger20));
    fontCaches.add(new BitmapFontCache(dagger30));
    fontCaches.add(new BitmapFontCache(dagger40));
    fontCaches.add(new BitmapFontCache(dagger50));
    shapeRenderer = new ShapeRenderer();
    gameMain = new MainMenu(fontCaches, assetManager, camera);
    loadingMenu = new LoadingMenu(fontCaches, assetManager, camera);
    connectingMenu = new ConnectingMenu(fontCaches, assetManager, camera);
    serverBrowser = new ServerBrowser(fontCaches, assetManager, camera);
    settingsMenu = new SettingsMenu(fontCaches, assetManager, camera);
    pickingInfoMenu = new ClientPickingInfoMenu(fontCaches, assetManager, camera);
    lobbyMenu = new ClientLobbyMenu(fontCaches, assetManager, camera);
    // loadingmenu is the only one that is setup before anything else is loaded, background frames are loaded and added to it here
    setupLoadingMenu();
    scW = Gdx.graphics.getWidth();
    scH = Gdx.graphics.getHeight();
    //System.out.println(new Pixmap(Gdx.files.internal("pixmapTest.png")).getPixel(0,0)>>8);//since gimp doesn't do alpha in a friendly way, I'll bitshift right 8 bits to ignore alpha
    state = GameState.State.LOADINGGAME;
    batch = new SpriteBatch();
    client = new MultiplayerClient();
    clientSoldier = new PlayerSoldier(new Rectangle(0, 0, 1, 2), 0, "");
    client.startClient();
    shapeRenderer.setProjectionMatrix(camera.combined);
    batch.setProjectionMatrix(camera.combined);
    menu = new UniversalClientMenu(fontCaches, assetManager, camera);
    Gdx.input.setInputProcessor(this);
}
Also used : MultiplayerClient(me.dumfing.multiplayerTools.MultiplayerClient) AssetManager(com.badlogic.gdx.assets.AssetManager) Rectangle(com.badlogic.gdx.math.Rectangle) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) PlayerSoldier(me.dumfing.multiplayerTools.PlayerSoldier) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont)

Example 20 with AssetManager

use of com.badlogic.gdx.assets.AssetManager in project Alkahest-Coffee by AlkahestDev.

the class CoffeeServer method create.

@Override
public void create() {
    batch = new SpriteBatch();
    camView = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
    camView.translate(Gdx.graphics.getWidth() / 2, Gdx.graphics.getHeight() / 2);
    camView.update();
    batch.setProjectionMatrix(camView.combined);
    manager = new AssetManager();
    shapeRenderer = new ShapeRenderer();
    loadingMenu = new LoadingMenu(fonts, manager, camView);
    readyLoadingBackground();
    manager.load("tuzki.png", Texture.class);
    manager.load("volcano-30238.png", Texture.class);
    manager.load("4k-image-santiago.jpg", Texture.class);
    manager.load("4914003-galaxy-wallpaper-png.png", Texture.class);
    manager.load("pixmapTest.png", Texture.class);
    manager.load("pixmapVisual.png", Texture.class);
    BitmapFont dagger30 = new BitmapFont(Gdx.files.internal("fonts/dagger30.fnt"));
    dagger30.getData().markupEnabled = true;
    serverInfo = new ServerInfoMenu(fonts, manager, camView);
    serverRunningMenu = new ServerRunningGameMenu(fonts, manager, camView);
    fonts.add(new BitmapFontCache(dagger30));
}
Also used : AssetManager(com.badlogic.gdx.assets.AssetManager) ServerInfoMenu(me.dumfing.menus.ServerInfoMenu) OrthographicCamera(com.badlogic.gdx.graphics.OrthographicCamera) ServerRunningGameMenu(me.dumfing.menus.ServerRunningGameMenu) BitmapFont(com.badlogic.gdx.graphics.g2d.BitmapFont) SpriteBatch(com.badlogic.gdx.graphics.g2d.SpriteBatch) ShapeRenderer(com.badlogic.gdx.graphics.glutils.ShapeRenderer) BitmapFontCache(com.badlogic.gdx.graphics.g2d.BitmapFontCache) LoadingMenu(me.dumfing.menus.LoadingMenu)

Aggregations

AssetManager (com.badlogic.gdx.assets.AssetManager)21 SpriteBatch (com.badlogic.gdx.graphics.g2d.SpriteBatch)13 BitmapFont (com.badlogic.gdx.graphics.g2d.BitmapFont)9 InternalFileHandleResolver (com.badlogic.gdx.assets.loaders.resolvers.InternalFileHandleResolver)8 OrthographicCamera (com.badlogic.gdx.graphics.OrthographicCamera)5 PerspectiveCamera (com.badlogic.gdx.graphics.PerspectiveCamera)5 ShapeRenderer (com.badlogic.gdx.graphics.glutils.ShapeRenderer)4 OrthoCamController (com.badlogic.gdx.tests.utils.OrthoCamController)4 ModelBatch (com.badlogic.gdx.graphics.g3d.ModelBatch)3 LoadedCallback (com.badlogic.gdx.assets.AssetLoaderParameters.LoadedCallback)2 FileHandleResolver (com.badlogic.gdx.assets.loaders.FileHandleResolver)2 Texture (com.badlogic.gdx.graphics.Texture)2 BitmapFontCache (com.badlogic.gdx.graphics.g2d.BitmapFontCache)2 FreeTypeFontGeneratorLoader (com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGeneratorLoader)2 FreetypeFontLoader (com.badlogic.gdx.graphics.g2d.freetype.FreetypeFontLoader)2 Material (com.badlogic.gdx.graphics.g3d.Material)2 Model (com.badlogic.gdx.graphics.g3d.Model)2 ModelInstance (com.badlogic.gdx.graphics.g3d.ModelInstance)2 ColorAttribute (com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute)2 CameraInputController (com.badlogic.gdx.graphics.g3d.utils.CameraInputController)2