Jump to content
  • Advertisement
Sign in to follow this  
tacostev

Help with blending puzzle blocks

This topic is 2977 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all. I've been struggling with this blending issue for a little while and I am sure you guys can point me in the right direction. I'm currently building a puzzle game with different colored blocks. I want to color each block with a different color and then blend in a texture. I can do a glBlendFunc(GL_ONE, GL_ONE) with a solid color and the texture but it's not quite the effect I want. What I'd really like do is color the polygon with a solid color and then throw the texture on top of that as a decal (imagine the texture is a drawing of a four screws or bolts). I think what I need to do is have the two textures, the actual texture and it's mask. With that I could do something like:
glBlendFunc(GL_ONE,GL_ZERO);

//draw the solid color to the verts.

//Load the mask texture
glBlendFunc(GL_DST_COLOR, GL_ZERO);

//draw the mask by blending the source with the destination (white maintains the original color, black removes it)

//Load the actual texture
glBlendFunc(GL_ONE, GL_ONE);

//draw the texture normally


Am I going about this in the right way or am I completely off? I feel like decaling models that are already colored (or even textured) is a pretty common thing but I haven't seen any solid posts on how to do it.

Share this post


Link to post
Share on other sites
Advertisement
If you want to decal a colored object then blending is not really what you want to be messing with. Blending is for transparency or combining objects from different draw calls.

It is certainly possible to have a texture apply on top of a colored object. Do you have any familiarity with using shaders? I don't have much memory of how alpha textures work in the old fixed function pipeline, but I'm certain that it should be possible. I think if you just use the alpha channel of your decal texture it might do what you want by default, but you might need to enable it with some other state variable that I can't remember.

Make the alpha zero in places where you don't want a texture, and have a value in places where you want your texture to appear. This is essentially the "mask" texture you mentioned, although you can combine it into the fourth channel of the original texture instead of having a second texture.

Share this post


Link to post
Share on other sites
@Karwosts I'm kind of curious about this. Does a texture contain alpha data on a per pixel level as well as color data? For instance in a png? I know I can apply an alpha to each vertex of the texture but I wasn't sure if the image itself stored alpha. I'm using the same masking texture NeHe technique from a few years ago so I'm willing to try something new.

Haven't done anything with shaders yet, I should mention this project is using OpenGLES on an IPhone so that limits me in various ways.


@szecs Would this do what I'm looking for with one glDrawArrays call, one glTexCoordPointer call, and one glColorPointer call? That would be incredible.

Do either of you know of a good texture editor I should be using? Thanks for the responses!

Share this post


Link to post
Share on other sites
No, two passes. First with color and no texture, than with texture. How many tiles do you want to draw? I mean are you sure the performance is an issue?

Draw all the non-textured colored tiles in the first pass, than draw the textured tiles in the second pass.

_____________

I use Photoshop 7

Share this post


Link to post
Share on other sites
I'll be rendering up to 6 rings of tiles, 20 per ring, so 120 tiles as most. If that's a problem with 2 or 3 passes per tile I can get it down to half of that by rendering only tiles on the top hemisphere (my block structure creates a circle with only the top half on screen at a time).

Currently with 1 to 2 passes it runs fine so I'm not worried about this being a performance issue at it at all.

Share this post


Link to post
Share on other sites
Er.. did you try that I suggested? It seems that you already use the two pass thing with wrong blending mode. So it would be 2 seconds to modify.

Share this post


Link to post
Share on other sites
Oh sorry, I'm a work and I can't try it out. I'm posting to get some idea things to try when I get home. I'll post here when I get the results.

Share this post


Link to post
Share on other sites
Yes, you can store the alpha per-pixel inside the texture. I don't know exactly how to create this in whatever image software you're using, but if you have two separate images (3 channel color + mask) you can combine them in CPU before you upload the data.

Instead of calling glTexImage2D with a GL_RGB type, you will want a GL_RGBA type (four channels). Then instead of uploading (RGB)(RGB)(RGB) pixel data, you'll upload a fourth data component per pixel (RGBA)(RGBA)(RGBA).

Unfortunately I can't remember at the moment how fixed pipeline treats the alpha component, if it uses it to cause transparency, or if it controls the texture blending.


Share this post


Link to post
Share on other sites
Sorry, my bad.

Anyway do you know this alpha layer stuff? Or texturing and blending are new to you?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!