hello,
I have created a model of the female body. the model is made up of 3 disjoint sub-models :
-
one semi superellipsoid model for each breast( left and right) which can be deformbed by varying a set of parameters of the superellipsoid.
-
and one model of the underlying body without the breast taken from a vrml file on which i have manually placed the two breast models close to the body.
but the problem is u can see the gaps between the breasts and the body.
My boss asked me to cover the above mentioned 3 models with a new surface like a cloth - so that it appears like a continuous smooth surface.
for, this i got an idea - i will retrieve the depth buffer and create a surface at a little lesser depth than my model and thus the viewer will not be able to see the gaps.
I retrieved the depth buffer, but somehow my depth buffer returns 1 every where which means nothin is being written into it.also it seems to be very slow.
if you have any ideas of a method for my task, please help me.
also my texture mapping is not working well - it was giving all wierd results. even though i am replaceing GL_REPLACE. i have to apply a skin texture to all the models in combination
here is my code in windows:
void CGLModelView::OnDraw(CDC* pDC)
{
CDocument* pDoc = GetDocument();
// TODO: add draw code here
wglMakeCurrent( pDC->m_hDC , m_hGLRC );
// glClearDepth( 1.0 );
glClearColor( 0.0f , 0.0f , 0.0f , 0.0f );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glEnable( GL_DEPTH_TEST );
glEnable( GL_LIGHTING );
glEnable( GL_LIGHT0 );
glColorMaterial( GL_FRONT_AND_BACK , GL_DIFFUSE );
glEnable( GL_COLOR_MATERIAL );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
CRect r;
GetClientRect(&r);
int depth = -(m_intPerspectiveZFar - m_intPerspectiveZNear);
double w = r.Width() / 2.0;
double h = r.Height() / 2.0;
double g = 240.0 / 255.0;
glBegin( GL_QUADS );
glNormal3f( 0.0 , 0.0 , 1.0 );
glColor3f( g /1.5 , g / 1.5 , g );
glVertex3d( -w , h , depth );
glColor3f( g / 3 , g / 3 , g / 1.5 );
glVertex3d( w , h , depth );
glColor3f( g / 3 , g / 3 , g / 3 );
glVertex3d( w , -h , depth );
glColor3f( g / 3 , g / 3 , g / 1.5 );
glVertex3d( -w , -h , depth );
glEnd();
if( m_uViewType != VIEW_PERSPECTIVE )
{
depth = -depth;
GLdouble m[4][4] = { { w / m_dblOrthoScale , 0 , 0 , 0} , { 0 , h / m_dblOrthoScale , 0 , 0 } , { 0 , 0 , 1.0 , 0 } , { 0 , 0 , 0 , 1} };
glMultMatrixd( &m[0][0] );
}
glTranslated( m_dblXTranslation , m_dblYTranslation , m_dblZTranslation );
glRotatef( m_intXAngle , 1.0 , 0.0 , 0.0 );
glRotatef( m_intYAngle , 0.0 , 1.0 , 0.0 );
glRotatef( m_intZAngle , 0.0 , 0.0 , 1.0 );
glCallList( ID_DISPLAY_LIST_GRID );
glEnable( GL_TEXTURE_2D );
//glDisable( GL_LIGHTING );
//glDisable( GL_COLOR_MATERIAL );
glCallList( ID_MODEL_DISPLAY_LIST );
glDisable( GL_TEXTURE_2D );
glFlush();
SwapBuffers( pDC->m_hDC );
wglMakeCurrent( NULL , NULL );
}
int CGLModelView::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
CClientDC dc(this);
PIXELFORMATDESCRIPTOR pfd;
memset( &pfd , 0 , sizeof( PIXELFORMATDESCRIPTOR ) );
pfd.nSize = sizeof( PIXELFORMATDESCRIPTOR );
pfd.cColorBits = 24;
pfd.cRedBits = 8;
pfd.cGreenBits = 8;
pfd.cBlueBits = 8;
pfd.cDepthBits = 32;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.iLayerType = PFD_MAIN_PLANE;
int nPixelFormatIndex = ChoosePixelFormat( dc.m_hDC , &pfd );
if( nPixelFormatIndex == 0 )
{
TRACE( "Choose Pixel Format Failed %d
" , GetLastError() );
return -1;
}
TRACE( “Pixel Format Found, index - %d” , nPixelFormatIndex );
BOOL blnResult = SetPixelFormat( dc.m_hDC , nPixelFormatIndex , &pfd );
if( !blnResult )
{
TRACE( "Set Pixel Format Failed,error - %d" , GetLastError() );
return -1;
}
// create a rendering context using the client dc
m_hGLRC = wglCreateContext( dc.m_hDC );
if( !m_hGLRC )
{
TRACE( "wglCreateContext failde %X
" , GetLastError() );
return -1;
}
blnResult = wglMakeCurrent( dc.m_hDC , m_hGLRC );
if( !blnResult )
{
TRACE( "wglMakeCurrent failed %d" , GetLastError() );
return -1;
}
glClearColor( 0.0f , 0.0f , 0.0f , 0.0f );
glClear( GL_COLOR_BUFFER_BIT );
BuildGridDisplayList();
glGenTextures( 1 , &nGLTextureName );
glBindTexture( GL_TEXTURE_2D , nGLTextureName );
glTexEnvf (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
BuildModelDisplayList();
wglMakeCurrent( NULL , NULL );
ReleaseDC( &dc );
SetProjectionMatrix();
return 0;
}
void CGLModelView::LoadTextureFile( CString strTextureFile )
{
CImage temp;
temp.Load( strTextureFile );
CClientDC dc(this);
wglMakeCurrent( dc.m_hDC , m_hGLRC );
GLint internalformat = temp.GetBPP() / 8;
GLenum fmt;
if( temp.IsIndexed() )
fmt = GL_COLOR_INDEX;
else
{
switch( internalformat )
{
case 3:
fmt = GL_RGB;
break;
case 4:
fmt = GL_RGBA;
break;
default :
MessageBox( "Error Loading Texture File into video memory : Invalid format" );
return;
}
}
glTexImage2D( GL_TEXTURE_2D , 0 , internalformat , temp.GetWidth() , temp.GetHeight() , 0 , fmt , GL_UNSIGNED_BYTE , temp.GetBits() );
wglMakeCurrent( NULL , NULL );
temp.Detach();
Invalidate(true);
}
void CGLModelView::BuildModelDisplayList()
{
glNewList(ID_MODEL_DISPLAY_LIST , GL_COMPILE );
glBegin( GL_QUADS );
glNormal3f( 0.0 , 0.0 , 1.0 );
glTexCoord2f( 0.0 , 0.0 );
glColor3f( 1.0 , 0.0 , 0.0 );
glVertex3f( -3.0 , -3.0 , 0.0 );
glTexCoord2f( 1.0 , 0.0 );
glColor3f( 0.0 , 1.0 , 0.0 );
glVertex3f( 3.0 , -3.0 , 0.0 );
glTexCoord2f( 1.0 , 1.0 );
glColor3f( 0.0 , 0.0 , 1.0 );
glVertex3f( 3.0 , 3.0 , 0.0 );
glTexCoord2f( 0.0 , 1.0 );
glColor3f( 0.0 , 1.0 , 0.0 );
glVertex3f( -3.0 , 3.0 , 0.0 );
glEnd();
glEndList();
}
please help me - i am still pretty much mediocre in opengl though i am good at programming.
please help me with this task … its really urgent.
Deepak Roy chittajallu
cdeepakroy@yahoo.com