Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8587563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:35:56+00:00 2026-06-11T22:35:56+00:00

if i don’t stand in the shadow,the shadow effect look perfect.but when i’m in

  • 0

if i don’t stand in the shadow,the shadow effect look perfect.but when i’m in the shadow,the shadow is gone.I don’t why?

here is my code to realize the shadow effect.

void  CastShadow(SECTOR &sec, float *lp)
{//lp is the relative position to the sec
    unsigned int    i, j, k, jj;
    unsigned int    p1, p2;
    VECTOR          v1, v2;
    float           side;


    for (i=0;i<sec.numplanes;i++)
    {
        side =sec.planes[i].planeeq.a*lp[0]+sec.planes[i].planeeq.b*lp[1]+sec.planes[i].planeeq.c*lp[2]+sec.planes[i].planeeq.d*lp[3];
        if (side>0) 
            sec.planes[i].visible = TRUE;
        else
            sec.planes[i].visible = FALSE;
    }

    glDisable(GL_LIGHTING);
    glDepthMask(GL_FALSE);
    glDepthFunc(GL_LEQUAL);
    glEnable(GL_STENCIL_TEST);
    glColorMask(0, 0, 0, 0);
    glStencilFunc(GL_ALWAYS, 1, 0xffffffff);

    // first pass, stencil operation decreases stencil value
    glFrontFace(GL_CCW);
    glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
    for (i=0; i<sec.numplanes;i++)
    {
        if (sec.planes[i].visible)
            for (j=0;j<3;j++){
                k = sec.planes[i].neigh[j];
                if ((!k) || (!sec.planes[k-1].visible))//如果以第k个点开始的邻边没有相邻平面或者相邻平面不可见
                {
                    // here we have an edge, we must draw a polygon
                    p1 = sec.planes[i].p[j]-1;//邻边的起点
                    jj = (j+1)%3;           
                    p2 = sec.planes[i].p[jj]-1;//邻边的终点

                    //calculate the length of the vector
                    v1.x = (sec.points[p1].vec.x - lp[0])*100;
                    v1.y = (sec.points[p1].vec.y - lp[1])*100;
                    v1.z = (sec.points[p1].vec.z - lp[2])*100;

                    v2.x = (sec.points[p2].vec.x - lp[0])*100;
                    v2.y = (sec.points[p2].vec.y - lp[1])*100;
                    v2.z = (sec.points[p2].vec.z - lp[2])*100;

                    glBegin(GL_TRIANGLE_STRIP);//将光源连到邻边的起点并延长,将光源连到邻边的终点的并延长,最后延长出来的梯形,画了过后模板缓冲区的值加1
                        glVertex3f(sec.points[p1].vec.x,sec.points[p1].vec.y,sec.points[p1].vec.z);
                        glVertex3f(sec.points[p1].vec.x + v1.x,sec.points[p1].vec.y + v1.y,sec.points[p1].vec.z + v1.z);
                        glVertex3f(sec.points[p2].vec.x,sec.points[p2].vec.y,sec.points[p2].vec.z);
                        glVertex3f(sec.points[p2].vec.x + v2.x,sec.points[p2].vec.y + v2.y,sec.points[p2].vec.z + v2.z);
                    glEnd();
                }
            }
    }

    // second pass, stencil operation increases stencil value
    glFrontFace(GL_CW);//这句表示画的多边形,只看到里面
    glStencilOp(GL_KEEP, GL_KEEP, GL_DECR);
    for (i=0; i<sec.numplanes;i++){
        if (sec.planes[i].visible)
            for (j=0;j<3;j++){
                k = sec.planes[i].neigh[j];
                if ((!k) || (!sec.planes[k-1].visible))//如果以第k个点开始的邻边没有相邻平面或者相邻平面不可见
                {
                    // here we have an edge, we must draw a polygon
                    p1 = sec.planes[i].p[j]-1;//邻边的起点
                    jj = (j+1)%3;           
                    p2 = sec.planes[i].p[jj]-1;//邻边的终点

                    //calculate the length of the vector
                    v1.x = (sec.points[p1].vec.x - lp[0])*100;
                    v1.y = (sec.points[p1].vec.y - lp[1])*100;
                    v1.z = (sec.points[p1].vec.z - lp[2])*100;

                    v2.x = (sec.points[p2].vec.x - lp[0])*100;
                    v2.y = (sec.points[p2].vec.y - lp[1])*100;
                    v2.z = (sec.points[p2].vec.z - lp[2])*100;

                    glBegin(GL_TRIANGLE_STRIP);//将光源连到邻边的起点并延长,将光源连到邻边的终点的并延长,最后延长出来的梯形,画了过后模板缓冲区的值加1
                        glVertex3f(sec.points[p1].vec.x,sec.points[p1].vec.y,sec.points[p1].vec.z);
                        glVertex3f(sec.points[p1].vec.x + v1.x,sec.points[p1].vec.y + v1.y,sec.points[p1].vec.z + v1.z);
                        glVertex3f(sec.points[p2].vec.x,sec.points[p2].vec.y,sec.points[p2].vec.z);
                        glVertex3f(sec.points[p2].vec.x + v2.x,sec.points[p2].vec.y + v2.y,sec.points[p2].vec.z + v2.z);
                    glEnd();
                }
            }
    }

    glFrontFace(GL_CCW);
    glColorMask(1, 1, 1, 1);

    //draw a shadowing rectangle covering the entire screen
    glColor4f(0.0f, 0.0f, 0.0f,0.4f);
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glStencilFunc(GL_NOTEQUAL, 0, 0xffffffff);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
    glPushMatrix();
    glLoadIdentity();
    glBegin(GL_TRIANGLE_STRIP);
        glVertex3f(-0.1f, 0.1f,-0.0010f);
        glVertex3f(-0.1f,-0.1f,-0.0010f);
        glVertex3f( 0.1f, 0.1f,-0.0010f);
        glVertex3f( 0.1f,-0.1f,-0.0010f);
    glEnd();
    glPopMatrix();
    glDisable(GL_BLEND);

    glDepthFunc(GL_LEQUAL);
    glDepthMask(GL_TRUE);
    glEnable(GL_LIGHTING);
    glDisable(GL_STENCIL_TEST);
    glShadeModel(GL_SMOOTH);

}

and the class SECTOR is like this:

class SECTOR
{
public:
    int numpoints;
    int numplanes;
    vector<VERTEX> points;
    vector<PLANE> planes;
    MATERIAL material;
    bool read();
    bool loadtexture();
    bool build();
    bool plane_calc();
    void SetConnectivity();
    SECTOR& SECTOR::subdivide(long depth);
    SECTOR(string str1,string str2):modelfilename(str1),texturefilename(str2)
    {
        numpoints=0;
        numplanes=0;

    }
    SECTOR()
    {
        numpoints=0;
        numplanes=0;

    }

private:
    FILE *modelfilein,*texturefilein;
    string modelfilename,texturefilename;
    char oneline[255];
    UINT texturename;
    AUX_RGBImageRec *TextureImage;
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:35:57+00:00Added an answer on June 11, 2026 at 10:35 pm

    Since you have already handled ‘capping’ the shadow volume at the near clip plane, you probably have a problem with the camera being inside a shadow volume cast by an object which is behind the camera. You can test this out by moving your camera so that it is inside the shadow volume (where the problem occurs) and then rotate the camera such that the object is infront of the near clip plane.

    It is easier to use the ‘depth fail’ algorithm to handle such special cases, although you must be able to compute and render caps for the far ends of shadow volumes. You can get an overview of the differences between shadow volume algorithms on wikipedia.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

don't know better title for this, but here's my code. I have class user
I don't know why, but this code worked for me a month ago... maybe
I don't get to see the source code but the .class file. Can I
Don't think there's much to say, here's my code for (int i = 0;
Don't know a better title but here is what im trying to do. I
Don't know how to frase this but I found this code wich works as
don't know if the title describes anything about what I'm trying to say but
Don't ask me how but I'm in a situation where I have DCPs published
Don't be scared of the extensive code. The problem is general. I just provided
Don't really know how to formulate the title, but it should be pretty obvious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.