Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: dual projected texturing via multitexture on GF2

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    Ukraine Krimea Theodosia
    Posts
    7

    dual projected texturing via multitexture on GF2

    sorry for my english

    have a problem

    how can i correctly use two projected textures (from different points) in 1 pass via multitexture on gf2?
    I tried to do it, bat have problems - works not correct..
    if i use 1 projected texture (for example on unit 0) and 1 cube (or sphere)(on unit 1) - all works good..
    multipass works good too..
    HELP SOMEBODY!
    if needed i can post parts of code..

  2. #2
    Junior Member Regular Contributor
    Join Date
    Aug 2001
    Posts
    204

    Re: dual projected texturing via multitexture on GF2

    Do you change to the current texture unit (glActiveTexture(...) ) when putting the projection matrix on the texture matrix stack and defining the texgen planes?

    kon

  3. #3
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    Ukraine Krimea Theodosia
    Posts
    7

    Re: dual projected texturing via multitexture on GF2

    kon
    code for projector(similar to lst version - can-t send last now):

    //////header
    #include "FastMath.h"
    #include "vector3d.h"
    struct TTexProj
    {
    Vector3<float> Position,ViewPoint,Direction,UPP;
    float aspect,Near,Far,angle;
    bool Started;
    void SetPerspective(float HorAngle,float Aspect,float ZNear, float ZFar);
    void SetLook(Vector3<float> From, Vector3<float> To, Vector3<float> Up);
    void Restore();
    void Look();
    void SetAnchor(float DefCoeff);
    void SetAnchor();
    TTextProj()
    {
    Started=false;
    }
    };
    // implimentation
    #include "TextProjector.h"
    #include <math.h>

    #include <gl\gl.h>
    #include <gl\glu.h>

    void TTexProj::SetPerspective(float HorAngle, // - угол зрения по горизонтали в градусах
    float Aspect, // - отношение вепр. размера окна к горизонтальному
    float ZNear, //
    float ZFar) //

    {
    aspect=Aspect;/// - отношение вертикали к горизонтали
    angle= HorAngle*sqrt(1+aspect*aspect);
    Near=ZNear;
    Far=ZFar;
    }
    //---------------------------------------------------------------------------
    void TTexProj::SetLook(Vector3<float> From, Vector3<float> To, Vector3<float> Up)
    {Vector3<float> a;
    Position=From;
    ViewPoint=To;
    Direction=To-From;
    Direction.Normalize();
    UPP=Up;
    }
    //---------------------------------------------------------------------------
    void TTexProj::Look()
    {
    int oldmatrix;
    glGetIntegerv(GL_MATRIX_MODE,&oldmatrix);

    glMatrixMode(GL_TEXTURE);
    glPushMatrix();
    glLoadIdentity();

    glTranslatef(0.5,0.5,0);
    glScalef(0.5,0.5,1);

    gluPerspective(angle,1/aspect,Near,Far);
    gluLookAt(Position.component[0],
    Position.component[1],
    Position.component[2],
    ViewPoint.component[0],
    ViewPoint.component[1],
    ViewPoint.component[2],
    UPP.component[0],
    UPP.component[1],
    UPP.component[2]);
    glMatrixMode(oldmatrix);

    glEnable(GL_TEXTURE_GEN_S);
    glEnable(GL_TEXTURE_GEN_T);
    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);

    Started=true;
    }
    //---------------------------------------------------------------------------
    void TTexProj::Restore()
    {
    if(Started)
    {
    int curm;
    glGetIntegerv(GL_MATRIX_MODE,&curm);
    glMatrixMode(GL_TEXTURE);
    glPopMatrix();
    glMatrixMode(curm);
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
    Started=false;
    }
    }
    //---------------------------------------------------------------------------
    void TTexProj::SetAnchor()
    {
    GLfloat Splane[] = {1,0,0,0};
    GLfloat Tplane[] = {0,1,0,0};
    glTexGenfv(GL_S,GL_EYE_PLANE,Splane);
    glTexGenfv(GL_T,GL_EYE_PLANE,Tplane);
    }
    //--------------------------------------------------------------------------
    void TTexProj::SetAnchor(float DefCoeff)
    {
    GLfloat Splane[] = {1,0,DefCoeff,0};
    GLfloat Tplane[] = {0,1,DefCoeff,0};
    glTexGenfv(GL_S,GL_EYE_PLANE,Splane);
    glTexGenfv(GL_T,GL_EYE_PLANE,Tplane);
    }
    /// -sorry comments in russian
    in last version i added support for NV_Rectangle textures

    in code where problems it looks like:

    glActiveTextureARB(GL_TEXTURE0_ARB);
    glEnable(texture1tipe);
    glBindTexture(texture1tipe,texture1);
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
    glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_REPLACE);

    RefrProjector.SetPerspective(CamAngle2,1/Aspect2,ZNEAR,ZFAR);
    RefrProjector.SetLook(RefrPos,Zero,Up);
    RefrProjector.SetAnchor(-2);
    RefrProjector.Look();


    glActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(texture2tipe);
    glBindTexture(texture2tipe,texture2);
    glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
    glTexEnvf (GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);

    Projector.SetPerspective(CamAngle,1/Aspect,ZNEAR,ZFAR);
    Projector.SetLook(Down,Zero,Up);
    Projector.SetAnchor(3);
    Projector.Look();

    glDrawElemens(GL_TRIANGLE_STRIP,Elements.GetSize(1 ),GL_UNSIGNED_INT,Elements.GetAddr());

    Projector.Restore();
    glDisable(texture2tipe);

    glActiveTextureARB(GL_TEXTURE0_ARB);
    RefrProjector.Restore();
    glDisable(texture1tipe);

    /////////

    if i use for example cube texturing (reflection_arb) for one of units (with changing texture matrix, pushing and poping it) - all works good.......


    [This message has been edited by cad_andry (edited 04-19-2002).]

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2002
    Location
    Ukraine Krimea Theodosia
    Posts
    7

    Re: dual projected texturing via multitexture on GF2

    are nobody have no answer?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •