Spotlight doesn't work with textured polygon
Hi,
I have a problem with combining a spot light with a textured triangle strip. The spot light and the textured triangle strip work well, as long as they are not combined, but as soon as I activate the texture with the glEnable(GL_TEXTURE_2D) command, the spotlight doesn't work anymore. Has anybody an idea, where I have made the mistake? I would be grateful for any hints.
thanks a lot
Heinz
P.S. The actual code I use for texture and lightning is as follows:
void __fastcall TFormMain::SetupLighting()
{
GLfloat MaterialAmbient[] = {0.5, 0.5, 0.5, 1.0};
GLfloat MaterialDiffuse[] = {1.0, 1.0, 1.0, 1.0};
GLfloat MaterialSpecular[] = {1.0, 1.0, 1.0, 1.0};
GLfloat MaterialShininess[] = {50.0};
glMaterialfv(GL_FRONT, GL_AMBIENT, MaterialAmbient);
glMaterialfv(GL_FRONT, GL_DIFFUSE, MaterialDiffuse);
glMaterialfv(GL_FRONT, GL_SPECULAR, MaterialSpecular);
glMaterialfv(GL_FRONT, GL_SHININESS, MaterialShininess);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glShadeModel(GL_SMOOTH);
// set ambient light intensity
GLfloat ambientLight[]={0.5,0.5,0.5,1.0};
glLightfv(GL_LIGHT0,GL_AMBIENT,ambientLight);
// set diffuse light intensity
GLfloat diffuseLight[]={0.8,0.8,0.8,1.0};
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuseLight);
// set specular light intensity
GLfloat specularLight[]={0.5,0.5,0.5,1.0};
glLightfv(GL_LIGHT0,GL_SPECULAR,specularLight);
// set light position
GLfloat lightPos[]={0.0,0.0,60.0,1.0};
glLightfv(GL_LIGHT0,GL_POSITION,lightPos);
// set material properties
GLfloat specularReflection[]={1.0,1.0,1.0,1.0};
glMaterialfv(GL_FRONT, GL_SPECULAR, specularReflection);
glMateriali(GL_FRONT,GL_SHININESS,128);
// set spot light parameters
GLfloat spotDir[]={0.0,0.0,-1.0}; // define spot direction
glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, spotDir);
glLightf(GL_LIGHT0, GL_SPOT_CUTOFF,40.0); // set cutoff angle
glLightf(GL_LIGHT0, GL_SPOT_EXPONENT,7.0); // set focusing strength
glEnable(GL_LIGHT0); // activate the defined light
glEnable(GL_LIGHTING); // enable lighting
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambientLight); // set lighting model
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT,GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_NORMALIZE); // normalize normal vectors
}
//---------------------------------------------------------------------------
void __fastcall TFormMain::SetupTexture()
{
const int texturesize1=512;
bitmap = new Graphics::TBitmap;
bitmap->LoadFromFile("keller2.bmp");
GLubyte bits[texturesize1][texturesize1][4];
for(int i = 0; i < texturesize1; i++)
{
for(int j = 0; j < texturesize1; j++)
{
bits[j][0]= (GLbyte)GetRValue(bitmap->Canvas->Pixels[j]);
bits[j][1]= (GLbyte)GetGValue(bitmap->Canvas->Pixels[j]);
bits[j][2]= (GLbyte)GetBValue(bitmap->Canvas->Pixels[j]);
bits[j][3]= (GLbyte)255;
}
}
glPixelStorei(GL_UNPACK_ALIGNMENT, 4); // specify memory alignment
glGenTextures(1, &texture1);
glBindTexture(GL_TEXTURE_2D, texture1);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texturesize1, texturesize1, 0, GL_RGBA, GL_UNSIGNED_BYTE, bits);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
}
Hi Heinz,
i am havin the same prob, but not with spotlight. I am trying to gets some fonts workin but i cannot change the color of them once i initialize my textures.
somehow i think its the same prob.
hope it helped ;-)))
cherio Woltan
i am havin the same prob, but not with spotlight. I am trying to gets some fonts workin but i cannot change the color of them once i initialize my textures.
somehow i think its the same prob.
hope it helped ;-)))
cherio Woltan
I think your problem is
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
Try switching it to
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
From what I understand from my problem ridden attempts to do opengl lighting and blending, the texture needs to be blended, in a sense, with the trangle it's being put on to show the lighting on that trangle. GL_DECAL puts the texture on the triangle, overwriting anything underneath. GL_MODULATE basically lights the texture based on the trangle "beneath". So, from what I've seen, a texture is never directly lit, the traingle beneath it is, then they are combined. If I'm off, maybe some kind soul will come on here and flame me...
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
Try switching it to
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
From what I understand from my problem ridden attempts to do opengl lighting and blending, the texture needs to be blended, in a sense, with the trangle it's being put on to show the lighting on that trangle. GL_DECAL puts the texture on the triangle, overwriting anything underneath. GL_MODULATE basically lights the texture based on the trangle "beneath". So, from what I've seen, a texture is never directly lit, the traingle beneath it is, then they are combined. If I'm off, maybe some kind soul will come on here and flame me...
Quote:Original post by Brad789
I think your problem is
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
Try switching it to
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
From what I understand from my problem ridden attempts to do opengl lighting and blending, the texture needs to be blended, in a sense, with the trangle it's being put on to show the lighting on that trangle. GL_DECAL puts the texture on the triangle, overwriting anything underneath. GL_MODULATE basically lights the texture based on the trangle "beneath". So, from what I've seen, a texture is never directly lit, the traingle beneath it is, then they are combined. If I'm off, maybe some kind soul will come on here and flame me...
Basically you're right. Of course GL lighting and texturing are 2 different processes. Let's say GL wants to calculate the color for a pixel inside a triangle. Lighting calculates a color for each vertex and intepolates them across the triangle. That is called the primary color. Texturing access the texture and retrieves also a color(texel) based on the texture coordinates. glTexEnvf defines how the final color of the pixel will be calculated.
GL_DECAL: pixel_color=TEXTURE;
GL_MODULATE: pixel_color=PRIMARY_COLOR*TEXTURE
There other modes too of course. So you understand that if you want lighting you need GL_MODULATE.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement