private int getMaxTextureSize() { // The OpenGL texture size is the maximum size that can be drawn in an ImageView int[] maxSize = new int[1]; GLES10.glGetIntegerv(GLES10.GL_MAX_TEXTURE_SIZE, maxSize, 0); return maxSize[0]; }
glDisable(GL_DITHER); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, mTextureID); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); float angle = 0.090f * ((int) time); glRotatef(angle, 0, 0, 1.0f);
@Override public void draw(final int texId, final float[] tex_matrix, final int offset) { // FIXME Matrixを適用 GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY); pVertex.position(0); GLES10.glVertexPointer(2, GLES10.GL_FLOAT, VERTEX_SZ, pVertex); //-------------------------------------------------------------------------------- GLES10.glEnableClientState(GLES10.GL_TEXTURE_COORD_ARRAY); pTexCoord.position(0); GLES10.glTexCoordPointer(VERTEX_NUM, GLES10.GL_FLOAT, VERTEX_SZ, pTexCoord); GLES10.glActiveTexture(GLES10.GL_TEXTURE0); GLES10.glBindTexture(mTexTarget, texId); //-------------------------------------------------------------------------------- GLES10.glDrawArrays(GLES10.GL_TRIANGLE_STRIP, 0, VERTEX_NUM); //-------------------------------------------------------------------------------- GLES10.glBindTexture(mTexTarget, 0); GLES10.glDisableClientState(GLES10.GL_TEXTURE_COORD_ARRAY); //-------------------------------------------------------------------------------- GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY); }
glDisable(GL_DITHER); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glClearColor(.5f, .5f, .5f, 1); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glGenTextures(1, textures, 0); glBindTexture(GL_TEXTURE_2D, mTextureID); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); mTextureLoader.load(gl);
public void draw(GL10 unused) { GLES10.glColorPointer(4, GLES10.GL_FLOAT, 0, mColorBuffer); GLES10.glVertexPointer(3, GLES10.GL_FLOAT, 0, mVertexBuffer); GLES10.glEnableClientState(GLES10.GL_COLOR_ARRAY); GLES10.glEnableClientState(GLES10.GL_VERTEX_ARRAY); GLES10.glDrawElements(GLES10.GL_TRIANGLES, 36, GLES10.GL_UNSIGNED_BYTE, mIndexBuffer); GLES10.glDisableClientState(GLES10.GL_COLOR_ARRAY); GLES10.glDisableClientState(GLES10.GL_VERTEX_ARRAY); }
public void draw(GL10 gl) { glFrontFace(GL_CCW); glVertexPointer(3, GL_FLOAT, 0, mFVertexBuffer); glEnable(GL_TEXTURE_2D); glTexCoordPointer(2, GL_FLOAT, 0, mTexBuffer); glDrawElements(GL_TRIANGLE_STRIP, VERTS, GL_UNSIGNED_SHORT, mIndexBuffer); }
/** * テクスチャ名を生成 * @param texTarget * @param texUnit テクスチャユニット, GL_TEXTURE0...GL_TEXTURE31 * @param min_filter テクスチャの補間方法を指定, GL_LINEARとかGL_NEAREST * @param mag_filter テクスチャの補間方法を指定, GL_LINEARとかGL_NEAREST * @param wrap テクスチャのクランプ方法, GL_CLAMP_TO_EDGE * @return */ public static int initTex(final int texTarget, final int texUnit, final int min_filter, final int mag_filter, final int wrap) { // if (DEBUG) Log.v(TAG, "initTex:target=" + texTarget); final int[] tex = new int[1]; GLES10.glActiveTexture(texUnit); GLES10.glGenTextures(1, tex, 0); GLES10.glBindTexture(texTarget, tex[0]); GLES10.glTexParameterx(texTarget, GLES10.GL_TEXTURE_WRAP_S, wrap); GLES10.glTexParameterx(texTarget, GLES10.GL_TEXTURE_WRAP_T, wrap); GLES10.glTexParameterx(texTarget, GLES10.GL_TEXTURE_MIN_FILTER, min_filter); GLES10.glTexParameterx(texTarget, GLES10.GL_TEXTURE_MAG_FILTER, mag_filter); return tex[0]; }
public void onSurfaceChanged(GL10 gl, int w, int h) { glViewport(0, 0, w, h); /* * Set our projection matrix. This doesn't have to be done * each time we draw, but usually a new projection needs to * be set when the viewport is resized. */ float ratio = (float) w / h; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustumf(-ratio, ratio, -1, 1, 3, 7); }
public static int loadTextureFromResource(final Context context, final int resId) { // Create an empty, mutable bitmap final Bitmap bitmap = Bitmap.createBitmap(256, 256, Bitmap.Config.ARGB_8888); // get a canvas to paint over the bitmap final Canvas canvas = new Canvas(bitmap); canvas.drawARGB(0,0,255,0); // get a background image from resources // note the image format must match the bitmap format final Drawable background = context.getResources().getDrawable(resId); background.setBounds(0, 0, 256, 256); background.draw(canvas); // draw the background to our bitmap final int[] textures = new int[1]; //Generate one texture pointer... GLES10.glGenTextures(1, textures, 0); //...and bind it to our array GLES10.glBindTexture(GLES10.GL_TEXTURE_2D, textures[0]); //Create Nearest Filtered Texture GLES10.glTexParameterx(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_MIN_FILTER, GLES10.GL_NEAREST); GLES10.glTexParameterx(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_MAG_FILTER, GLES10.GL_LINEAR); //Different possible texture parameters, e.g. GLES10.GL_CLAMP_TO_EDGE GLES10.glTexParameterx(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_WRAP_S, GLES10.GL_REPEAT); GLES10.glTexParameterx(GLES10.GL_TEXTURE_2D, GLES10.GL_TEXTURE_WRAP_T, GLES10.GL_REPEAT); //Use the Android GLUtils to specify a two-dimensional texture image from our bitmap GLUtils.texImage2D(GLES10.GL_TEXTURE_2D, 0, bitmap, 0); //Clean up bitmap.recycle(); return textures[0]; }
/** * このインスタンスで管理しているテクスチャを有効にする(バインドする) */ @Override public void bind() { // if (DEBUG) Log.v(TAG, "bind:"); GLES10.glActiveTexture(mTextureUnit); // テクスチャユニットを選択 GLES10.glBindTexture(mTextureTarget, mTextureId); }
public void onSurfaceChanged(GL10 unused, int w, int h) { GLES10.glViewport(0, 0, w, h); }
/** * Should be overridden in subclasses and used to perform rendering. */ public void draw(GL10 gl) { GLES10.glClear(GLES10.GL_COLOR_BUFFER_BIT | GLES10.GL_DEPTH_BUFFER_BIT); }
public void onSurfaceCreated(GL10 unused, EGLConfig config) { // Transparent background GLES10.glClearColor(0.0f, 0.0f, 0.0f, 0.f); }
/** * Set up a perspective projection matrix * * @param fovy specifies the field of view angle, in degrees, in the Y * direction. * @param aspect specifies the aspect ration that determins the field of * view in the x direction. The aspect ratio is the ratio of x * (width) to y (height). * @param zNear specifies the distance from the viewer to the near clipping * plane (always positive). * @param zFar specifies the distance from the viewer to the far clipping * plane (always positive). */ public static void gluPerspective(final float fovy, final float aspect, final float zNear, final float zFar) { final float top = zNear * (float) Math.tan(fovy * (Math.PI / 360.0)); final float bottom = -top; final float left = bottom * aspect; final float right = top * aspect; GLES10.glFrustumf(left, right, bottom, top, zNear, zFar); }
glDisable(GL_DITHER); glTexEnvx(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, mTextureID); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameterx(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); float angle = 0.090f * ((int) time); glRotatef(angle, 0, 0, 1.0f);
glDisable(GL_DITHER); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST); glClearColor(.5f, .5f, .5f, 1); glShadeModel(GL_SMOOTH); glEnable(GL_DEPTH_TEST); glEnable(GL_TEXTURE_2D); glGenTextures(1, textures, 0); glBindTexture(GL_TEXTURE_2D, mTextureID); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); mTextureLoader.load(gl);
public void draw(GL10 gl) { glFrontFace(GL_CCW); glVertexPointer(3, GL_FLOAT, 0, mFVertexBuffer); glEnable(GL_TEXTURE_2D); glTexCoordPointer(2, GL_FLOAT, 0, mTexBuffer); glDrawElements(GL_TRIANGLE_STRIP, VERTS, GL_UNSIGNED_SHORT, mIndexBuffer); }
public void onSurfaceChanged(GL10 gl, int w, int h) { glViewport(0, 0, w, h); /* * Set our projection matrix. This doesn't have to be done * each time we draw, but usually a new projection needs to * be set when the viewport is resized. */ float ratio = (float) w / h; glMatrixMode(GL_PROJECTION); glLoadIdentity(); glFrustumf(-ratio, ratio, -1, 1, 3, 7); }
/** * このインスタンスで管理しているテクスチャを無効にする(アンバインドする) */ @Override public void unbind() { // if (DEBUG) Log.v(TAG, "unbind:"); GLES10.glActiveTexture(mTextureUnit); // テクスチャユニットを選択 GLES10.glBindTexture(mTextureTarget, 0); }
@Override public void makeCurrent() { mEglBase.makeCurrent(mEglSurface); if (mEglBase.getGlVersion() >= 2) { GLES20.glViewport(0, 0, mEglBase.getSurfaceWidth(mEglSurface), mEglBase.getSurfaceHeight(mEglSurface)); } else { GLES10.glViewport(0, 0, mEglBase.getSurfaceWidth(mEglSurface), mEglBase.getSurfaceHeight(mEglSurface)); } }