PDA

View Full Version : Alpha blend problem in Age of empires mod



glBomb
09-30-2006, 03:05 AM
I am trying to make this mod for Age of Empires & here you can see a isometric map/terrain & a castle on it. Now the art is stored in rectangular pictures with the white regions being masked to get irregular outlines. To mask the white regions i gave those pixels an alpha of 0 & the remaining colors an alpha=255 & converted them to textures in Orthographic view. The tiles are also stored similarly .

http://img220.imageshack.us/img220/9185/postitns9.th.jpg (http://img220.imageshack.us/my.php?image=postitns9.jpg)

I have also added lights by using a white light texture as can be seen at the top left of the castle(LEFT PIC)
here are the steps i follow to draw the scene:-

1. glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Nice perspective correction


glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // Set The Blending Function For Translucency

glEnable(GL_TEXTURE_2D); // Allow 2D textures
glEnable(GL_BLEND);

//draw terrain textures inside glBegin().....glEnd() as textured quads

2.Now draw the castle in solid shape
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glBindTexture(GL_TEXTURE_2D, textures[2]);//castle


glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);glVertex2i(100,100); //tl
glTexCoord2f(1, 0.0f);glVertex2i(400, 100); //tr
glTexCoord2f(1, 1); glVertex2i(400, 400); //br
glTexCoord2f(0.0f, 1); glVertex2i(100, 400); //ULTA AAYEGA!! - bl
glEnd();


3.Now draw the light map blending it with whats already in buffer


*-->> //glColor4ub(255,0,0,255);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glBindTexture(GL_TEXTURE_2D, textures[1]);//lights

//light map

glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f);glVertex2i(100,100); //tl
glTexCoord2f(1, 0.0f);glVertex2i(150, 100); //tr
glTexCoord2f(1, 1); glVertex2i(150, 150); //br
glTexCoord2f(0.0f, 1); glVertex2i(100, 150); //ULTA AAYEGA!! - bl
glEnd();

4. Swap SDL l buffers

SDL_GL_SwapBuffers( );

This gives me a bright white light ...no problem(LEFT PICTURE)
the trouble starts when i want a red light
Then i use the line

*-->> glColor4ub(255,0,0,255);

at the position shown.THIS SHOULD DRAW THE LIGHT MAP TEXTURE IN RED & BLEND IT TOO...instead the WhOLE SCREEN gOES RED.I want 2D lighting with different colors....what should i do if this does not work.In the Nehe tutorials the chapter 9 on animated stars does the same and acieves colors on grayscale textures like mine.But in my case it floods the whole screen.
(RIGHT PICTURE)
ARE the BLEND FUNCTIONS WRONG ??

PLEASE SOMEBODY HELP!!

Zengar
09-30-2006, 03:36 AM
When you use the vertex command, a bunch of data is submitted to the pipeline: vertex position, color etc. Commands like color, normal and others just write to a state register - meaning that a single color command will affect all vertices that follow it. I guess your problem is setting the color to red, but never resetting it back to white :-) The first pass is drawn white, while all subsequent passes will be red.

glBomb
09-30-2006, 04:12 AM
Thanks a lot .That solved the problem!!