Results 1 to 3 of 3

Thread: Alpha blend problem in Age of empires mod

  1. #1
    Member Newbie
    Join Date
    Jul 2006
    Posts
    39

    Alpha blend problem in Age of empires mod

    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 .



    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!!

  2. #2
    Senior Member OpenGL Pro Zengar's Avatar
    Join Date
    Sep 2001
    Location
    Germany
    Posts
    1,931

    Re: Alpha blend problem in Age of empires mod

    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.

  3. #3
    Member Newbie
    Join Date
    Jul 2006
    Posts
    39

    Re: Alpha blend problem in Age of empires mod

    Thanks a lot .That solved the problem!!

Similar Threads

  1. How to alpha blend PBOs?
    By bsder in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 06-10-2010, 08:34 PM
  2. Multitexturing problem in Age of Empires
    By glBomb in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-19-2006, 07:27 AM
  3. alpha blend with an extra alpha.
    By alh in forum OpenGL ES
    Replies: 2
    Last Post: 01-20-2005, 04:56 AM
  4. alpha blend not working?
    By supagu in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 12-25-2004, 02:17 PM
  5. alpha blend
    By nehh in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 09-27-2002, 02:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean