lighting effect is not enough..
Hi...
I'm troubling with this prob. but I cannot figure it out..
I can see the shading for small object but cannot for big one.
I can tell the faces of Big boxes.
These are my codes for materials and lightings
changing paremeter does not work for me.
Please please help me
------------------------------------------------------------------
void TMainForm::GLInit(void)
{
int pf;
hDC = GetDeviceContext( this );
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(pfd);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cDepthBits = 16;
pfd.cColorBits = 32; //true color
pfd.iLayerType = PFD_MAIN_PLANE;
pf = ChoosePixelFormat(hDC, &pfd);
if (pf == 0) { MessageBox(NULL, "ChoosePixelFormat() failed: Cannot find a suitable pixel format.", "error", MB_OK); return; }
if (SetPixelFormat(hDC, pf, &pfd) == FALSE) { MessageBox(NULL, "SetPixelFormat() failed: Cannot set format specified.", "Error", MB_OK); return; }
DescribePixelFormat(hDC, pf, sizeof(PIXELFORMATDESCRIPTOR), &pfd);
hRC = wglCreateContext(hDC);
wglMakeCurrent(hDC, hRC);
ReleaseDC(hDC, Handle);
this->StringGrid1->Cols[0]->Add("속성");
this->StringGrid1->Rows[0]->Add("값");
// Ligting and material and other rendering
GLfloat lightPos[] = { 0.0f, 0.0f, 1.0f, 0.0f };
GLfloat ambientLight[] = { 0.3f, 0.3f, 0.3f, 1.0f };
GLfloat diffuseLight[] = { 0.4f, 0.4f, 0.4f, 1.0f };
GLfloat specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat specref[] = { 5.0f, 5.0f, 5.0f, 1.0f };
glClearColor(0.0f, 0.0f, 0.0f, 1.0f); // Black Background
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glEnable(GL_CULL_FACE);
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glShadeModel(GL_SMOOTH);
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glFrontFace(GL_CCW);
glEnable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE);
glMaterialfv(GL_FRONT, GL_SPECULAR, specref);
glMateriali(GL_FRONT, GL_SHININESS, 1);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambientLight);
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuseLight);
glLightfv(GL_LIGHT0, GL_POSITION, lightPos);
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
glEnable(GL_LIGHT0);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
// initialize font
fontListBase = CreateBitmapFont("Verdana" /*"Comic Sans MS"*/, 12);
bDraw = true;
}
-------------------------------------------------------------------------
-- Drawing Function
-------------------------------------------------------------------------
void TMainForm::DrawScene(void)
{
if(!bDraw) return;
// Clear view
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// set camera position
glLoadIdentity();
eyeX = cameraX + cameraLength*cos(cameraAlpha)*cos(cameraBeta);
eyeY = cameraY + cameraLength*sin(cameraAlpha)*cos(cameraBeta);
eyeZ = cameraZ + cameraLength*sin(cameraBeta);
float tx = 0;
float ty = 0;
float tz = 1;
gluLookAt( eyeX, eyeY, eyeZ ,cameraX, cameraY, cameraZ, tx, ty, tz);
// Basic setting
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glLineWidth(1);
// Draw objects
glEnable(GL_LIGHTING);
for(int i=0; i<showModelNum; i++)
{
currentModel.DrawModel( );
}
//Draw Grids
glDisable(GL_LIGHTING);
if (CheckBoxGrid->Checked == true)
{
DrawGrids(5000.0f, 5);
}
// Display object's name
if (CheckBoxPrintID->Checked == true)
{
glDisable(GL_DEPTH_TEST);
float x,y, z;
for(int i=0; i<currentModelNum; i++)
{
currentModel.GetScreenLocation(&x, &y, &z);
PrintString(currentModel->name, x,y,z );
}
}
// View setting
glLoadIdentity();
gluLookAt( 0, 0, 10 ,0, 0, 0, 0, 1, 0);
// Cross at middle
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(0, -0.15, 0);
glVertex3f(0, 0.15, 0);
glVertex3f(-0.15, 0, 0);
glVertex3f(0.15, 0, 0);
glEnd();
// Draw axis
float len = 0.4f, chSize = 0.06f;
glPushMatrix();
glTranslatef(3.8, -3.3, 0);
glLineWidth(2);
glBegin(GL_LINES);
int xH = 1;
if(cameraAlpha>PI*1.5 && cameraAlpha<PI*2.0f)
xH = 0;
//x
len = 0.4f;
glColor3f(1.0, 1.0, 0);
glVertex3f(0, 0, xH*0.001);
glVertex3f(0-len*cos(cameraAlpha-PI/2.0f), len*sin(cameraAlpha-PI/2.0f) * sin(cameraBeta), xH*0.001);
len = 0.7f;
glVertex3f(0-len*cos(cameraAlpha-PI/2.0f) -chSize, len*sin(cameraAlpha-PI/2.0f) * sin(cameraBeta)+chSize, 0);
glVertex3f(0-len*cos(cameraAlpha-PI/2.0f) +chSize, len*sin(cameraAlpha-PI/2.0f) * sin(cameraBeta)-chSize, 0);
glVertex3f(0-len*cos(cameraAlpha-PI/2.0f) -chSize, len*sin(cameraAlpha-PI/2.0f) * sin(cameraBeta)-chSize, 0);
glVertex3f(0-len*cos(cameraAlpha-PI/2.0f) +chSize, len*sin(cameraAlpha-PI/2.0f) * sin(cameraBeta)+chSize, 0);
//y
len = 0.4f;
glColor3f(0, 0, 1.0);
glVertex3f(0, 0, (1-xH)*0.001);
glVertex3f(0-len*cos(cameraAlpha+PI), len*sin(cameraAlpha+PI) * sin(cameraBeta), (1-xH)*0.001);
len = 0.7f;
glVertex3f(0-len*cos(cameraAlpha+PI) - chSize, len*sin(cameraAlpha+PI) * sin(cameraBeta) + chSize, 0 );
glVertex3f(0-len*cos(cameraAlpha+PI), len*sin(cameraAlpha+PI) * sin(cameraBeta), 0 );
glVertex3f(0-len*cos(cameraAlpha+PI) + chSize, len*sin(cameraAlpha+PI) * sin(cameraBeta) + chSize, 0 );
glVertex3f(0-len*cos(cameraAlpha+PI), len*sin(cameraAlpha+PI) * sin(cameraBeta), 0 );
glVertex3f(0-len*cos(cameraAlpha+PI), len*sin(cameraAlpha+PI) * sin(cameraBeta), 0 );
glVertex3f(0-len*cos(cameraAlpha+PI), len*sin(cameraAlpha+PI) * sin(cameraBeta) - chSize, 0 );
//Z
len = 0.4f;
glColor3f(1.0, 0, 0);
glVertex3f(0, 0, 0);
glVertex3f(0, len - len * sin(cameraBeta), 0);
len = 0.7f;
glVertex3f(-chSize, len - len * sin(cameraBeta) + chSize, 0);
glVertex3f(chSize, len - len * sin(cameraBeta) + chSize, 0);
glVertex3f(chSize, len - len * sin(cameraBeta) + chSize, 0);
glVertex3f(-chSize, len - len * sin(cameraBeta) - chSize, 0);
glVertex3f(-chSize, len - len * sin(cameraBeta) - chSize, 0);
glVertex3f(+chSize, len - len * sin(cameraBeta) - chSize, 0);
glEnd();
glPopMatrix();
SwapBuffers(wglGetCurrentDC());
}
[Edited by - mrbrown7732 on December 12, 2006 8:10:36 PM]
You need to describe the problem you're having a little better than that.
Because we do not understand what you're asking for.
Speak more clearly, screenshots perhaps if you aren't good with words?
My best Guess, since you said something about boxes of different size and shading. Is that you're running into the problem of Not Enough Vertices on big faces to get shading details.
OpenGL lighting is vertex based, more vertices = more detail.
Because we do not understand what you're asking for.
Speak more clearly, screenshots perhaps if you aren't good with words?
My best Guess, since you said something about boxes of different size and shading. Is that you're running into the problem of Not Enough Vertices on big faces to get shading details.
OpenGL lighting is vertex based, more vertices = more detail.
thank you very much for your answer...
I added screen shot..check it up and tell me more advices plz
I added screen shot..check it up and tell me more advices plz
hmmm. you didn't calculate the normals by urself .
try glEnable(GL_NORMALIZE);
if didn't work then you need to do calaulation part by urself.
take care.
try glEnable(GL_NORMALIZE);
if didn't work then you need to do calaulation part by urself.
take care.
The actual problem is hidden behind this invocation
currentModel.DrawModel( )
or perhaps the model loading/creation code. Without knowing that code it is difficult to say what happens. However, since there are small boxes that look correct, the problem may be already the model creation.
[Edited by - haegarr on December 13, 2006 2:27:14 AM]
currentModel.DrawModel( )
or perhaps the model loading/creation code. Without knowing that code it is difficult to say what happens. However, since there are small boxes that look correct, the problem may be already the model creation.
[Edited by - haegarr on December 13, 2006 2:27:14 AM]
Quote:Original post by ff8
hmmm. you didn't calculate the normals by urself .
try glEnable(GL_NORMALIZE);
if didn't work then you need to do calaulation part by urself.
take care.
glEnable(GL_NORMALIZE) only ensures that existing normals are unit length before doing the lighting. It doesn't magically conjure normals out of thin air.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement