android - OpenGL, how to set a monochrome texture to a colored shape? -


I am developing on Android with OpenGL, I have to draw some cubes and I will use my colors with Globular 4F I change. Now, which I want to give a more realistic effect on cubes, so I made a monochromatic 8-bit depth, 64x64 pixel size PNG file. I have loaded on a texture, and this is my problem, which is the way to combine color and texture to get a colorful and textured cubes on the screen?

I am not an expert at OpenGL, I tried to do it:

Make:

  Public zero asignBitmap (GL10GL, bitmap bitmap ) {Int [] Texture = new int [1]; Gl.glGenTextures (1, texture, 0); Amature = texture [0]; Gl.glBindTexture (GL10.GL_TEXTURE_2D, MTexture); Gl.glTexParameterf (GL10.GL_TEXTURE_2D, GL 10.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); GLUtils.texImage2D (GL10.GL_TEXTURE_2D, 0, GL10.GL_ALPHA, Bitmap, 0); Bytebuffer TBB = BitFuffer.Oldright Direct (TexCoors.Length * 4); Tbb.order (ByteOrder.nativeOrder ()); Mtexbuffer = tbb.asFloatBuffer (); For (int i = 0; i <48; i ++) mtexbuffer.put (texCoords [i]); MTexBuffer.position (0); }  

and OnDo:

  Public Zero Draw (GL10GL, Int alpha) {gl.glColor4f (1.0f, 0.0f, 0.0f, 0.5 f); // red gl.glBindTexture (GL10.GL_TEXTURE_2D, mTtexture); Gl.glBlendFunc (GL10.GL_SRC_ALPHA, GL 10.GL_ONE_MINUS_SRC_ALPHA); Gl.glEnable (GL10.GL_TEXTURE_2D); Gl.glEnable (GL10.GL_BLEND); Gl.glEnableClientState (GL10.GL_TEXTURE_COORD_ARRAY); Gl.glTexCoordPointer (2, GL10.GL_FLOAT, 0, Amtexbuffer); // Set face rotation gl.glFrontFace (GL10.GL_CW); // Indicate our buffers gl.glVertexPointer (3, GL10.GL_FLOAT, 0, peak buffer); // Enable top and color state gl.glEnableClientState (GL10.GL_VERTEX_ARRAY); // index buffer information gl.glDrawElements (GL10.GL_TRIANGLES, 36, GL10.GL_UNSIGNED_BYTE, index buffer), sketch as a triangle; // Disable customer status before leaving Gl.glDisableClientState (GL10.GL_VERTEX_ARRAY); Gl.glDisableClientState (GL10.GL_TEXTURE_COORD_ARRAY); Gl.glDisable (GL10.GL_BLEND); Gl.glDisable (GL10.GL_TEXTURE_2D); }  

I'm not sure that I have to use a mixing option, because I do not need transparency, but this is plus :)

When you set texture environment mode, use GL_MODULATE instead of GL_REPLACE. The modular multiplication of interpolated color will be multiplied with the sampled texture color, where the replacement discards the fully-formed color, and replaces it with a sampled textured color.


Comments