Bump Mapping

29 Sep

I have a problem trying to do the bump mapping texture, when i want to compile my project, this gave an error that says that the function GlActiveTexture is not define.

I tried to include it in the headers like <GL/gl.h> and <GL/glext.h> but it didn’t work, so in a forum gave me the solution and was to do this validation:

PFNGLACTIVETEXTUREPROC glActiveTexture = (PFNGLACTIVETEXTUREPROC) wglGetProcAddress (“glActiveTexture”);


And oddly works.

Shadows – Test 2

28 Sep

Well, like i couldn’t make shadows with the code of the last post, i tried with this one:


but, still without any results, in fact it almost work but the shadows puts over my objects (spheres) and i tried to move them but i couldn’t, so what this wants to do is to analyze the depth, then create a fake object (which is going to be our shadow) then move it to the floor (plane) and then create the real object.

/disable the color mask
    glDepthMask(GL_FALSE); //disable the depth mask

    glEnable(GL_STENCIL_TEST); //enable the stencil testing

    glStencilFunc(GL_ALWAYS, 1, 0xFFFFFFFF);
    glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE); //set
 the stencil buffer to replace our next lot of data

    bench(); //set the data plane to be replaced

    glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); //enable
 the color mask
    glDepthMask(GL_TRUE); //enable the depth mask

    glStencilFunc(GL_EQUAL, 1, 0xFFFFFFFF);
    glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); //set the stencil
 buffer to keep our next lot of data

    glDisable(GL_TEXTURE_2D); //disable texturing of the 
    glDisable(GL_DEPTH_TEST); //disable depth testing of the
    glScalef(1.0f, -1.0f, 1.0f); //flip the shadow vertically

    glTranslatef(0,2,0); //translate the shadow onto our 
drawing plane
    glRotatef(angle,0,1,0); //rotate the shadow accordingly

    glColor4f(0,0,0,1); //color the shadow black
    square(); //draw our square as the shadow
    glEnable(GL_DEPTH_TEST); //enable depth testing
    glEnable(GL_TEXTURE_2D); //enable texturing

    glDisable(GL_STENCIL_TEST); //disable the stencil testing


Shadows – Test 1

28 Sep

I have a non-solved issue with this subject, I tried a lot of code to try this to work, but i couldn’t achieve it.

So, the first code that i try is from this link:


so, what the example tries to do is to create a matrix of shadows, depending on the source of light, the angle and the floor, like this:

/* Create a matrix that will project the desired shadow. */
shadowMatrix(GLfloat shadowMat[4][4],
  GLfloat groundplane[4],
  GLfloat lightpos[4])
  GLfloat dot;

  /* Find dot product between light position vector and ground plane normal. */
  dot = groundplane[X] * lightpos[X] +
    groundplane[Y] * lightpos[Y] +
    groundplane[Z] * lightpos[Z] +
    groundplane[W] * lightpos[W];

  shadowMat[0][0] = dot - lightpos[X] * groundplane[X];
  shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];
  shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];
  shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];

  shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];
  shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];
  shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];
  shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];

  shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];
  shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];
  shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];
  shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];

  shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];
  shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];
  shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];
  shadowMat[3][3] = dot - lightpos[W] * groundplane[W];




27 Sep

the easiest thing to do is the spotlights.

A spotlight is simply a point light source with a small light cone radius. Alternatively, a point light is just a spot light with a 180 degree radius light cone. Set the radius of the light cone by changing the cutoff parameter of the light.

First, we have to put a light in the space :

float Dl[4] = {1.0f, 1.0f, 1.0f, 1.0f };
float Sl[4] = {1.0f, 1.0f, 1.0f, 1.0f };

Then we add the three spotlights:

glLightf (GL_LIGHT1, GL_SPOT_CUTOFF, 75.f);
glLightf (GL_LIGHT1, GL_SPOT_CUTOFF, 45.f);
glLightf (GL_LIGHT1, GL_SPOT_CUTOFF, 15.f);

Before the Spotlights

After the Spotlights


Get every new post delivered to your Inbox.