Java Code Examples for javax.microedition.khronos.opengles.GL11#glTexParameteri()

The following examples show how to use javax.microedition.khronos.opengles.GL11#glTexParameteri() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GraphicsHelper.java    From BobEngine with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Load a particular graphic.
 * 
 * @param gl The OpenGL object to handle gl functions
 * @param g The index of the graphic in graphics[] to load
 * @param sampleSize The sample size to load the graphic.
 */
private void loadGraphic(GL11 gl, int g, int sampleSize) {
	Bitmap bmp;
	BitmapFactory.Options op = new BitmapFactory.Options();
	op.inSampleSize = sampleSize;

	InputStream is = context.getResources().openRawResource(graphics[g].drawable);

	try {
		bmp = BitmapFactory.decodeStream(is, null, op);
	} finally {
		try {
			is.close();
		} catch (IOException e) {
			Log.e("BobEngine", "Failed to load graphic.");
			e.printStackTrace();
		}
	}

	// Generate an ID for the graphic
	final int[] texID = new int[1];
	gl.glGenTextures(1, texID, 0);
	graphics[g].id = texID[0];

	// Tell openGL which texture we are working with
	gl.glBindTexture(GL11.GL_TEXTURE_2D, graphics[g].id);

	// Create mipmaps and set texture parameters.
	gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, graphics[g].minFilter);                 // Filtering for downscaling
	gl.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, graphics[g].magFilter);                 // Upscale filtering
	if (graphics[g].useMipMaps) gl.glTexParameterx(GL11.GL_TEXTURE_2D, GL11.GL_GENERATE_MIPMAP, GL11.GL_TRUE); // Use mipmapping

	// Texture wrapping
	if (graphics[g].repeating) {
		gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_REPEAT);
		gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_REPEAT);
	} else {
		gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE);
		gl.glTexParameterf(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE);
	}

	// This assigns bmp to the texture we are working with (g)
	GLUtils.texImage2D(GL11.GL_TEXTURE_2D, 0, bmp, 0);

	// Set the face rotation
	gl.glFrontFace(GL11.GL_CCW);

	bmp.recycle();

	graphics[g].loaded();

	gl.glFinish();
}
 
Example 2
Source File: ByteBufferTexture.java    From document-viewer with GNU General Public License v3.0 4 votes vote down vote up
private void uploadToCanvas(final GLCanvas canvas) {
    final GL11 gl = canvas.getGLInstance();

    if (mBitmap != null) {
        try {
            final int bWidth = mBitmap.getWidth();
            final int bHeight = mBitmap.getHeight();
            final int texWidth = getTextureWidth();
            final int texHeight = getTextureHeight();

            // Define a vertically flipped crop rectangle for
            // OES_draw_texture.
            // The four values in sCropRect are: left, bottom, width, and
            // height. Negative value of width or height means flip.
            sCropRect[0] = 0;
            sCropRect[1] = bHeight;
            sCropRect[2] = bWidth;
            sCropRect[3] = -bHeight;

            // Upload the bitmap to a new texture.
            GLId.glGenTextures(1, sTextureId, 0);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, sTextureId[0]);
            gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
            gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
            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);

            if (bWidth == texWidth && bHeight == texHeight) {
                gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, texWidth, texHeight, 0, GL10.GL_RGBA,
                        GL10.GL_UNSIGNED_BYTE, mBitmap.getPixels());
            } else {
                gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, texWidth, texHeight, 0, GL10.GL_RGBA,
                        GL10.GL_UNSIGNED_BYTE, null);
                gl.glTexSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bWidth, bHeight, GL10.GL_RGBA,
                        GL10.GL_UNSIGNED_BYTE, mBitmap.getPixels());
            }
        } finally {
            freeBitmap();
        }
        // Update texture state.
        setAssociatedCanvas(canvas);
        mId = sTextureId[0];
        mState = STATE_LOADED;
    } else {
        mState = STATE_ERROR;
        LCTX.e("Texture load fail, no bitmap");
    }
}
 
Example 3
Source File: UploadedTexture.java    From document-viewer with GNU General Public License v3.0 4 votes vote down vote up
private void uploadToCanvas(final GLCanvas canvas) {
    final GL11 gl = canvas.getGLInstance();

    final Bitmap bitmap = getBitmap();
    if (bitmap != null) {
        try {
            final int bWidth = bitmap.getWidth();
            final int bHeight = bitmap.getHeight();
            final int texWidth = getTextureWidth();
            final int texHeight = getTextureHeight();

            // Upload the bitmap to a new texture.
            GLId.glGenTextures(1, sTextureId, 0);
            gl.glBindTexture(GL10.GL_TEXTURE_2D, sTextureId[0]);
            gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S, GL10.GL_CLAMP_TO_EDGE);
            gl.glTexParameteri(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T, GL10.GL_CLAMP_TO_EDGE);
            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);

            if (bWidth == texWidth && bHeight == texHeight) {
                GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
            } else {
                final int format = GLUtils.getInternalFormat(bitmap);
                final int type = GLUtils.getType(bitmap);

                gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, format, texWidth, texHeight, 0, format, type, null);
                GLUtils.texSubImage2D(GL10.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type);
            }
        } finally {
            freeBitmap();
        }
        // Update texture state.
        setAssociatedCanvas(canvas);
        mId = sTextureId[0];
        mState = STATE_LOADED;
        mContentValid = true;
    } else {
        mState = STATE_ERROR;
        throw new RuntimeException("Texture load fail, no bitmap");
    }
}