# OpenGL tile blending problem (with pictures)

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

## Recommended Posts

hey, i'm trying to put together a little tile based editor/game. i'm working on blending tiles using opengl + multitexturing so i dont have to make all the different transitions. this is what my base map looks like: and this is what i want after my second pass (draws grass tile blended with alpha map over water): over the water tile, i would like to draw another grass texture: with a "hole" cut in the middle using an alpha map: i dont think my alpha map is made right. i'm not even sure if i have to save an alpha channel. the white is supposed to show the grass, and the black is supposed to be a hole (or transparent) and show the base water tile under it. is that explained ok? i know its a pretty common question but i haven't been able to get it work by searching around. oh, and let me know if the images don't show up. thanks, Scott

##### Share on other sites
I'm working on the same problem, I believe you'll want to set it up like this:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, RGBAbitmap);//...glEnable(GL_ALPHA_TEST);glAlphaFunc(GL_NOTEQUAL, 1);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

I had this working fine before and it works just how you are expecting but my new code seems to be missing something.

##### Share on other sites
I'm stumped! For some reason my alpha channel in the RGBA bitmap is being ignored. I should be able to narrow down what works in my old code but I can't find a way to compile it in VC 2005 express right now.

##### Share on other sites
i've gotten it to look pretty close, but not quite.

i'm not sure why the color is lighter.. should be the same color as the darker blue bit of water near the bottom right.

void c_map::draw(){    int x, y;        glEnable(GL_TEXTURE_2D);        // first pass    for (y=0;y<6;y++)    {        for (x=0;x<6;x++)        {            glBindTexture(GL_TEXTURE_2D, texture[tile[x][y].tex_id]);            glBegin(GL_QUADS);                glTexCoord2f(0, 1); glVertex2f((x*ts),      (y*ts));                glTexCoord2f(1, 1); glVertex2f((x*ts)+ts,   (y*ts));                glTexCoord2f(1, 0); glVertex2f((x*ts)+ts,   (y*ts)+ts);                glTexCoord2f(0, 0); glVertex2f((x*ts),      (y*ts)+ts);            glEnd();         }    }        // second pass for terrain transitions    glDisable(GL_DEPTH_TEST);    glEnable(GL_BLEND);                    for (y=0;y<6;y++)    {        for (x=0;x<6;x++)        {            if (x==2 && y == 2)            {                glBlendFunc(GL_DST_COLOR, GL_ZERO);                glBindTexture(GL_TEXTURE_2D, alpha[0]);                glBegin(GL_QUADS);                    glTexCoord2f(0, 1); glVertex2f((x*ts),      (y*ts));                    glTexCoord2f(1, 1); glVertex2f((x*ts)+ts,   (y*ts));                    glTexCoord2f(1, 0); glVertex2f((x*ts)+ts,   (y*ts)+ts);                    glTexCoord2f(0, 0); glVertex2f((x*ts),      (y*ts)+ts);                glEnd();                                 glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_DST_COLOR);                glBindTexture(GL_TEXTURE_2D, texture[0]);                glBegin(GL_QUADS);                    glTexCoord2f(0, 1); glVertex2f((x*ts),      (y*ts));                    glTexCoord2f(1, 1); glVertex2f((x*ts)+ts,   (y*ts));                    glTexCoord2f(1, 0); glVertex2f((x*ts)+ts,   (y*ts)+ts);                    glTexCoord2f(0, 0); glVertex2f((x*ts),      (y*ts)+ts);                glEnd();             }        }    }        glDisable(GL_BLEND);    glEnable(GL_DEPTH_TEST);        glDisable(GL_TEXTURE_2D);}

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633761
• Total Posts
3013724
×