06 May 2013, 17:35
Mark sp_pragsmall

Mark Ortiz (2 posts)

Hi. I’ve enjoyed working through the book. Thanks for writing it.

I’m trying to do my own project which is mostly just 2D.

I’m stuck making grayscale bitmaps my own color. The book uses a grayscale bitmap, and decides it’s color in the particle app. I’d like to be able to do the same thing (but not particles)

Would it be possible for anyone to show me how to put the “particle_texture.png” on the hockey table, so I can set the color myself? I’ll then be able to use that knowledge to do what I really want to do.

EDIT: I probably should explain what I want to achieve - I have a color photo, that I’ve used photoshop to split into the 3 RGB channels. This gives 3 grayscale bitmaps. I’m trying to animate them combining. So one would be red, the other green, the other blue. When they reach the same position as each other, the full color photo is revealed. The coloring would need to be additive for this to work.

Thanks for your help!

10 May 2013, 18:24
Mark sp_pragsmall

Mark Ortiz (2 posts)

Anyone? Anyone? Bueller?

I’ve sorted this myself in the end (always more satisfactory). I hate coming across orphan questions on the web, so here’s what to do for any other future searchers.

In the load texture: gl.glTexEnvf(GL10.GL_TEXTURE_ENV, GL10.GL_TEXTURE_ENV_MODE, GL10.GL_MODULATE);

In the draw:

gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f); //RED

11 May 2013, 04:37
Generic-user-small

Kevin Brothaler (36 posts)

I’ve been away overseas, so my apologies for not getting to this sooner.

Does that code also work if you’re using OpenGL ES 2.0? With a shader, it would be very similar to the way the particles are done. You could pass in a uniform like this:

uniform vec3 u_Color;

In the main body, you’d apply the color as follows:

gl_FragColor = vec4(u_Color, 1.0) * texture2D(u_TextureUnit, v_TexCoord);

Where u_TextureUnit is the bound texture unit, and v_TexCoord is the texture coordinate coming from your vertex data. Let me know if this helps out as well.

  You must be logged in to comment