Here is how you can easily load a texture from any image format - PNG, BMP, JPG etc.. in OpenGL ES in Android. **Before you begin the code, you need to import your images into your project's /res/drawable/ folder. Just right click the project in eclipse and select import to do that.** //First setup the integer array to hold texture numbers which OpenGL generates int texture[] = new int[1]; //Generate and bind to the texture (gl is my GL10 object) gl.glGenTextures(1, texture, 0); gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[0]); //Setup the texture co-ordinates float texCoords[] = { 0.0f, 0.0f, 1.0f, 0.0f,.......}; FloatBuffer texcoords = FloatBuffer.wrap(texCoords); gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texcoords); Bitmap wood = BitmapFactory.decodeResource(this.getContext().getResources(), R.drawable.myimagefilenamewithoutextension); //Setup optional texture parameters gl.gl
Comments
Post a Comment