Java Code Examples for javax.microedition.khronos.opengles.GL10#glBindTexture()

The following examples show how to use javax.microedition.khronos.opengles.GL10#glBindTexture() . 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: LabelMaker.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Begin drawing labels. Sets the OpenGL state for rapid drawing.
 *
 * @param gl
 * @param viewWidth
 * @param viewHeight
 */
public void beginDrawing(GL10 gl, float viewWidth, float viewHeight) {
    checkState(STATE_INITIALIZED, STATE_DRAWING);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    gl.glShadeModel(GL10.GL_FLAT);
    gl.glEnable(GL10.GL_BLEND);
    gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
    gl.glColor4x(0x10000, 0x10000, 0x10000, 0x10000);
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    gl.glOrthof(0.0f, viewWidth, 0.0f, viewHeight, 0.0f, 1.0f);
    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glPushMatrix();
    gl.glLoadIdentity();
    // Magic offsets to promote consistent rasterization.
    gl.glTranslatef(0.375f, 0.375f, 0.0f);
}
 
Example 2
Source File: GLBitmap.java    From TikTok with Apache License 2.0 6 votes vote down vote up
public void loadGLTexture(GL10 gl, Context context) {
    // loading texture
    Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
            R.drawable.ic_launcher_background);

    // generate one texture pointer
    gl.glGenTextures(1, textures, 0);
    // ...and bind it to our array
    gl.glBindTexture(GL10.GL_TEXTURE_2D, textures[0]);

    // create nearest filtered texture
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER,
            GL10.GL_LINEAR);

    // Use Android GLUtils to specify a two-dimensional texture image from
    // our bitmap
    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);

    // Clean up
    bitmap.recycle();
}
 
Example 3
Source File: Model3D.java    From augmentedreality with Apache License 2.0 6 votes vote down vote up
@Override
public void init(GL10 gl){
	int[]  tmpTextureID = new int[1];

	Iterator<Material> materialI = model.getMaterials().values().iterator();
	while (materialI.hasNext()) {
		Material material = (Material) materialI.next();
		if(material.hasTexture()) {

			gl.glGenTextures(1, tmpTextureID, 0);
			gl.glBindTexture(GL10.GL_TEXTURE_2D, tmpTextureID[0]);
			textureIDs.put(material, tmpTextureID[0]);
			GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, material.getTexture(),0);
			material.getTexture().recycle();
			gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
			gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR); 
		}
	}
}
 
Example 4
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private int createTargetTexture(GL10 gl, int width, int height) {
            int texture;
            int[] textures = new int[1];
            gl.glGenTextures(1, textures, 0);
            texture = textures[0];
            gl.glBindTexture(GL10.GL_TEXTURE_2D, texture);
            gl.glTexImage2D(GL10.GL_TEXTURE_2D, 0, GL10.GL_RGBA, width, height, 0,
                    GL10.GL_RGBA, GL10.GL_UNSIGNED_BYTE, null);
            gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
                    GL10.GL_NEAREST);
            gl.glTexParameterf(GL10.GL_TEXTURE_2D,
                    GL10.GL_TEXTURE_MAG_FILTER,
                    GL10.GL_LINEAR);
            gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
                    GL10.GL_REPEAT);
            gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
                    GL10.GL_REPEAT);
;            return texture;
        }
 
Example 5
Source File: PLHotspot.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
/**render methods*/

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer)
{
	this.calculateCoords(gl);
	
	List<PLITexture> textures = this.getTextures();
	int textureId = (textures.size() > 0 ? textures.get(0).getTextureId(gl) : 0);
	if(textureId == 0 || mVertexsBuffer == null || mTextureCoordsBuffer == null)
		return;
	
	gl.glEnable(GL10.GL_TEXTURE_2D);
	
	PLIView view = renderer.getInternalView();
	gl.glColor4f(1.0f, 1.0f, 1.0f, (view != null && view.isValidForTransition()) || this.getTouchStatus() == PLSceneElementTouchStatus.PLSceneElementTouchStatusOut ? this.getAlpha() : mOverAlpha);
	
	gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexsBuffer);
	gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureCoordsBuffer);
	gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
	
	gl.glEnable(GL10.GL_CULL_FACE);
	gl.glCullFace(GL10.GL_FRONT);
	gl.glShadeModel(GL10.GL_SMOOTH);
	
	gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);
	
	gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
	
	gl.glDisable(GL10.GL_TEXTURE_2D);
	gl.glDisable(GL10.GL_BLEND);
	gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
	gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
 
Example 6
Source File: PLCubicPanorama.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
protected boolean bindTextureByIndex(GL10 gl, int index)
{
	boolean result = false;
	try
	{
		PLITexture texture = this.getTextures()[index];
		if(texture != null && texture.getTextureId(gl) != 0)
		{
			gl.glBindTexture(GL10.GL_TEXTURE_2D, texture.getTextureId(gl));
			result = true;
            if(this.getPreviewTextures()[index] != null)
            	this.removePreviewTextureAtIndex(index, true);
		}
		else
		{
			texture = this.getPreviewTextures()[index];
			if(texture != null && texture.getTextureId(gl) != 0)
			{
				gl.glBindTexture(GL10.GL_TEXTURE_2D, texture.getTextureId(gl));
				result = true;
			}
		}
	}
	catch(Throwable e)
	{
		PLLog.error("PLCubicPanorama::bindTextureByIndex", e);
	}
	return result;
}
 
Example 7
Source File: PLSphericalPanorama.java    From PanoramaGL with Apache License 2.0 5 votes vote down vote up
/**render methods*/

@Override
public void internalRender(GL10 gl, PLIRenderer renderer)
{
	PLITexture previewTexture = this.getPreviewTextures()[0], texture = this.getTextures()[0];
    
	boolean textureIsValid = (texture != null && texture.getTextureId(gl) != 0);
    
    if(textureIsValid || (previewTexture != null && previewTexture.getTextureId(gl) != 0))
    {
    	gl.glEnable(GL10.GL_TEXTURE_2D);
    	
    	int divs;
    	
	    if(textureIsValid)
	    {
	    	divs = this.getDivs();
	        gl.glBindTexture(GL10.GL_TEXTURE_2D, texture.getTextureId(gl));
	        if(previewTexture != null)
	            this.removePreviewTextureAtIndex(0, true);
	    }
	    else
	    {
	    	divs = this.getPreviewDivs();
	    	gl.glBindTexture(GL10.GL_TEXTURE_2D, previewTexture.getTextureId(gl));
	    }
	    
	    GLUES.gluSphere(gl, this.getQuadric(), PLConstants.kPanoramaRadius, divs, divs);
		
	    gl.glDisable(GL10.GL_TEXTURE_2D);
    }
}
 
Example 8
Source File: CubeMapActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private int generateCubeMap(GL10 gl, int[] resourceIds) {
    checkGLError(gl);
    int[] ids = new int[1];
    gl.glGenTextures(1, ids, 0);
    int cubeMapTextureId = ids[0];
    gl.glBindTexture(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP, cubeMapTextureId);
    gl.glTexParameterf(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP,
            GL10.GL_TEXTURE_MIN_FILTER, GL10.GL_LINEAR);
    gl.glTexParameterf(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP,
            GL10.GL_TEXTURE_MAG_FILTER, GL10.GL_LINEAR);

    for (int face = 0; face < 6; face++) {
        InputStream is = getResources().openRawResource(resourceIds[face]);
        Bitmap bitmap;
        try {
            bitmap = BitmapFactory.decodeStream(is);
        } finally {
            try {
                is.close();
            } catch(IOException e) {
                Log.e("CubeMap", "Could not decode texture for face " + Integer.toString(face));
            }
        }
        GLUtils.texImage2D(GL11ExtensionPack.GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0,
                bitmap, 0);
        bitmap.recycle();
    }
    checkGLError(gl);
    return cubeMapTextureId;
}
 
Example 9
Source File: TGAGLSurfaceView.java    From TGAReader with MIT License 5 votes vote down vote up
private void draw(GL10 gl, int texture) {
	
	gl.glEnable(GL_TEXTURE_2D);
	gl.glActiveTexture(GL_TEXTURE0);
	gl.glBindTexture(GL_TEXTURE_2D, texture);
	
	// front
	gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);
	// back
	gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 4, 4);
	
	gl.glDisable(GL_TEXTURE_2D);
}
 
Example 10
Source File: PLHotspot.java    From panoramagl with Apache License 2.0 5 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    this.calculateCoords(gl);

    List<PLITexture> textures = this.getTextures();
    int textureId = (textures.size() > 0 ? textures.get(0).getTextureId(gl) : 0);
    if (textureId == 0 || mVertexsBuffer == null || mTextureCoordsBuffer == null)
        return;

    gl.glEnable(GL10.GL_TEXTURE_2D);

    PLIView view = renderer.getInternalView();
    gl.glColor4f(1.0f, 1.0f, 1.0f, (view != null && view.isValidForTransition()) || this.getTouchStatus() == PLSceneElementTouchStatus.PLSceneElementTouchStatusOut ? this.getAlpha() : mOverAlpha);

    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexsBuffer);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mTextureCoordsBuffer);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glEnable(GL10.GL_CULL_FACE);
    gl.glCullFace(GL10.GL_FRONT);
    gl.glShadeModel(GL10.GL_SMOOTH);

    gl.glBindTexture(GL10.GL_TEXTURE_2D, textureId);

    gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, 4);

    gl.glDisable(GL10.GL_TEXTURE_2D);
    gl.glDisable(GL10.GL_BLEND);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
 
Example 11
Source File: TexCubeSmallGLUT.java    From opengl with Apache License 2.0 5 votes vote down vote up
void draw(GL10 gl) {
if (texEnabled) {
    gl.glEnable(GL10.GL_TEXTURE_2D);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mCoordBuffer);
}

super.draw(gl);

if (texEnabled) {
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
    gl.glDisable(GL10.GL_TEXTURE_2D);
}
   }
 
Example 12
Source File: PLCylindricalPanorama.java    From panoramagl with Apache License 2.0 5 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    PLITexture previewTexture = this.getPreviewTextures()[0], texture = this.getTextures()[0];

    boolean textureIsValid = (texture != null && texture.getTextureId(gl) != 0);

    if (textureIsValid || (previewTexture != null && previewTexture.getTextureId(gl) != 0)) {
        gl.glEnable(GL10.GL_TEXTURE_2D);

        int divs;

        if (textureIsValid) {
            divs = this.getDivs();
            gl.glBindTexture(GL10.GL_TEXTURE_2D, texture.getTextureId(gl));
            if (previewTexture != null)
                this.removePreviewTextureAtIndex(0, true);
        } else {
            divs = this.getPreviewDivs();
            gl.glBindTexture(GL10.GL_TEXTURE_2D, previewTexture.getTextureId(gl));
        }

        gl.glTranslatef(0.0f, 0.0f, -mHalfHeight);

        GLUES.gluCylinder(gl, this.getQuadric(), PLConstants.kPanoramaRadius, PLConstants.kPanoramaRadius, mHeight, divs, divs);

        gl.glTranslatef(0.0f, 0.0f, mHalfHeight);

        gl.glDisable(GL10.GL_TEXTURE_2D);
    }
}
 
Example 13
Source File: FrameBufferObjectActivity.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
private void drawOnscreen(GL10 gl, int width, int height) {
    gl.glViewport(0, 0, width, height);
    float ratio = (float) width / height;
    gl.glMatrixMode(GL10.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustumf(-ratio, ratio, -1, 1, 3, 7);

    gl.glClearColor(0,0,1,0);
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTargetTexture);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glActiveTexture(GL10.GL_TEXTURE0);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);

    gl.glRotatef(angle, 0, 0, 1.0f);

    mTriangle.draw(gl);

    // Restore default state so the other renderer is not affected.

    gl.glBindTexture(GL10.GL_TEXTURE_2D, 0);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDisableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
}
 
Example 14
Source File: QuadRenderSystem.java    From BobEngine with GNU Lesser General Public License v2.1 4 votes vote down vote up
/**
 * Render the quads in this system.
 *
 * @param gl OpenGL ES 1 object.
 * @param layer layer to render.
 */
public void render(GL10 gl, int layer) {
	boolean obFound = false;
	int gID;
	int numIndices = 0;    // The number of indices for all objects

	if (graphic == null) {
		gID = 0;
	} else {
		gID = graphic.id;
	}

	for (int i = 0; i < numQuads; i++) {
		Transformation t = quads.get(i).getTransformation();
		GraphicAreaTransformation g = quads.get(i).getGraphicAreaTransformation();

		if (t.getLayer() == layer && onScreen(t, getRoom()) && Transform.getRealVisibility(t)) {
			if (!obFound) {
				vertexBuffer.clear();
				textureBuffer.clear();

				vertexBuffer.position(0);
				textureBuffer.position(0);
				indexBuffer[layer].position(0);

				obFound = true;
			}

			vertexBuffer.put(getVertices(t));
			textureBuffer.put(getVertices(g));
			numIndices += INDICES;
		}
	}

	if (obFound) {
		if (numIndices != lastIndex[layer]) {
			if (numIndices > indices.length) {
				indices = new short[numIndices + 1];
			}

			for (int i = 0; i < numIndices; i += 6) {
				indices[i + 0] = (short) (((i / 6) * 4) + 0);
				indices[i + 1] = (short) (((i / 6) * 4) + 1);
				indices[i + 2] = (short) (((i / 6) * 4) + 2);
				indices[i + 3] = (short) (((i / 6) * 4) + 1);
				indices[i + 4] = (short) (((i / 6) * 4) + 2);
				indices[i + 5] = (short) (((i / 6) * 4) + 3);
			}

			indexBuffer[layer].clear();
			indexBuffer[layer].put(indices);
			lastIndex[layer] = numIndices;
		}

		vertexBuffer.position(0);
		textureBuffer.position(0);
		indexBuffer[layer].position(0);

		// Add color
		gl.glColor4f(red[layer] * alpha[layer], green[layer] * alpha[layer], blue[layer] * alpha[layer], alpha[layer]);

		// Bind the texture
		gl.glBindTexture(GL11.GL_TEXTURE_2D, gID);

		// Point to our vertex and texture buffers
		gl.glVertexPointer(2, GL10.GL_FLOAT, 0, vertexBuffer);
		gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, textureBuffer);

		// Draw the vertices as triangles
		gl.glDrawElements(GL10.GL_TRIANGLES, numIndices, GL10.GL_UNSIGNED_SHORT, indexBuffer[layer]);
	}
}
 
Example 15
Source File: TriangleRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onDrawFrame(GL10 gl) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    gl.glDisable(GL10.GL_DITHER);

    gl.glTexEnvx(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_MODULATE);

    /*
     * Usually, the first thing one might want to do is to clear
     * the screen. The most efficient way of doing this is to use
     * glClear().
     */

    gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);

    /*
     * Now we're ready to draw some 3D objects
     */

    gl.glMatrixMode(GL10.GL_MODELVIEW);
    gl.glLoadIdentity();

    GLU.gluLookAt(gl, 0, 0, -5, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);

    gl.glActiveTexture(GL10.GL_TEXTURE0);
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_S,
            GL10.GL_REPEAT);
    gl.glTexParameterx(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_WRAP_T,
            GL10.GL_REPEAT);

    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);

    gl.glRotatef(angle, 0, 0, 1.0f);

    mTriangle.draw(gl);
}
 
Example 16
Source File: Texture.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public static Texture createTexture(Bitmap bitmap, FlipRenderer renderer, GL10 gl) {
  Texture t = new Texture();
  t.renderer = renderer;

  Assert.assertTrue("bitmap should not be null or recycled",
                    bitmap != null && !bitmap.isRecycled());

  int potW = Integer.highestOneBit(bitmap.getWidth() - 1) << 1;
  int potH = Integer.highestOneBit(bitmap.getHeight() - 1) << 1;

  t.contentWidth = bitmap.getWidth();
  t.contentHeight = bitmap.getHeight();
  t.width = potW;
  t.height = potH;

  if (AphidLog.ENABLE_DEBUG) {
    AphidLog.d("createTexture: %d, %d; POT: %d, %d", bitmap.getWidth(), bitmap.getHeight(), potW,
            potH);
  }

  gl.glGenTextures(1, t.id, 0);
  gl.glBindTexture(GL_TEXTURE_2D, t.id[0]);

  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

  switch (bitmap.getConfig()) {
    case ARGB_8888:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, potW, potH, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case ARGB_4444:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, potW, potH, 0, GL_RGBA,
                      GL_UNSIGNED_SHORT_4_4_4_4, null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case RGB_565:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, potW, potH, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
                      null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case ALPHA_8:
    default:
      throw new RuntimeException(
          "Unrecognized bitmap format for OpenGL texture: " + bitmap.getConfig());
  }

  FlipRenderer.checkError(gl);

  return t;
}
 
Example 17
Source File: SpriteTextRenderer.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    /*
     * By default, OpenGL enables features that improve quality
     * but reduce performance. One might want to tweak that
     * especially on software renderer.
     */
    gl.glDisable(GL10.GL_DITHER);

    /*
     * Some one-time OpenGL initialization can be made here
     * probably based on features of this particular context
     */
    gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT,
            GL10.GL_FASTEST);

    gl.glClearColor(.5f, .5f, .5f, 1);
    gl.glShadeModel(GL10.GL_SMOOTH);
    gl.glEnable(GL10.GL_DEPTH_TEST);
    gl.glEnable(GL10.GL_TEXTURE_2D);

    /*
     * Create our texture. This has to be done each time the
     * surface is created.
     */

    int[] textures = new int[1];
    gl.glGenTextures(1, textures, 0);

    mTextureID = textures[0];
    gl.glBindTexture(GL10.GL_TEXTURE_2D, mTextureID);

    gl.glTexParameterf(GL10.GL_TEXTURE_2D, GL10.GL_TEXTURE_MIN_FILTER,
            GL10.GL_NEAREST);
    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);

    gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE,
            GL10.GL_REPLACE);

    InputStream is = mContext.getResources()
            .openRawResource(R.raw.robot);
    Bitmap bitmap;
    try {
        bitmap = BitmapFactory.decodeStream(is);
    } finally {
        try {
            is.close();
        } catch(IOException e) {
            // Ignore.
        }
    }

    GLUtils.texImage2D(GL10.GL_TEXTURE_2D, 0, bitmap, 0);
    bitmap.recycle();

    if (mLabels != null) {
        mLabels.shutdown(gl);
    } else {
        mLabels = new LabelMaker(true, 256, 64);
    }
    mLabels.initialize(gl);
    mLabels.beginAdding(gl);
    mLabelA = mLabels.add(gl, "A", mLabelPaint);
    mLabelB = mLabels.add(gl, "B", mLabelPaint);
    mLabelC = mLabels.add(gl, "C", mLabelPaint);
    mLabelMsPF = mLabels.add(gl, "ms/f", mLabelPaint);
    mLabels.endAdding(gl);

    if (mNumericSprite != null) {
        mNumericSprite.shutdown(gl);
    } else {
        mNumericSprite = new NumericSprite();
    }
    mNumericSprite.initialize(gl, mLabelPaint);
}
 
Example 18
Source File: Texture.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public static Texture createTexture(Bitmap bitmap, FlipRenderer renderer, GL10 gl) {
  Texture t = new Texture();
  t.renderer = renderer;

  Assert.assertTrue("bitmap should not be null or recycled",
                    bitmap != null && !bitmap.isRecycled());

  int potW = Integer.highestOneBit(bitmap.getWidth() - 1) << 1;
  int potH = Integer.highestOneBit(bitmap.getHeight() - 1) << 1;

  t.contentWidth = bitmap.getWidth();
  t.contentHeight = bitmap.getHeight();
  t.width = potW;
  t.height = potH;

  if (AphidLog.ENABLE_DEBUG) {
    AphidLog.d("createTexture: %d, %d; POT: %d, %d", bitmap.getWidth(), bitmap.getHeight(), potW,
            potH);
  }

  gl.glGenTextures(1, t.id, 0);
  gl.glBindTexture(GL_TEXTURE_2D, t.id[0]);

  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  gl.glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

  switch (bitmap.getConfig()) {
    case ARGB_8888:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, potW, potH, 0, GL_RGBA, GL_UNSIGNED_BYTE, null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case ARGB_4444:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, potW, potH, 0, GL_RGBA,
                      GL_UNSIGNED_SHORT_4_4_4_4, null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case RGB_565:
      gl.glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, potW, potH, 0, GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
                      null);
      GLUtils.texSubImage2D(GL_TEXTURE_2D, 0, 0, 0, bitmap);
      break;
    case ALPHA_8:
    default:
      throw new RuntimeException(
          "Unrecognized bitmap format for OpenGL texture: " + bitmap.getConfig());
  }

  FlipRenderer.checkError(gl);

  return t;
}
 
Example 19
Source File: PLSpherical2Panorama.java    From panoramagl with Apache License 2.0 4 votes vote down vote up
/**
 * render methods
 */

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer) {
    PLITexture previewTexture = this.getPreviewTextures()[0];
    PLITexture[] textures = this.getTextures();
    PLITexture frontTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationFront.ordinal()];
    PLITexture backTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationBack.ordinal()];
    PLITexture leftTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationLeft.ordinal()];
    PLITexture rightTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationRight.ordinal()];

    boolean frontTextureIsValid = (frontTexture != null && frontTexture.getTextureId(gl) != 0);
    boolean backTextureIsValid = (backTexture != null && backTexture.getTextureId(gl) != 0);
    boolean leftTextureIsValid = (leftTexture != null && leftTexture.getTextureId(gl) != 0);
    boolean rightTextureIsValid = (rightTexture != null && rightTexture.getTextureId(gl) != 0);

    if (frontTextureIsValid || backTextureIsValid || leftTextureIsValid || rightTextureIsValid || (previewTexture != null && previewTexture.getTextureId(gl) != 0)) {
        gl.glEnable(GL10.GL_TEXTURE_2D);

        GLUquadric quadratic = this.getQuadric();
        float radius = PLConstants.kPanoramaRadius;
        int halfDivs = this.getDivs() / 2, quarterDivs = halfDivs / 2;

        if (previewTexture != null) {
            if (frontTextureIsValid && backTextureIsValid && leftTextureIsValid && rightTextureIsValid)
                this.removePreviewTextureAtIndex(0, true);
            else {
                int previewDivs = this.getPreviewDivs();
                gl.glBindTexture(GL10.GL_TEXTURE_2D, previewTexture.getTextureId(gl));
                GLUES.gluSphere(gl, quadratic, radius, previewDivs, previewDivs);
            }
        }

        // Front Face
        if (frontTextureIsValid) {
            gl.glBindTexture(GL10.GL_TEXTURE_2D, frontTexture.getTextureId(gl));
            GLUES.glu3DArc(gl, quadratic, PLConstants.kPI8, -PLConstants.kPI16, false, radius, quarterDivs, quarterDivs);
        }

        // Back Face
        if (backTextureIsValid) {
            gl.glBindTexture(GL10.GL_TEXTURE_2D, backTexture.getTextureId(gl));
            GLUES.glu3DArc(gl, quadratic, PLConstants.kPI8, -PLConstants.kPI16, true, radius, quarterDivs, quarterDivs);
        }

        // Left Face
        if (leftTextureIsValid) {
            gl.glBindTexture(GL10.GL_TEXTURE_2D, leftTexture.getTextureId(gl));
            GLUES.gluHemisphere(gl, quadratic, false, radius, halfDivs, halfDivs);
        }

        //Right Face
        if (rightTextureIsValid) {
            gl.glBindTexture(GL10.GL_TEXTURE_2D, rightTexture.getTextureId(gl));
            GLUES.gluHemisphere(gl, quadratic, true, radius, halfDivs, halfDivs);
        }

        gl.glDisable(GL10.GL_TEXTURE_2D);
    }
}
 
Example 20
Source File: PLSpherical2Panorama.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
/**render methods*/

@Override
protected void internalRender(GL10 gl, PLIRenderer renderer)
{
	PLITexture previewTexture = this.getPreviewTextures()[0];
	PLITexture[] textures = this.getTextures();
	PLITexture frontTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationFront.ordinal()];
	PLITexture backTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationBack.ordinal()];
	PLITexture leftTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationLeft.ordinal()];
	PLITexture rightTexture = textures[PLSpherical2FaceOrientation.PLSpherical2FaceOrientationRight.ordinal()];
	
    boolean frontTextureIsValid = (frontTexture != null && frontTexture.getTextureId(gl) != 0);
    boolean backTextureIsValid = (backTexture != null && backTexture.getTextureId(gl) != 0);
    boolean leftTextureIsValid = (leftTexture != null && leftTexture.getTextureId(gl) != 0);
    boolean rightTextureIsValid = (rightTexture != null && rightTexture.getTextureId(gl) != 0);
    
    if(frontTextureIsValid || backTextureIsValid || leftTextureIsValid || rightTextureIsValid || (previewTexture != null && previewTexture.getTextureId(gl) != 0))
    {
    	gl.glEnable(GL10.GL_TEXTURE_2D);
    	
    	GLUquadric quadratic = this.getQuadric();
	    float radius = PLConstants.kPanoramaRadius;
	    int halfDivs = this.getDivs() / 2, quarterDivs = halfDivs / 2;
	    
	    if(previewTexture != null)
	    {
	        if(frontTextureIsValid && backTextureIsValid && leftTextureIsValid && rightTextureIsValid)
	            this.removePreviewTextureAtIndex(0, true);
	        else
	        {
	        	int previewDivs = this.getPreviewDivs();
	            gl.glBindTexture(GL10.GL_TEXTURE_2D, previewTexture.getTextureId(gl));
	            GLUES.gluSphere(gl, quadratic, radius, previewDivs, previewDivs);
	        }
	    }
	    
	    // Front Face
	    if(frontTextureIsValid)
	    {
	        gl.glBindTexture(GL10.GL_TEXTURE_2D, frontTexture.getTextureId(gl));
	        GLUES.glu3DArc(gl, quadratic, PLConstants.kPI8, -PLConstants.kPI16, false, radius, quarterDivs, quarterDivs);
	    }
	    
	    // Back Face
	    if(backTextureIsValid)
	    {
	        gl.glBindTexture(GL10.GL_TEXTURE_2D, backTexture.getTextureId(gl));
	        GLUES.glu3DArc(gl, quadratic, PLConstants.kPI8, -PLConstants.kPI16, true, radius, quarterDivs, quarterDivs);
	    }
	    
	    // Left Face
	    if(leftTextureIsValid)
	    {
	        gl.glBindTexture(GL10.GL_TEXTURE_2D, leftTexture.getTextureId(gl));
	        GLUES.gluHemisphere(gl, quadratic, false, radius, halfDivs, halfDivs);
	    }
	    
	    //Right Face
	    if(rightTextureIsValid)
	    {
	        gl.glBindTexture(GL10.GL_TEXTURE_2D, rightTexture.getTextureId(gl));
	        GLUES.gluHemisphere(gl, quadratic, true, radius, halfDivs, halfDivs);
	    }
	    
		gl.glDisable(GL10.GL_TEXTURE_2D);
    }
}