|
-
October 25th, 2011, 08:34 AM
#1
model, shade, looksRealistic OpenGL
Dear Friends
I am successfully able to generate a 3D surface by revolving the profiles by 360 degree. Now my 3d model is in red color so the color is so shining I am not able to distinguish various parts in the model. For this I am trying to use some lighting but I am not successful. Can u help me someone what kind of lighting should I use so that my model looks realistics and I would be able to visualize various parts on the model . Check my snippet I am trying to use this kind of lighting but finding black shadows on the sides not able to visualize properly. Thanks a lot for any help.
Code:
void CRevolutionProjView::OnViewShade()
{
// TODO: Add your command handler code here
// TODO: Add your command handler code here
CDC* pDC = GetDC();
wglMakeCurrent(pDC->m_hDC, m_hrc);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST);
// Enable light and setup 2 light sources (GL_LIGHT0 and GL_LIGHT1)
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glColor3f(1.0f, 0.0f, 0.0f);
// We're setting up twolight sources. One of them is located
// on the left side ofthe model (x = -1.5f) and emits white light. The
// second light sourceis located on the right side of the model (x = 1.5f)
// emitting red light.
// GL_LIGHT0: the whitelight emitting light source
// Create lightcomponents for GL_LIGHT0
GLfloat emissionLight0[] = {0.2f, 0.0f, 0.0f, 1.0f};
GLfloat ambientLight0[] = { 0.2f, 0.2f, 0.2f, 1.0f };
GLfloat diffuseLight0[] = { 0.8f, 0.8f, 0.8, 1.0f };
GLfloat specularLight0[] = { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat position0[] = { -1.5f, 1.0f, -4.0f, 1.0f };
// Assign createdcomponents to GL_LIGHT0
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight0);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight0);
glLightfv(GL_LIGHT0, GL_SPECULAR, specularLight0);
glLightfv(GL_LIGHT0, GL_EMISSION, emissionLight0);
glLightfv(GL_LIGHT0, GL_POSITION, position0);
// GL_LIGHT1: the redlight emitting light source
// Create lightcomponents for GL_LIGHT1
float ambientLight1[] = { 0.2f, 0.2f, 0.2f, 1.0f };
float diffuseLight1[] = { 0.8f, 0.8f, 0.8f, 1.0f };
float specularLight1[] = { 0.5f, 0.5f, 0.5f, 1.0f };
float emissionLight1[] = { 0.2f, 0.0f, 0.0f, 1.0f };
float position1[]= { -1.5f, 1.0f, -4.0f, 1.0f };
// Assign createdcomponents to GL_LIGHT1
glLightfv(GL_LIGHT1, GL_AMBIENT, ambientLight1);
glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuseLight1);
glLightfv(GL_LIGHT1, GL_SPECULAR, specularLight1);
glLightfv(GL_LIGHT1, GL_EMISSION, emissionLight1);
glLightfv(GL_LIGHT1, GL_POSITION, position1);
//---------------------------------
// enable color tracking
glEnable(GL_COLOR_MATERIAL);
// set material properties which will be assigned by glColor
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
// ...Somewhere in the main rendering loop of your program...
// Draw a polygon with material properties set by glColor
float specReflection[] = { 0.8f, 0.8f, 0.8f, 1.0f };
glMaterialfv(GL_FRONT, GL_SPECULAR, specReflection);
glMateriali(GL_FRONT, GL_SHININESS, 96);
glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
Invalidate();
wglMakeCurrent(NULL,NULL);
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|