Android Open Source - agldemo Base Renderer






From Project

Back to project page agldemo.

License

The source code is released under:

Copyright (c) 2013 Wenhao Li Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software...

If you think the Android project agldemo listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/**
 * Copyright (C) 2010 Wenhao Li. All Rights Reserved.
 * /*from   ww  w  . j av a 2 s. co m*/
 */
package com.agldemo;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.opengles.GL10;

import android.graphics.Bitmap;
import android.opengl.GLUtils;

import com.agldemo.GLView.Renderer;

/**
 * Base Renderer implement.
 */
public abstract class BaseRenderer implements Renderer {

  public static FloatBuffer makeFloatBuffer(float[] arr) {
        ByteBuffer bb = ByteBuffer.allocateDirect(arr.length * 4);
        bb.order(ByteOrder.nativeOrder());
        FloatBuffer fb = bb.asFloatBuffer();
        fb.put(arr);
        fb.position(0);
        return fb;
    }

  public static int loadTexture(GL10 gl, Bitmap bmp) {
        gl.glEnable(GL10.GL_TEXTURE_2D);

        int[] tex = new int[1];

        gl.glGenTextures(1, tex, 0);

        gl.glBindTexture(GL10.GL_TEXTURE_2D, tex[0]);
        GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bmp, 0);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
        gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

        return tex[0];
    }
}




Java Source Code List

com.agldemo.BaseRenderer.java
com.agldemo.GLDemoActivity.java
com.agldemo.GLViewStage.java
com.agldemo.GLView.java
com.agldemo.Lesson.java
com.agldemo.lessons.Lesson01.java
com.agldemo.lessons.Lesson02.java
com.agldemo.lessons.Lesson03.java
com.agldemo.lessons.Lesson04.java
com.agldemo.lessons.Lesson05.java
com.agldemo.lessons.Lesson06.java
com.agldemo.lessons.Lesson07.java
com.agldemo.lessons.Lesson08.java
com.agldemo.lessons.Lesson09.java