I need help adding a second texture to glSurfaceView - android

I used harism's page curl ( Harism, thanx a lot for this excelent library!) for android to develop a commercial application - an electronic magazine.
I wrapped everything that should have been around the app, that is xml - rpc fetching of the magazine pages, caching, loaders, my own bitmap provider, custom gesture event handlers etc...
But, i have a very big problem that no matter how i tried i cannot solve myself.
I need to implement a real book functionality, meaning that when the page is oriented in a landscape mode, i need pairs of pages ( initial screen - left blank, right cover. First flip = left page 1, right page 2. Second flip = left page 3, right page 4... )
I read the info Harism gave to people that asked the same thing on github on the issue they opened concerning this, but that is simply not enough with my limited knowledge of openGL es.
I understand i need to implement a backside texture, but can anyone please be a bit more detailed on this issue? I hit a dead end trying to do it myself and i'm in dire need of help.
If there is ANY need for additional code posting - let me know, i will be more willing to post any / all of the code.
Thanks!
EDIT re- reading it i realized i should have been more detailed. The page that is curling has a texture that is the bitmap of the actual page. At the current setting, the bitmap front and back are rendered separately, but it is the same texture. I need the back one to be the different one.
Some code that does the actual rendering:
/**
* Draws our mesh.
*/
public synchronized void draw(GL10 gl) {
// First allocate texture if there is not one yet.
if (DRAW_TEXTURE && mTextureIds == null) {
// Generate texture.
mTextureIds = new int[1];
gl.glGenTextures(1, mTextureIds, 0);
// Set texture attributes.
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[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);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_CLAMP_TO_EDGE);
}
// If mBitmap != null we have a new texture.
if (DRAW_TEXTURE && mBitmap != null) {
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmap, 0);
mBitmap = null;
}
if (DRAW_TEXTURE) {
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureIds[0]);
}
// Some 'global' settings.
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
// TODO: Drop shadow drawing is done temporarily here to hide some
// problems with its calculation.
if (DRAW_SHADOW) {
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, mShadowColors);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mShadowVertices);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, mDropShadowCount);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
gl.glDisable(GL10.GL_BLEND);
}
// Enable texture coordinates.
if (DRAW_TEXTURE) {
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTexCoords);
}
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertices);
// Enable color array.
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, mColors);
// Draw blank / 'white' front facing vertices.
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, mVerticesCountFront);
// Draw front facing texture.
// TODO: Decide whether it's really needed to have alpha blending for
// front facing texture. If not, GL_BLEND isn't needed, possibly
// increasing performance. The heck, is it needed at all?
if (DRAW_TEXTURE) {
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, mVerticesCountFront);
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glDisable(GL10.GL_BLEND);
}
int backStartIdx = Math.max(0, mVerticesCountFront - 2);
int backCount = mVerticesCountFront + mVerticesCountBack - backStartIdx;
// Draw blank / 'white' back facing vertices.
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, backStartIdx, backCount);
// Draw back facing texture.
if (DRAW_TEXTURE) {
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, backStartIdx, backCount);
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glDisable(GL10.GL_BLEND);
}
// Disable textures and color array.
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
if (DRAW_POLYGON_OUTLINES) {
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glLineWidth(1.0f);
gl.glColor4f(0.5f, 0.5f, 1.0f, 1.0f);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertices);
gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, mVerticesCountFront);
gl.glDisable(GL10.GL_BLEND);
}
if (DRAW_CURL_POSITION) {
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glLineWidth(1.0f);
gl.glColor4f(1.0f, 0.5f, 0.5f, 1.0f);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, mCurlPositionLines);
gl.glDrawArrays(GL10.GL_LINES, 0, mCurlPositionLinesCount * 2);
gl.glDisable(GL10.GL_BLEND);
}
if (DRAW_SHADOW) {
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, mShadowColors);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mShadowVertices);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, mDropShadowCount,
mSelfShadowCount);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
gl.glDisable(GL10.GL_BLEND);
}
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
I suppose i should tamper with :
// Draw back facing texture.
if (DRAW_TEXTURE) {
gl.glEnable(GL10.GL_BLEND);
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, backStartIdx, backCount);
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glDisable(GL10.GL_BLEND);
}
And provide it with a sepparate bitmap, but i don't know how to do this.
Thanks again
EDIT: I started a mega- bounty, i really need this answered... :)

My openGL knowledge is also limited but I had a similar issue in the past.
To have two textures you will need, at least, to modify this line:
gl.glGenTextures(2, mTextureIds, 0);
Here you have an example of how to use more than one texture.

Related

Android OpenGL Texture Coloring

I'm trying to change color of my textures, I have 2 render methods inside my sprite, one without color params and one with, It works fine if there is just 1 object being rendered, but If i render for example 1 colored texture and 1 normal texture, both will be colored
I'm guessing I somehow have to reset the glTextEnvf state but I got no idea how.
Here is my source code
public void Render(GL10 gl)
{
gl.glBindTexture(GL10.GL_TEXTURE_2D,textures[0]);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glVertexPointer(2, GL10.GL_FLOAT,0, verticesBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP,0, vertices.length/2);
//RESTORE
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
public void Render(GL10 gl,float r,float g,float b)
{
gl.glBindTexture(GL10.GL_TEXTURE_2D,textures[0]);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glColor4f(r,g,b,1.0f);
gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, verticesBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 2);
//RESTORE
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
After you've called glDrawArrays in the sprite you want to be colored, set the color back to 1:
gl.glColor4f(1, 1, 1, 1);
Hope this helps

OpenGL ES 2D on Samsung 4 - no textures on the screen

I have Nexsus 4 and several HTCs and my game works fine.
When I launch on Samsung 4 I see white rectangles (empty textures),
no errors,
Further, my game uses sensors but I see on Samsung 4 it doesn't work too,
but Samsung 3 - works,
please help,
[EDIT]
on Samsung 3 works!
I heard that they did a lot of changes with S4
[EDIT 2]
This is how I load textures:
public void loadTextures(GL10 gl, Context context){
//Log.e(LOG_TAG, "DevQuestSprites :: loadTextures");
InputStream is;
Bitmap bitmap;
is = context.getResources().openRawResource(R.drawable.fly_a1_sprite);
bitmap = BitmapFactory.decodeStream(is);
try {
is.close();
is = null;
} catch (IOException e) {
}
gl.glGenTextures(textureCount, textures, 0);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
bitmap.recycle();
}
For me most impotent row is:
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
Here actually I put texture.
And this is draw method:
public void draw(GL10 gl,
...
...
)
{
...
//gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glTranslatef(transx, transy, 0.0f);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, floatBufferArray[mFrame]);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length / 3);
//gl.glDrawElements(GL10.GL_TRIANGLES, 1, GL10.GL_UNSIGNED_SHORT, vertexBuffer);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
[EDIT 3]
I added to draw, onDrawFrame and main loop, no errors:
int error = gl.glGetError();
if (error != 0)
Log.e("main loop", "Draw " + error);
After debugging I found only one new error for Samsung 4:
08-07 12:57:53.356: E/ViewRootImpl(29124): sendUserActionEvent() mView == null
[EDIT 4]
#Override
public void onSurfaceCreated(GL10 gl, EGLConfig confid) {
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearColor(0,0,0,0);
gl.glClearDepthf(1.0f);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
gl.glEnable(GL10.GL_BLEND);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
}
One issue is that you have enabled alpha blending, but you can't use GLUtils.texImage2D() to load alpha textures on Android. This is a common problem that Google really should document better. The problem is that the Bitmap class converts all images into pre-multiplied format, but that does not work with OpenGL ES unless the image is completely opaque. The best solution is to use native code. This article gives more detail on this:
http://software.intel.com/en-us/articles/porting-opengl-games-to-android-on-intel-atom-processors-part-1
What is the size of your image? if you are using opnel GL It depends on which driver have the mobile but you need the size image to be power of two to work fine in all devices, 2,4,8,16,32...etc

How to set on texture on top of another texture in android using OPEN GL

I have been searching for this for the pass two days .I am developing an android game using Open GL in which there is a situation where i have to display two images at the same time, one should be the background image and second one is displayed depending on a condition.
I have displayed the background imgae using Open GL Texture property.But when i tried to display the second image by using texture first one is not displaying.Since i am dealing with multiple texture i have used a GLTexture class to manipulate the texture (http://tkcodesharing.blogspot.in/2008/05/working-with-textures-in-androids.html).Even then i am not able to display two images at the same time.
Here is some code :
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
glTextures= new GLTextures(gl,this.context);//class to manipulate textures
//adding image resources
this.glTextures.add(R.drawable.back);
this.glTextures.add(R.drawable.hand);
//loading texture
this.glTextures.loadTextures();
gl.glEnable(GL10.GL_TEXTURE_2D);
...
}
In onDrawFrame
gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 0.0f, -3.5f);
glTextures.setTexture(R.drawable.back);//it will bind this particular texture for drawing
draw(gl);
if(condition == 1){
gl.glLoadIdentity();
gl.glTranslatef(0.0f, 1.0f, -7.0f);
glTextures.setTexture(R.drawable.hand);
drawSecond(gl);
}
////////////////////////////////////////////////////////
In draw code
public void draw(GL10 gl){
gl.glActiveTexture(GL10.GL_TEXTURE0);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length/3);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
public void drawSecond(GL10 gl){
gl.glActiveTexture(GL10.GL_TEXTURE1);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
//GLES20.glUniform1i(isShaked, 1);
gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, vertices.length/3);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
remove "gl.glActiveTexture(GL10.GL_TEXTURE0);" and gl.glActiveTexture(GL10.GL_TEXTURE1);
lines from the rendering code.
you use multiple texture units only if you need multi-texturing,
which is using multiple textures in one draw call.
just bind the first texture to the active texture unit (default to GL_TEXTURE0) and draw the first triangle strip, than bind the second texture (without changing the active texture unit GL_TEXTURE0) and draw the second triangle strip.

How to flip an Image in OpenGL?

I hate to ask such a dumb question but I just can't firgure out how to flip an image using Android OpenGL.
I try using gl.glScalef(-1,y,z) android gl.glRotatef(180,0,1,0) but when I do this the image flip but it also change the positions which I do not want. I'm sure there a easy way to do this I'm just not getting.
Here is my draw code:
public void draw(GL10 gl){
gl.glLoadIdentity();
gl.glTranslatef(position.x, position.y, 0);
gl.glRotatef(angle, rotX, rotY, rotZ);
gl.glScalef(scaleX, scaleY, scaleZ);
gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId[0]);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glEnable(GL10.GL_BLEND);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexsBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);
gl.glDrawElements(GL10.GL_TRIANGLES, indices.length, GL10.GL_UNSIGNED_SHORT, indexBuffer);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glDisable(GL10.GL_BLEND);
if(animation == true){
PlayAnimations();
}
}
center the object (remember the translation)
perform the flipping by scaling to -1 with respect to the desired axis.
then "reverse translate" the object.
For more information, please grab yourself a copy of Computer Graphics by James D. Foley.
http://www.amazon.com/Computer-Graphics-Principles-Practice-2nd/dp/0201848406
You could use a different set of texture coordinates or use a texture matrix.

OpenGL ES Textures do not display properly on HTC Magic (1.6) but display fine on Emulator and Mytouch 4g

A texture used for a cube is being used for other objects in the view even though they aren't assigned it. This only happens on my HTC Magic running 1.6. I load the texture image from resources using the standard Bitmap libraries. This shouldn't be the problem however since it correctly applies texture to intended models.
I tried deleted the texture after using it however the texture is completely wiped and the cubes never seem to display it.
I recycled a lot of code taken from tutorials around the net.
Code:
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glRotatef(sceneroty, 0, 1, 0);
gl.glTranslatef(xtrans, 0, ztrans);
root.draw(gl);
Root.Draw Function:
gl.glPushMatrix();
gl.glFrontFace(GL10.GL_CCW);
gl.glEnable(GL10.GL_CULL_FACE);
gl.glCullFace(GL10.GL_BACK);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, verticesBuffer);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glColor4f(rgba[0], rgba[1], rgba[2], rgba[3]);
// Smooth color
if (colorBuffer != null) {
// Enable the color array buffer to be used during rendering.
gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
gl.glColorPointer(4, GL10.GL_FLOAT, 0, colorBuffer);
}
// New part...
if (mShouldLoadTexture) {
loadGLTexture(gl);mShouldLoadTexture = false;
}
if (mTextureId != -1 && mTextureBuffer != null) {
gl.glEnable(GL10.GL_TEXTURE_2D);
// Enable the texture state
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
// Point to our buffers
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureBuffer);
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureId);
}
// ... end new part.
gl.glTranslatef(x, y, z);
gl.glRotatef(rx, 1, 0, 0);
gl.glRotatef(ry, 0, 1, 0);
gl.glRotatef(rz, 0, 0, 1);
// Point out the where the color buffer is.
gl.glDrawElements(GL10.GL_TRIANGLES, numOfIndices,
GL10.GL_UNSIGNED_SHORT, indicesBuffer);
// Disable the vertices buffer.
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
// New part...
if (mTextureId != -1 && mTextureBuffer != null) {
gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
// ... end new part.
// Disable face culling.
gl.glDisable(GL10.GL_CULL_FACE);
gl.glPopMatrix();
Other used Functions:
protected void setTextureCoordinates(float[] textureCoords) {
// float is 4 bytes, therefore we multiply the number if
// vertices with 4.
ByteBuffer byteBuf = ByteBuffer.allocateDirect(
textureCoords.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
mTextureBuffer = byteBuf.asFloatBuffer();
mTextureBuffer.put(textureCoords);
mTextureBuffer.position(0);
}
public void loadBitmap(Bitmap bitmap) {
this.mBitmap = bitmap;
mShouldLoadTexture = true;
}
private void loadGLTexture(GL10 gl) {
// Generate one texture pointer...
gl.glGenTextures(1, textures, 0);
mTextureId = textures[0];
// ...and bind it to our array
gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureId);
// Create Nearest Filtered Texture
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);
// Different possible texture parameters, e.g. GL10.GL_CLAMP_TO_EDGE
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
GL10.GL_CLAMP_TO_EDGE);
gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
GL10.GL_REPEAT);
// Use the Android GLUtils to specify a two-dimensional texture image
// from our bitmap
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, mBitmap, 0);
}
It looks like you aren't disabling texturing nor unbinding the TEXTURE_2D target. If your other cubes are untextured they will then be drawn using the same texture left over from the previous draw operation. You should disable texturing if the object doesn't have a texture assigned to it:
if (mTextureId == -1) {
gl.glDisable(GL10.GL_TEXTURE_2D);
gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
}

Categories

Resources