UPDATE 1:
I have been able to show two different GLsurfaceview showing one
simple square for every surface with OpenGL and it works.
Then I applied a texture on one square and it works.
Now I'd like to share textures within the second square on the second
GLSurfaceView, but it seems a bit complicated.
Is there anyone who knows how to work it out?
Here my code... it's bad code, but it just for testing...
private static int id_text = -1; //id texture
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glClearColor(0, 0, 0, 0);
gl.glClearDepthf(1.0f);
gl.glEnable(GL10.GL_DEPTH_TEST);
gl.glDepthFunc(GL10.GL_LEQUAL);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
//TEXTTURE
gl.glEnable(GL11.GL_TEXTURE_2D);
// create vertex buffer for texture
textureBuffer = setTextureVertex();
//if I am the first glsurfaceview (it means texture
sharing == false) I create my texture, otherwise i get the shared one.
if(!textureSharing)
//id_text is the texture id generated, see below
methods
id_text = GlRenderer.loadTexture(gl, context,
R.drawable.texture);
gl.glDisable(GL11.GL_TEXTURE_2D);
}
public void onDrawFrame(GL10 gl) {
gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
gl.glMatrixMode(GL10.GL_MODELVIEW);
gl.glLoadIdentity();
//if my texture id isn't generated yet, nop, else I
use it do for drawing
if (id_text != -1) {
// draw quad
gl.glPushMatrix();
gl.glColor4f(1, 1, 1, 1);
// create texture
gl.glEnable(GL10.GL_TEXTURE_2D);
gl.glBindTexture(GL10.GL_TEXTURE_2D, id_text);
gl.glTranslatef(0, 0, -4f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, quadBuffer);
gl.glTexCoordPointer(2, GL11.GL_FLOAT, 0,
textureBuffer);
gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
// Disable the vertices buffer.
gl.glDisableClientState(GL11.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL11.GL_TEXTURE_COORD_ARRAY);
gl.glDisable(GL11.GL_TEXTURE_2D);
gl.glPopMatrix();
}
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
// avoid division by zero
if (height == 0)
height = 1;
// draw on the entire screen
gl.glViewport(0, 0, width, height);
// setup projection matrix
gl.glMatrixMode(GL10.GL_PROJECTION);
gl.glLoadIdentity();
GLU.gluPerspective(gl, 45.0f, (float)width / (float)height,
1.0f,
100.0f);
}
/*
* Generate a new ID for texture
*/
private static int newTextureID(GL10 gl) {
int[] temp = new int[1];
gl.glGenTextures(1, temp, 0);
return temp[0];
}
/*
* Load Texture
*/
private static int loadTexture(GL10 gl, Context context, int
resource) {
int id = id_text;
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
Bitmap temp =
BitmapFactory.decodeResource(context.getResources(), resource, opts);
Bitmap texture = Bitmap.createBitmap(temp, 0, 0,
temp.getWidth(), temp.getHeight());
id = newTextureID(gl); //generate the ID texture
gl.glBindTexture(GL10.GL_TEXTURE_2D, id);
// setup texture parameters
gl.glTexParameterx(GL10.GL_TEXTURE_2D,
GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);
gl.glTexParameterx(GL10.GL_TEXTURE_2D,
GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, texture, 0);
temp.recycle();
texture.recycle();
return id;
}
What happen?
The first glsurfaceview shows the correct square textured, the second
one show only a white square....
My goal is share only the ID and the to call glBindTexture(), but
maybe I'm wrong.
Please help me to undestand! Thanks
Paolo
On 8 Giu, 20:37, Paolo <[email protected]> wrote:
> Hi there,
>
> as the Object of this topic... is it possible to create two different
> OpenGL Contexts in the same activity? I mean creating two different
> glsurfaceviews, where every of them use a different EGLConfig and
> Renderer.
>
> And also... what about texture? Can I share texture through the two
> OGL Context?
>
> I need to use it either with 2.1, 2.2. 2.3 or 3.0 with tablets for a
> dual indipendent 3D window.
>
> Thanks in advance
>
> Paolo
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en