Archived

This topic is now archived and is closed to further replies.

blah! how to make this red light work...

This topic is 5171 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

//global
GLfloat LightPosition[] = { 0.0f, 0.0f, 2.0f, 1.0f};
GLfloat LightAmbient[] = { 0.5f, 0.5f, 0.5f, 1.0f};
GLfloat LightDiffuse[] = { 1.0f, 0.0f, 0.0f, 1.0f};
//after initializing open gl
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT1,GL_AMBIENT,LightAmbient);
glLightfv(GL_LIGHT1,GL_DIFFUSE,LightDiffuse);
glLightfv(GL_LIGHT1,GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);
//frame function
bool Frame()
{
	if(keys[VK_ADD]) goy-=0.09f;
	if(keys[VK_SUBTRACT]) goy+=0.09f;
	if(keys[VK_UP]) goz+=0.09f;
	if(keys[VK_DOWN]) goz-=0.09f;
	if(keys[VK_LEFT]) gox+=0.09f;
	if(keys[VK_RIGHT]) gox-=0.09f;
	
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	glLightfv( GL_LIGHT1, GL_POSITION, LightPosition );	

	glBindTexture(GL_TEXTURE_2D,texture[0]);

	glTranslatef(gox,goy,goz);
	//glRotatef(gox,1.0f,0.0f,0.0f);
	glRotatef(angle,0.0f,1.0f,0.0f);
	
	DrawPyramid(0.0f,0.0f,0.0f,2.0f,2.0f);

	glTranslatef(2.0f,0.0f,-2.0f);
	glRotatef(angle,0.0f,-1.0f,0.0f);
	DrawPyramid(0.0f,0.0f,0.0f,2.0f,2.0f);

	angle += 1.0f;

	SwapBuffers(opengl.GetHDC());
	return true;
}
i get a really dark scene, my pyramids are drawn (very faint) and you can slightly make out that the textures are in deed being drawn... you can even see a slight bit of red tint (and i mean VERY slight), but its not REALLY red! and i have it set to 1.0f!! i can get the pyramids to light up really bright (not red though)if i set the values in ambient to 1000.0f help?

Share this post


Link to post
Share on other sites
i wrote the draw pyramid function my self

ive changed normals around a lot...


void DrawPyramid(float x,float y,float z,float radius,float height)
{
glBegin(GL_TRIANGLES);
glNormal3f(0.0f,1.0f,1.0f);
glTexCoord2f(0.5f,0.0f);
glVertex3f(x,y+(height/2),z);
glTexCoord2f(1.0f,1.0f);
glVertex3f(x+(radius/2),y-(height/2),z+(radius/2));
glTexCoord2f(0.0f,1.0f);
glVertex3f(x-(radius/2),y-(height/2),z+(radius/2));
glNormal3f(0.0f,1.0f,-1.0f);
glTexCoord2f(0.5f,0.0f);
glVertex3f(x,y+(height/2),z);
glTexCoord2f(1.0f,1.0f);
glVertex3f(x+(radius/2),y-(height/2),z-(radius/2));
glTexCoord2f(0.0f,1.0f);
glVertex3f(x-(radius/2),y-(height/2),z-(radius/2));
glNormal3f(-1.0f,1.0f,0.0f);
glTexCoord2f(0.5f,0.0f);
glVertex3f(x,y+(height/2),z);
glTexCoord2f(1.0f,1.0f);
glVertex3f(x-(radius/2),y-(height/2),z+(radius/2));
glTexCoord2f(0.0f,1.0f);
glVertex3f(x-(radius/2),y-(height/2),z-(radius/2));
glNormal3f(1.0f,1.0f,0.0f);
glTexCoord2f(0.5f,0.0f);
glVertex3f(x,y+(height/2),z);
glTexCoord2f(1.0f,1.0f);
glVertex3f(x+(radius/2),y-(height/2),z+(radius/2));
glTexCoord2f(0.0f,1.0f);
glVertex3f(x+(radius/2),y-(height/2),z-(radius/2));
glEnd();
glBegin(GL_QUADS);
glNormal3f(0.0f,-1.0f,0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(x-(radius/2),y-(height/2),z-(radius/2));
glTexCoord2f(0.0f, 1.0f);
glVertex3f(x+(radius/2),y-(height/2),z-(radius/2));
glTexCoord2f(0.0f, 0.0f);
glVertex3f(x+(radius/2),y-(height/2),z+(radius/2));
glTexCoord2f(1.0f, 0.0f);
glVertex3f(x-(radius/2),y-(height/2),z+(radius/2));
glEnd();
}

Share this post


Link to post
Share on other sites
This might help?
I did a quick pyramid in 3DS Max and exported it to see what the normals would be and here's what it uses:

(This is the whole mesh so there's no confusion)

*MESH {
*TIMEVALUE 0
*MESH_NUMVERTEX 6
*MESH_NUMFACES 8
*MESH_VERTEX_LIST {
*MESH_VERTEX 0 0.0000 0.0000 39.4937
*MESH_VERTEX 1 -50.1266 -49.6203 -39.4937
*MESH_VERTEX 2 50.1266 -49.6203 -39.4937
*MESH_VERTEX 3 50.1266 49.6203 -39.4937
*MESH_VERTEX 4 -50.1266 49.6203 -39.4937
*MESH_VERTEX 5 0.0000 0.0000 -39.4937
}
*MESH_FACE_LIST {
*MESH_FACE 0: A: 0 B: 1 C: 2 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 3 *MESH_MTLID 0
*MESH_FACE 1: A: 0 B: 2 C: 3 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 2 *MESH_MTLID 0
*MESH_FACE 2: A: 0 B: 3 C: 4 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 5 *MESH_MTLID 0
*MESH_FACE 3: A: 0 B: 4 C: 1 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 6 *MESH_MTLID 0
*MESH_FACE 4: A: 1 B: 5 C: 2 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 4 *MESH_MTLID 0
*MESH_FACE 5: A: 2 B: 5 C: 3 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 4 *MESH_MTLID 0
*MESH_FACE 6: A: 3 B: 5 C: 4 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 4 *MESH_MTLID 0
*MESH_FACE 7: A: 4 B: 5 C: 1 AB: 1 BC: 1 CA: 1 *MESH_SMOOTHING 4 *MESH_MTLID 0
}
*MESH_NUMTVERTEX 0
*MESH_NUMCVERTEX 0
*MESH_NORMALS {
*MESH_FACENORMAL 0 0.0000 -0.8468 0.5319
*MESH_VERTEXNORMAL 0 0.0000 -0.8468 0.5319
*MESH_VERTEXNORMAL 1 0.0000 -0.8468 0.5319
*MESH_VERTEXNORMAL 2 0.0000 -0.8468 0.5319
*MESH_FACENORMAL 1 0.8443 0.0000 0.5358
*MESH_VERTEXNORMAL 0 0.8443 0.0000 0.5358
*MESH_VERTEXNORMAL 2 0.8443 0.0000 0.5358
*MESH_VERTEXNORMAL 3 0.8443 0.0000 0.5358
*MESH_FACENORMAL 2 0.0000 0.8468 0.5319
*MESH_VERTEXNORMAL 0 0.0000 0.8468 0.5319
*MESH_VERTEXNORMAL 3 0.0000 0.8468 0.5319
*MESH_VERTEXNORMAL 4 0.0000 0.8468 0.5319
*MESH_FACENORMAL 3 -0.8443 0.0000 0.5358
*MESH_VERTEXNORMAL 0 -0.8443 0.0000 0.5358
*MESH_VERTEXNORMAL 4 -0.8443 0.0000 0.5358
*MESH_VERTEXNORMAL 1 -0.8443 0.0000 0.5358
*MESH_FACENORMAL 4 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 1 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 5 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 2 0.0000 0.0000 -1.0000
*MESH_FACENORMAL 5 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 2 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 5 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 3 0.0000 0.0000 -1.0000
*MESH_FACENORMAL 6 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 3 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 5 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 4 0.0000 0.0000 -1.0000
*MESH_FACENORMAL 7 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 4 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 5 0.0000 0.0000 -1.0000
*MESH_VERTEXNORMAL 1 0.0000 0.0000 -1.0000
}
}


EDIT
Why would I complain about that? If it works then it's fine!

-UltimaX-

"You wished for a white christmas... Now go shovel your wishes!"

[edited by - UltimaX on October 14, 2003 9:42:35 PM]

Share this post


Link to post
Share on other sites
actually im pretty sure my normals are correct, i just changed one to opposite (-1) and the red tint wasnt on that face... changed it back, and the red tint was back

something isnt making the light shine on the faces, cuz if i go inside the pyramid, its also not lit...

also, if i use the default light, without changing its parameters (GL_LIGHT0) everything lights correctly, confirming that my normals are ok..

Share this post


Link to post
Share on other sites
Your light is not a directional light (position.w is != 0). Thus, all the different light fall-off terms will apply. However, you don''t configure them.

Try making the light a normalized vector, with 0 in the w part. That would make the light directional. That, plus enabling COLOR_MATERIAL if you use colors, would probably help. Take a look in the red book, or the OpenGL spec, for the other lighting parameters you may need to set for it to work right.

Share this post


Link to post
Share on other sites
dangit, nothing is working!

could someone show me a working example of lighting a textured pyramid (drawn by primitive functions, not a model) with a red light lighting up the faces as it spins...

Share this post


Link to post
Share on other sites
actually i spoke too soon, doesnt work...


bool Init()
{
opengl.EnableOpenGL(myapp.GetHwnd());
opengl.ResizeOpenGL(myapp.mwidth,myapp.mheight);
opengl.InitOpenGL();
glDisable(GL_LIGHT0);
GLfloat lightambient[] = {0.5f,0.5f,0.5f,1.0f};
GLfloat lightdiffuse[] = {1.0f,0.0f,0.0f,1.0f};
GLfloat lightposition[] = {0.0f,0.0f,2.0f,1.0f};
glLightfv(GL_LIGHT1,GL_AMBIENT,lightambient);
glLightfv(GL_LIGHT1,GL_DIFFUSE,lightdiffuse);
glLightfv(GL_LIGHT1,GL_POSITION,lightposition);
glEnable(GL_LIGHT1);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MODULATE);
myapp.Error(false,"% test",f);
LoadGLTextures();
return true;
}


thats how im initialzing my code (yes, GL_LIGHTING is enabled inside of opengl.InitOpenGL(); LIGHT0 is disabled cuz the open gl class automatically enables it...)

help?

Share this post


Link to post
Share on other sites